admin commited on
Commit
31d6574
·
1 Parent(s): 9c02599
Files changed (3) hide show
  1. app.py +9 -10
  2. requirements.txt +3 -3
  3. utils.py +4 -10
app.py CHANGED
@@ -8,9 +8,9 @@ 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_files, embed_img, TEMP_DIR
12
  from collections import Counter
13
  from model import EvalNet
 
14
 
15
 
16
  TRANSLATE = {
@@ -235,6 +235,7 @@ TRANSLATE = {
235
  "T0323": ["都它尔", "du1_ta1_er3"],
236
  }
237
  CLASSES = list(TRANSLATE.keys())
 
238
  SAMPLE_RATE = 44100
239
 
240
 
@@ -363,7 +364,7 @@ def infer(wav_path: str, log_name: str, folder_path=TEMP_DIR):
363
  shutil.rmtree(folder_path)
364
 
365
  if not wav_path:
366
- return None, "请输入音频 Please input an audio!"
367
 
368
  try:
369
  model = EvalNet(log_name, len(TRANSLATE)).model
@@ -399,27 +400,25 @@ if __name__ == "__main__":
399
  gr.Interface(
400
  fn=infer,
401
  inputs=[
402
- gr.Audio(label="上传录音 Upload a recording", type="filepath"),
403
- gr.Dropdown(
404
- choices=models, label="选择模型 Select a model", value=models[0]
405
- ),
406
  ],
407
  outputs=[
408
- gr.Textbox(label="音频文件名 Audio filename", show_copy_button=True),
409
  gr.Textbox(
410
- label="中国乐器识别 Chinese instrument recognition",
411
  show_copy_button=True,
412
  ),
413
  ],
414
  examples=examples,
415
  cache_examples=False,
416
  flagging_mode="never",
417
- title="建议录音时长保持在 3s 左右<br>It is recommended to keep the recording length around 3s.",
418
  )
419
 
420
  gr.Markdown(
421
  """
422
- # 引用 Cite
423
  ```bibtex
424
  @dataset{zhaorui_liu_2021_5676893,
425
  author = {Monan Zhou, Shenyang Xu, Zhaorui Liu, Zhaowen Wang, Feng Yu, Wei Li and Baoqiang Han},
 
8
  import gradio as gr
9
  import librosa.display
10
  import matplotlib.pyplot as plt
 
11
  from collections import Counter
12
  from model import EvalNet
13
+ from utils import get_modelist, find_files, embed_img
14
 
15
 
16
  TRANSLATE = {
 
235
  "T0323": ["都它尔", "du1_ta1_er3"],
236
  }
237
  CLASSES = list(TRANSLATE.keys())
238
+ TEMP_DIR = "./__pycache__/tmp"
239
  SAMPLE_RATE = 44100
240
 
241
 
 
364
  shutil.rmtree(folder_path)
365
 
366
  if not wav_path:
367
+ return None, "Please input an audio!"
368
 
369
  try:
370
  model = EvalNet(log_name, len(TRANSLATE)).model
 
400
  gr.Interface(
401
  fn=infer,
402
  inputs=[
403
+ gr.Audio(label="Upload a recording", type="filepath"),
404
+ gr.Dropdown(choices=models, label="Select a model", value=models[0]),
 
 
405
  ],
406
  outputs=[
407
+ gr.Textbox(label="Audio filename", show_copy_button=True),
408
  gr.Textbox(
409
+ label="Chinese instrument recognition",
410
  show_copy_button=True,
411
  ),
412
  ],
413
  examples=examples,
414
  cache_examples=False,
415
  flagging_mode="never",
416
+ title="It is recommended to keep the recording length around 3s.",
417
  )
418
 
419
  gr.Markdown(
420
  """
421
+ # Cite
422
  ```bibtex
423
  @dataset{zhaorui_liu_2021_5676893,
424
  author = {Monan Zhou, Shenyang Xu, Zhaorui Liu, Zhaowen Wang, Feng Yu, Wei Li and Baoqiang Han},
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
- librosa
2
  torch
 
 
3
  matplotlib
4
  torchvision
5
- pillow
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
- f"ccmusic-database/CTIS",
9
- cache_dir=f"{os.getcwd()}/__pycache__",
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"无法访问 {model_dir}: {e}")
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"跳过 .git examples 文件夹: {full_path}")
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/CTIS",
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 or 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