Update download_models.py
Browse files- download_models.py +17 -20
download_models.py
CHANGED
|
@@ -4,35 +4,32 @@ from huggingface_hub import hf_hub_download
|
|
| 4 |
MODEL_DIR = os.path.join(os.path.dirname(__file__), "models")
|
| 5 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
"languages/eslav/rec.onnx",
|
| 11 |
"languages/eslav/dict.txt",
|
| 12 |
]
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
local_path = os.path.join(MODEL_DIR, remote_path)
|
| 16 |
if os.path.exists(local_path):
|
| 17 |
print(f"Skipping {remote_path}")
|
| 18 |
continue
|
| 19 |
print(f"Downloading {remote_path}...")
|
| 20 |
-
hf_hub_download(repo_id=
|
| 21 |
print(f" Saved to {local_path}")
|
| 22 |
|
| 23 |
-
# Попробуем скачать cls модель
|
| 24 |
-
for repo, path in [
|
| 25 |
-
("RapidAI/RapidOCR", "onnx/PP-OCRv4/cls/ch_ppocr_mobile_v2.0_cls_infer.onnx"),
|
| 26 |
-
("RapidAI/RapidOCR", "onnx/PP-OCRv3/cls/ch_ppocr_mobile_v2.0_cls_infer.onnx"),
|
| 27 |
-
]:
|
| 28 |
-
local = os.path.join(MODEL_DIR, path)
|
| 29 |
-
if os.path.exists(local):
|
| 30 |
-
continue
|
| 31 |
-
try:
|
| 32 |
-
hf_hub_download(repo_id=repo, filename=path, local_dir=MODEL_DIR)
|
| 33 |
-
print(f"Saved cls: {local}")
|
| 34 |
-
break
|
| 35 |
-
except Exception:
|
| 36 |
-
pass
|
| 37 |
-
|
| 38 |
print("\nAll models ready!")
|
|
|
|
| 4 |
MODEL_DIR = os.path.join(os.path.dirname(__file__), "models")
|
| 5 |
os.makedirs(MODEL_DIR, exist_ok=True)
|
| 6 |
|
| 7 |
+
# Mobile-детекция (4.83 МБ) вместо server-варианта (88 МБ)
|
| 8 |
+
det_repo = "ilaylow/PP_OCRv5_mobile_onnx"
|
| 9 |
+
det_file = "ppocrv5_det.onnx"
|
| 10 |
+
|
| 11 |
+
# Рекогнишн под кириллицу + латиницу
|
| 12 |
+
rec_repo = "monkt/paddleocr-onnx"
|
| 13 |
+
REC_FILES = [
|
| 14 |
"languages/eslav/rec.onnx",
|
| 15 |
"languages/eslav/dict.txt",
|
| 16 |
]
|
| 17 |
|
| 18 |
+
local_det = os.path.join(MODEL_DIR, det_file)
|
| 19 |
+
if not os.path.exists(local_det):
|
| 20 |
+
print(f"Downloading {det_file}...")
|
| 21 |
+
hf_hub_download(repo_id=det_repo, filename=det_file, local_dir=MODEL_DIR)
|
| 22 |
+
print(f" Saved to {local_det}")
|
| 23 |
+
else:
|
| 24 |
+
print(f"Skipping {det_file}")
|
| 25 |
+
|
| 26 |
+
for remote_path in REC_FILES:
|
| 27 |
local_path = os.path.join(MODEL_DIR, remote_path)
|
| 28 |
if os.path.exists(local_path):
|
| 29 |
print(f"Skipping {remote_path}")
|
| 30 |
continue
|
| 31 |
print(f"Downloading {remote_path}...")
|
| 32 |
+
hf_hub_download(repo_id=rec_repo, filename=remote_path, local_dir=MODEL_DIR)
|
| 33 |
print(f" Saved to {local_path}")
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
print("\nAll models ready!")
|