kybocr / download_model.py
tommulder's picture
Seperate everything into files
1a22905
#!/usr/bin/env python3
"""
Download the dots.ocr model from Hugging Face Hub.
This script downloads the model to the HF cache and writes the path to a file.
"""
import os
import sys
from huggingface_hub import snapshot_download
def main():
# Get model ID from environment variable or use default
model_id = os.environ.get("MODEL_ID", "rednote-hilab/dots.ocr")
print(f"Downloading model: {model_id}")
# Download model to HF cache (default location: ~/.cache/huggingface/hub)
# This automatically handles caching, deduplication, and proper directory structure
model_path = snapshot_download(
repo_id=model_id,
allow_patterns=["*"]
)
print(f"Model downloaded to: {model_path}")
# Write the model path to a file for later use
output_file = "/home/user/app/model_path.txt"
with open(output_file, "w") as f:
f.write(model_path)
print(f"Model path written to: {output_file}")
if __name__ == "__main__":
main()