File size: 2,297 Bytes
4ed7d03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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}")