from huggingface_hub import HfApi from pathlib import Path import os api = HfApi() repo_id = "itsluckysharma01/NETRA-Models" print("📁 Creating repository on Hugging Face Hub...") try: api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True) print("✅ Repository ready!\n") except Exception as e: print(f"Error: {e}\n") # Upload individual models with timeout and retry models_dir = Path("ai_models") def upload_with_retry(file_path, max_retries=3): """Upload a file with retry logic""" for attempt in range(max_retries): try: print(f"📤 Uploading: {file_path} (Attempt {attempt+1}/{max_retries})") api.upload_file( path_or_fileobj=str(file_path), path_in_repo=str(file_path), repo_id=repo_id, repo_type="model", commit_message=f"Upload {file_path.name}" ) print(f"✅ Success: {file_path}\n") return True except Exception as e: if attempt < max_retries - 1: print(f"⚠️ Attempt {attempt+1} failed: {str(e)[:100]}") print(f" Retrying...\n") else: print(f"❌ Failed after {max_retries} attempts: {file_path}\n") return False # Upload main models main_models = [ "ai_models/activity_recognition/violence_model.h5", "ai_models/object_detection/yolov8n.pt", "ai_models/pose_detection/yolo11n-pose.pt", "ai_models/weapon_detection/best.pt", ] print("=" * 60) print("UPLOADING MAIN MODELS") print("=" * 60 + "\n") for model in main_models: if os.path.exists(model): upload_with_retry(model) else: print(f"❌ File not found: {model}\n") # Upload analysis models folder (one file at a time) print("=" * 60) print("UPLOADING ANALYSIS MODELS") print("=" * 60 + "\n") analysis_dir = Path("ai_models/analysis_models") if analysis_dir.exists(): for model_file in analysis_dir.glob("**/*"): if model_file.is_file(): upload_with_retry(model_file) else: print(f"❌ Directory not found: {analysis_dir}\n") print("\n" + "=" * 60) print("🎉 UPLOAD PROCESS COMPLETE!") print("=" * 60) print(f"📊 View your models: https://huggingface.co/{repo_id}")