File size: 1,409 Bytes
19f420a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
# download_model.py
import os
from huggingface_hub import hf_hub_download

# --- Configuration ---
# Details from your Hugging Face repository screenshot.
REPO_ID = "Testys/drowsiness-detection-model"
FILENAME = "best_model_efficientnet_b7.pth"
LOCAL_DIR = "models"

def download_model():
    """
    Downloads the specified model file from Hugging Face Hub
    and saves it to the local models/ directory.
    """
    print(f"Downloading model '{FILENAME}' from repository '{REPO_ID}'...")

    # Ensure the local directory exists.
    if not os.path.exists(LOCAL_DIR):
        os.makedirs(LOCAL_DIR)
        print(f"Created directory: {LOCAL_DIR}")

    try:
        # Download the file.
        # local_dir_use_symlinks=False ensures the file is copied to your directory
        # instead of just pointing to the cache.
        model_path = hf_hub_download(
            repo_id=REPO_ID,
            filename=FILENAME,
            local_dir=LOCAL_DIR,
            local_dir_use_symlinks=False,
            # token=True # Use token for private repos, can be omitted for public ones
        )
        print(f"\nModel downloaded successfully!")
        print(f"Saved to: {model_path}")

    except Exception as e:
        print(f"\nAn error occurred during download: {e}")
        print("Please check the repository ID, filename, and your network connection.")

if __name__ == "__main__":
    download_model()