Update download_model.py
Browse files- download_model.py +25 -8
download_model.py
CHANGED
|
@@ -2,14 +2,31 @@ from huggingface_hub import hf_hub_download
|
|
| 2 |
import shutil
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
print("Downloading ONNX model from toandev/OCR-for-Captcha...")
|
| 6 |
os.makedirs("./model", exist_ok=True)
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
repo_type
|
| 12 |
-
|
|
|
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import shutil
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
os.makedirs("./model", exist_ok=True)
|
| 6 |
|
| 7 |
+
# Try model repo first, then space repo
|
| 8 |
+
configs = [
|
| 9 |
+
{"repo_id": "toandev/OCR-for-Captcha", "repo_type": "model"},
|
| 10 |
+
{"repo_id": "toandev/OCR-for-Captcha", "repo_type": "space"},
|
| 11 |
+
{"repo_id": "toandev/OCR-for-Captcha", "repo_type": "dataset"},
|
| 12 |
+
]
|
| 13 |
|
| 14 |
+
model_path = None
|
| 15 |
+
for cfg in configs:
|
| 16 |
+
try:
|
| 17 |
+
print(f"Trying repo_type='{cfg['repo_type']}'...")
|
| 18 |
+
model_path = hf_hub_download(
|
| 19 |
+
repo_id=cfg["repo_id"],
|
| 20 |
+
filename="model.onnx",
|
| 21 |
+
repo_type=cfg["repo_type"]
|
| 22 |
+
)
|
| 23 |
+
print(f"✅ Found with repo_type='{cfg['repo_type']}'")
|
| 24 |
+
break
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(f"❌ Failed: {e}")
|
| 27 |
+
|
| 28 |
+
if model_path:
|
| 29 |
+
shutil.copy(model_path, "./model/model.onnx")
|
| 30 |
+
print("✅ ONNX model saved to ./model/model.onnx")
|
| 31 |
+
else:
|
| 32 |
+
raise RuntimeError("Could not find model.onnx in any repo type")
|