mwauranjorogekelvin commited on
Commit
2241a78
·
verified ·
1 Parent(s): ae1f14a

Update download_model.py

Browse files
Files changed (1) hide show
  1. 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
- model_path = hf_hub_download(
9
- repo_id="toandev/OCR-for-Captcha",
10
- filename="model.onnx",
11
- repo_type="space"
12
- )
 
13
 
14
- shutil.copy(model_path, "./model/model.onnx")
15
- print("✅ ONNX model saved to ./model/model.onnx")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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")