File size: 1,009 Bytes
1a22905
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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()