From f89063efcc17fa6ce1927d34c48dc6a3482a7366 Mon Sep 17 00:00:00 2001 From: samiabat Date: Mon, 28 Jul 2025 18:55:26 +0300 Subject: [PATCH] add attempt to downloads --- Docker/download.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/Docker/download.py b/Docker/download.py index 234fd069..ed077660 100644 --- a/Docker/download.py +++ b/Docker/download.py @@ -1,5 +1,27 @@ # Download moda ASR related models 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") -model_dir = snapshot_download('damo/speech_fsmn_vad_zh-cn-16k-common-pytorch',revision="v2.0.4") -model_dir = snapshot_download('damo/punc_ct-transformer_zh-cn-common-vocab272727-pytorch',revision="v2.0.4") +import shutil +import os +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')