FFomy commited on
Commit
4e69efc
·
verified ·
1 Parent(s): 42143e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -24
app.py CHANGED
@@ -6,37 +6,65 @@ from modelscope.hub.snapshot_download import snapshot_download
6
 
7
  # 1. 定义本地路径和远程仓库ID
8
  FUN_ASR_NANO_LOCAL_PATH = "./Fun-ASR/model"
9
- FUN_ASR_NANO_REPO_ID = "FunAudioLLM/Fun-ASR-Nano-2512"
10
  SENSE_VOICE_SMALL_LOCAL_PATH = "./Fun-ASR/model/SenseVoiceSmall"
11
- # SENSE_VOICE_SMALL_REPO_ID = "FunAudioLLM/SenseVoiceSmall"
12
- # REPO_TYPE = "hf" # "hf" for Hugging Face, "ms" for ModelScope
13
- SENSE_VOICE_SMALL_REPO_ID = "iic/SenseVoiceSmall"
14
- REPO_TYPE = "ms"
15
 
16
- # 2. 检查本地是否存在,不存在则下载
17
- if not os.path.exists(FUN_ASR_NANO_LOCAL_PATH):
18
- from modelscope import HubApi
19
- api= HubApi()
20
- api.login(os.getenv("MODELSCOPE_TOKEN"))
21
- print(f"正在下载模型 Fun-ASR-Nano {FUN_ASR_NANO_LOCAL_PATH} ...")
22
- snapshot_download(
23
- repo_id=FUN_ASR_NANO_REPO_ID,
24
- local_dir=FUN_ASR_NANO_LOCAL_PATH,
25
- ignore_patterns=["*.onnx"], # 如果你不需要onnx文件,可以过滤掉以节省时间和空间
26
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  print("模型下载完毕!")
 
 
 
 
28
  else:
29
  print("检测到本地模型文件,跳过下载。")
30
 
31
-
32
  if not os.path.exists(SENSE_VOICE_SMALL_LOCAL_PATH):
33
- print(f"正在下载模型 {SENSE_VOICE_SMALL_REPO_ID} 到 {SENSE_VOICE_SMALL_LOCAL_PATH} ...")
34
- snapshot_download(
35
- repo_id=SENSE_VOICE_SMALL_REPO_ID,
36
- local_dir=SENSE_VOICE_SMALL_LOCAL_PATH,
37
- ignore_patterns=["*.onnx"], # 如果你不需要onnx文件,可以过滤掉以节省时间和空间
38
- )
39
- print("模型下载完毕!")
40
  else:
41
  print("检测到本地模型文件,跳过下载。")
42
 
 
6
 
7
  # 1. 定义本地路径和远程仓库ID
8
  FUN_ASR_NANO_LOCAL_PATH = "./Fun-ASR/model"
 
9
  SENSE_VOICE_SMALL_LOCAL_PATH = "./Fun-ASR/model/SenseVoiceSmall"
 
 
 
 
10
 
11
+ # 配置仓库类型 (通过修改这个变量来切换平台)
12
+ # "ms" = ModelScope, "hf" = Hugging Face
13
+ REPO_TYPE = "hf" # 修改这里来切换平台
14
+
15
+ # 根据仓库类型配置仓库ID
16
+ if REPO_TYPE == "hf":
17
+ # Hugging Face 配置
18
+ FUN_ASR_NANO_REPO_ID = "FunAudioLLM/Fun-ASR-Nano-2512"
19
+ SENSE_VOICE_SMALL_REPO_ID = "FunAudioLLM/SenseVoiceSmall"
20
+ else: # "ms"
21
+ # ModelScope 配置
22
+ FUN_ASR_NANO_REPO_ID = "FunAudioLLM/Fun-ASR-Nano-2512"
23
+ SENSE_VOICE_SMALL_REPO_ID = "iic/SenseVoiceSmall"
24
+
25
+ # 2. 导入下载库
26
+ if REPO_TYPE == "hf":
27
+ from huggingface_hub import snapshot_download as hf_snapshot_download
28
+ else:
29
+ from modelscope.hub.snapshot_download import snapshot_download as ms_snapshot_download
30
+
31
+ def download_model(repo_id, local_path):
32
+ """
33
+ 根据平台类型下载模型
34
+
35
+ Args:
36
+ repo_id (str): 仓库ID
37
+ local_path (str): 本地存储路径
38
+ """
39
+ if REPO_TYPE == "hf":
40
+ # Hugging Face 下载逻辑
41
+ print(f"正在从 Hugging Face 下载模型 {repo_id} 到 {local_path} ...")
42
+ hf_snapshot_download(
43
+ repo_id=repo_id,
44
+ local_dir=local_path,
45
+ ignore_patterns=["*.onnx"], # 如果你不需要onnx文件,可以过滤掉以节省时间和空间
46
+ )
47
+ else: # "ms"
48
+ # ModelScope 下载逻辑
49
+ print(f"正在从 ModelScope 下载模型 {repo_id} 到 {local_path} ...")
50
+ from modelscope import HubApi
51
+ api = HubApi()
52
+ api.login(os.getenv("MODELSCOPE_TOKEN"))
53
+ ms_snapshot_download(
54
+ repo_id=repo_id,
55
+ local_dir=local_path,
56
+ ignore_patterns=["*.onnx"], # 如果你不需要onnx文件,可以过滤掉以节省时间和空间
57
+ )
58
  print("模型下载完毕!")
59
+
60
+ # 3. 检查本地是否存在,不存在则下载
61
+ if not os.path.exists(FUN_ASR_NANO_LOCAL_PATH):
62
+ download_model(FUN_ASR_NANO_REPO_ID, FUN_ASR_NANO_LOCAL_PATH)
63
  else:
64
  print("检测到本地模型文件,跳过下载。")
65
 
 
66
  if not os.path.exists(SENSE_VOICE_SMALL_LOCAL_PATH):
67
+ download_model(SENSE_VOICE_SMALL_REPO_ID, SENSE_VOICE_SMALL_LOCAL_PATH)
 
 
 
 
 
 
68
  else:
69
  print("检测到本地模型文件,跳过下载。")
70