Triventure-AI / src /utils /model_downloader.py
ABAO77's picture
Upload 37 files
5ce8318 verified
import os
import subprocess
from pathlib import Path
def download_model_if_not_exists():
"""
Download model from Hugging Face if the model directory doesn't exist.
"""
model_dir = Path("./model")
if not model_dir.exists():
print("Model directory not found. Downloading from Hugging Face...")
try:
# Create model directory
model_dir.mkdir(parents=True, exist_ok=True)
# Install git-lfs if not already installed
subprocess.run(["git", "lfs", "install"], check=True)
# Clone the model repository
subprocess.run([
"git", "clone",
"https://huggingface.co/spaces/dinhanit/triventure_model",
"temp_model"
], check=True)
# Copy model files
subprocess.run([
"cp", "-r",
"temp_model/model/*",
str(model_dir)
], check=True)
# Clean up
subprocess.run(["rm", "-rf", "temp_model"], check=True)
print("Model downloaded successfully!")
except Exception as e:
print(f"Error downloading model: {str(e)}")
raise
else:
print("Model directory already exists. Skipping download.")
def download_image_if_not_exists():
image_dir = Path("./images")
if not image_dir.exists():
print("Image directory not found. Downloading from Hugging Face...")
try:
# Create image directory
image_dir.mkdir(parents=True, exist_ok=True)
# Clone the image repository
subprocess.run([
"git", "clone",
"https://huggingface.co/spaces/dinhanit/triventure_image",
"temp_image"
], check=True)
# Copy image files
subprocess.run([
"cp", "-r",
"temp_image/images/*",
str(image_dir)
], check=True)
# Clean up
subprocess.run(["rm", "-rf", "temp_image"], check=True)
print("Image downloaded successfully!")
except Exception as e:
print(f"Error downloading image: {str(e)}")
raise
else:
print("Image directory already exists. Skipping download.")