Spaces:
Running
Running
admin
commited on
Commit
·
153d7d2
1
Parent(s):
0f4dacf
2 pure en
Browse files- app.py +21 -24
- requirements.txt +3 -3
- utils.py +4 -10
app.py
CHANGED
|
@@ -8,24 +8,25 @@ import numpy as np
|
|
| 8 |
import gradio as gr
|
| 9 |
import librosa.display
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
-
from utils import get_modelist, find_wav_files, embed_img, TEMP_DIR
|
| 12 |
from model import EvalNet
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
TRANSLATE = {
|
| 16 |
-
"vibrato": "
|
| 17 |
-
"trill": "
|
| 18 |
-
"tremolo": "
|
| 19 |
-
"staccato": "
|
| 20 |
-
"ricochet": "
|
| 21 |
-
"pizzicato": "
|
| 22 |
-
"percussive": "
|
| 23 |
-
"legato_slide_glissando": "
|
| 24 |
-
"harmonic": "
|
| 25 |
-
"diangong": "
|
| 26 |
-
"detache": "
|
| 27 |
}
|
| 28 |
CLASSES = list(TRANSLATE.keys())
|
|
|
|
| 29 |
SAMPLE_RATE = 44100
|
| 30 |
|
| 31 |
|
|
@@ -107,7 +108,7 @@ def infer(wav_path: str, log_name: str, folder_path=TEMP_DIR):
|
|
| 107 |
shutil.rmtree(folder_path)
|
| 108 |
|
| 109 |
if not wav_path:
|
| 110 |
-
return None, "
|
| 111 |
|
| 112 |
try:
|
| 113 |
model = EvalNet(log_name, len(TRANSLATE)).model
|
|
@@ -138,30 +139,26 @@ if __name__ == "__main__":
|
|
| 138 |
gr.Interface(
|
| 139 |
fn=infer,
|
| 140 |
inputs=[
|
| 141 |
-
gr.Audio(label="
|
| 142 |
-
gr.Dropdown(
|
| 143 |
-
choices=models, label="选择模型 Select a model", value=models[0]
|
| 144 |
-
),
|
| 145 |
],
|
| 146 |
outputs=[
|
| 147 |
-
gr.Textbox(label="
|
| 148 |
-
gr.Textbox(
|
| 149 |
-
label="演奏技法识别 Playing tech recognition", show_copy_button=True
|
| 150 |
-
),
|
| 151 |
],
|
| 152 |
examples=examples,
|
| 153 |
cache_examples=False,
|
| 154 |
allow_flagging="never",
|
| 155 |
-
title="
|
| 156 |
)
|
| 157 |
|
| 158 |
gr.Markdown(
|
| 159 |
"""
|
| 160 |
-
#
|
| 161 |
```bibtex
|
| 162 |
@dataset{zhaorui_liu_2021_5676893,
|
| 163 |
author = {Monan Zhou, Shenyang Xu, Zhaorui Liu, Zhaowen Wang, Feng Yu, Wei Li and Baoqiang Han},
|
| 164 |
-
title = {CCMusic: an Open and Diverse Database for Chinese
|
| 165 |
month = {mar},
|
| 166 |
year = {2024},
|
| 167 |
publisher = {HuggingFace},
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
import librosa.display
|
| 10 |
import matplotlib.pyplot as plt
|
|
|
|
| 11 |
from model import EvalNet
|
| 12 |
+
from utils import get_modelist, find_wav_files, embed_img
|
| 13 |
|
| 14 |
|
| 15 |
TRANSLATE = {
|
| 16 |
+
"vibrato": "Rou xian",
|
| 17 |
+
"trill": "Chan yin",
|
| 18 |
+
"tremolo": "Chan gong",
|
| 19 |
+
"staccato": "Dun gong",
|
| 20 |
+
"ricochet": "Pao gong",
|
| 21 |
+
"pizzicato": "Bo xian",
|
| 22 |
+
"percussive": "Ji gong",
|
| 23 |
+
"legato_slide_glissando": "Lian hua yin",
|
| 24 |
+
"harmonic": "Fan yin",
|
| 25 |
+
"diangong": "Dian gong",
|
| 26 |
+
"detache": "Fen gong",
|
| 27 |
}
|
| 28 |
CLASSES = list(TRANSLATE.keys())
|
| 29 |
+
TEMP_DIR = "./__pycache__/tmp"
|
| 30 |
SAMPLE_RATE = 44100
|
| 31 |
|
| 32 |
|
|
|
|
| 108 |
shutil.rmtree(folder_path)
|
| 109 |
|
| 110 |
if not wav_path:
|
| 111 |
+
return None, "Please input an audio!"
|
| 112 |
|
| 113 |
try:
|
| 114 |
model = EvalNet(log_name, len(TRANSLATE)).model
|
|
|
|
| 139 |
gr.Interface(
|
| 140 |
fn=infer,
|
| 141 |
inputs=[
|
| 142 |
+
gr.Audio(label="Upload a recording", type="filepath"),
|
| 143 |
+
gr.Dropdown(choices=models, label="Select a model", value=models[0]),
|
|
|
|
|
|
|
| 144 |
],
|
| 145 |
outputs=[
|
| 146 |
+
gr.Textbox(label="Audio filename", show_copy_button=True),
|
| 147 |
+
gr.Textbox(label="Playing tech recognition", show_copy_button=True),
|
|
|
|
|
|
|
| 148 |
],
|
| 149 |
examples=examples,
|
| 150 |
cache_examples=False,
|
| 151 |
allow_flagging="never",
|
| 152 |
+
title="It is recommended to keep the recording length around 3s.",
|
| 153 |
)
|
| 154 |
|
| 155 |
gr.Markdown(
|
| 156 |
"""
|
| 157 |
+
# Cite
|
| 158 |
```bibtex
|
| 159 |
@dataset{zhaorui_liu_2021_5676893,
|
| 160 |
author = {Monan Zhou, Shenyang Xu, Zhaorui Liu, Zhaowen Wang, Feng Yu, Wei Li and Baoqiang Han},
|
| 161 |
+
title = {CCMusic: an Open and Diverse Database for Chinese Music Information Retrieval Research},
|
| 162 |
month = {mar},
|
| 163 |
year = {2024},
|
| 164 |
publisher = {HuggingFace},
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
-
librosa
|
| 2 |
torch
|
|
|
|
|
|
|
| 3 |
matplotlib
|
| 4 |
torchvision
|
| 5 |
-
|
| 6 |
-
modelscope==1.15
|
|
|
|
|
|
|
| 1 |
torch
|
| 2 |
+
pillow
|
| 3 |
+
librosa
|
| 4 |
matplotlib
|
| 5 |
torchvision
|
| 6 |
+
modelscope[framework]==1.18
|
|
|
utils.py
CHANGED
|
@@ -5,10 +5,9 @@ from modelscope import snapshot_download
|
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
MODEL_DIR = snapshot_download(
|
| 8 |
-
|
| 9 |
-
cache_dir=
|
| 10 |
)
|
| 11 |
-
TEMP_DIR = f"{os.getcwd()}/flagged"
|
| 12 |
|
| 13 |
|
| 14 |
def toCUDA(x):
|
|
@@ -34,22 +33,17 @@ def get_modelist(model_dir=MODEL_DIR):
|
|
| 34 |
try:
|
| 35 |
entries = os.listdir(model_dir)
|
| 36 |
except OSError as e:
|
| 37 |
-
print(f"
|
| 38 |
return
|
| 39 |
|
| 40 |
-
# 遍历所有条目
|
| 41 |
output = []
|
| 42 |
for entry in entries:
|
| 43 |
-
# 获取完整路径
|
| 44 |
full_path = os.path.join(model_dir, entry)
|
| 45 |
-
# 跳过'.git'文件夹
|
| 46 |
if entry == ".git" or entry == "examples":
|
| 47 |
-
print(f"
|
| 48 |
continue
|
| 49 |
|
| 50 |
-
# 检查条目是文件还是目录
|
| 51 |
if os.path.isdir(full_path):
|
| 52 |
-
# 打印目录路径
|
| 53 |
output.append(os.path.basename(full_path))
|
| 54 |
|
| 55 |
return output
|
|
|
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
MODEL_DIR = snapshot_download(
|
| 8 |
+
"ccmusic-database/erhu_playing_tech",
|
| 9 |
+
cache_dir="./__pycache__",
|
| 10 |
)
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def toCUDA(x):
|
|
|
|
| 33 |
try:
|
| 34 |
entries = os.listdir(model_dir)
|
| 35 |
except OSError as e:
|
| 36 |
+
print(f"Cannot access {model_dir}: {e}")
|
| 37 |
return
|
| 38 |
|
|
|
|
| 39 |
output = []
|
| 40 |
for entry in entries:
|
|
|
|
| 41 |
full_path = os.path.join(model_dir, entry)
|
|
|
|
| 42 |
if entry == ".git" or entry == "examples":
|
| 43 |
+
print(f"Skip .git / examples dir: {full_path}")
|
| 44 |
continue
|
| 45 |
|
|
|
|
| 46 |
if os.path.isdir(full_path):
|
|
|
|
| 47 |
output.append(os.path.basename(full_path))
|
| 48 |
|
| 49 |
return output
|