| 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") |
|
|
| |
| 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 |
|
|
| |
| 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") |
|
|
| |
| 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}") |