add attempt to downloads

This commit is contained in:
samiabat 2025-07-28 18:55:26 +03:00
parent f3d03ecb8f
commit f89063efcc

View File

@ -1,5 +1,27 @@
# Download moda ASR related models # Download moda ASR related models
from modelscope import snapshot_download from modelscope import snapshot_download
model_dir = snapshot_download('damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch',revision="v2.0.4") import shutil
model_dir = snapshot_download('damo/speech_fsmn_vad_zh-cn-16k-common-pytorch',revision="v2.0.4") import os
model_dir = snapshot_download('damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch',revision="v2.0.4") import time
from modelscope.hub.snapshot_download import snapshot_download
def safe_download(model_id, revision='v2.0.4', max_retries=3):
cache_base = os.path.expanduser(f'~/.cache/modelscope/hub/{model_id.replace("/", "/")}')
if os.path.exists(cache_base):
shutil.rmtree(cache_base) # Remove possibly corrupted model cache
for attempt in range(max_retries):
try:
print(f"Attempting download for: {model_id} (Attempt {attempt + 1})")
model_dir = snapshot_download(model_id, revision=revision)
print(f"✅ Downloaded {model_id} to {model_dir}")
return model_dir
except Exception as e:
print(f"❌ Failed on attempt {attempt + 1} for {model_id}: {e}")
time.sleep(5)
raise RuntimeError(f"❌ All attempts failed for {model_id}")
# Model downloads
safe_download('damo/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-pytorch')
safe_download('damo/speech_fsmn_vad_zh-cn-16k-common-pytorch')
safe_download('damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch')