Spaces:
Sleeping
Sleeping
File size: 2,482 Bytes
c2fb4c6 |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# setup_models.py
import os
import shutil
from huggingface_hub import hf_hub_download, snapshot_download
# Configuration
REPO_ID = "ShadowGard3n/AgroVision-Models"
DEST_MODELS_DIR = "models"
# Ensure the destination models directory exists
os.makedirs(DEST_MODELS_DIR, exist_ok=True)
print(f"--- Starting Download from {REPO_ID} ---")
# 1. Download final_output.csv to the root directory
try:
print("Downloading final_output.csv...")
hf_hub_download(
repo_id=REPO_ID,
filename="final_output.csv",
local_dir=".",
local_dir_use_symlinks=False
)
print("β
final_output.csv downloaded.")
except Exception as e:
print(f"β Error downloading csv: {e}")
# 2. Download 'market_models' folder and move files to 'models/'
try:
print("Downloading market_models...")
market_path = snapshot_download(
repo_id=REPO_ID,
allow_patterns="market_models/*",
local_dir="temp_download",
local_dir_use_symlinks=False
)
# Move files from temp_download/market_models to models/
source_dir = os.path.join(market_path, "market_models")
if os.path.exists(source_dir):
for file_name in os.listdir(source_dir):
full_file_name = os.path.join(source_dir, file_name)
if os.path.isfile(full_file_name):
shutil.move(full_file_name, DEST_MODELS_DIR)
print("β
Market models moved to /models.")
except Exception as e:
print(f"β Error downloading market models: {e}")
# 3. Download 'other_models' folder and move files to 'models/'
try:
print("Downloading other_models...")
other_path = snapshot_download(
repo_id=REPO_ID,
allow_patterns="other_models/*",
local_dir="temp_download_other",
local_dir_use_symlinks=False
)
# Move files from temp_download_other/other_models to models/
source_dir = os.path.join(other_path, "other_models")
if os.path.exists(source_dir):
for file_name in os.listdir(source_dir):
full_file_name = os.path.join(source_dir, file_name)
if os.path.isfile(full_file_name):
shutil.move(full_file_name, DEST_MODELS_DIR)
print("β
Other models moved to /models.")
except Exception as e:
print(f"β Error downloading other models: {e}")
# Cleanup temp folders
shutil.rmtree("temp_download", ignore_errors=True)
shutil.rmtree("temp_download_other", ignore_errors=True)
print("--- Setup Complete ---") |