Spaces:
Running
on
Zero
Running
on
Zero
last trt to download the model at build time using the scripts
Browse files- download_model.py +27 -10
- test_download.py +46 -0
download_model.py
CHANGED
|
@@ -25,17 +25,34 @@ def download_model():
|
|
| 25 |
# Create local directory if it doesn't exist
|
| 26 |
os.makedirs(LOCAL_MODEL_PATH, exist_ok=True)
|
| 27 |
|
| 28 |
-
# Use huggingface_hub to download the model
|
| 29 |
-
from huggingface_hub import
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
logger.info(f"Model downloaded successfully to {LOCAL_MODEL_PATH}")
|
| 41 |
return True
|
|
|
|
| 25 |
# Create local directory if it doesn't exist
|
| 26 |
os.makedirs(LOCAL_MODEL_PATH, exist_ok=True)
|
| 27 |
|
| 28 |
+
# Use huggingface_hub to download the model files
|
| 29 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
| 30 |
|
| 31 |
+
# List files in the int4 subfolder
|
| 32 |
+
files = list_repo_files(MAIN_MODEL_ID, subfolder="int4")
|
| 33 |
+
|
| 34 |
+
# Download each required file
|
| 35 |
+
required_files = [
|
| 36 |
+
"config.json",
|
| 37 |
+
"pytorch_model.bin",
|
| 38 |
+
"tokenizer.json",
|
| 39 |
+
"tokenizer_config.json",
|
| 40 |
+
"special_tokens_map.json",
|
| 41 |
+
"generation_config.json"
|
| 42 |
+
]
|
| 43 |
+
|
| 44 |
+
for file_name in required_files:
|
| 45 |
+
if file_name in files:
|
| 46 |
+
logger.info(f"Downloading {file_name}...")
|
| 47 |
+
hf_hub_download(
|
| 48 |
+
repo_id=MAIN_MODEL_ID,
|
| 49 |
+
filename=f"int4/{file_name}",
|
| 50 |
+
local_dir=LOCAL_MODEL_PATH,
|
| 51 |
+
local_dir_use_symlinks=False
|
| 52 |
+
)
|
| 53 |
+
logger.info(f"Downloaded {file_name}")
|
| 54 |
+
else:
|
| 55 |
+
logger.warning(f"File {file_name} not found in int4 subfolder")
|
| 56 |
|
| 57 |
logger.info(f"Model downloaded successfully to {LOCAL_MODEL_PATH}")
|
| 58 |
return True
|
test_download.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Simple test script to verify download functionality for Hugging Face Spaces
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
import logging
|
| 9 |
+
|
| 10 |
+
# Configure logging
|
| 11 |
+
logging.basicConfig(level=logging.INFO)
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
+
def test_download():
|
| 15 |
+
"""Test the download functionality"""
|
| 16 |
+
try:
|
| 17 |
+
logger.info("Testing download functionality...")
|
| 18 |
+
|
| 19 |
+
# Import and run the download script
|
| 20 |
+
from download_model import main as download_main
|
| 21 |
+
|
| 22 |
+
success = download_main()
|
| 23 |
+
logger.info(f"Download test result: {'PASS' if success else 'FAIL'}")
|
| 24 |
+
|
| 25 |
+
return success
|
| 26 |
+
|
| 27 |
+
except Exception as e:
|
| 28 |
+
logger.error(f"Error testing download: {e}")
|
| 29 |
+
return False
|
| 30 |
+
|
| 31 |
+
def main():
|
| 32 |
+
"""Main test function"""
|
| 33 |
+
logger.info("Starting download test...")
|
| 34 |
+
|
| 35 |
+
success = test_download()
|
| 36 |
+
|
| 37 |
+
if success:
|
| 38 |
+
logger.info("β
Download test passed!")
|
| 39 |
+
else:
|
| 40 |
+
logger.error("β Download test failed!")
|
| 41 |
+
|
| 42 |
+
return success
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
success = main()
|
| 46 |
+
sys.exit(0 if success else 1)
|