itsluckysharma01 commited on
Commit
83e3e20
Β·
verified Β·
1 Parent(s): 8866e2b

Upload 5 files

Browse files
login.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ from huggingface_hub import login
2
+
3
+ # Terminal-friendly login
4
+ login()
requirements.txt ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # AI & Computer Vision
2
+ torch>=2.0.0
3
+ torchvision>=0.15.0
4
+ ultralytics>=8.0.0
5
+ opencv-python>=4.8.0
6
+ numpy>=1.24.0
7
+ pillow>=10.0.0
8
+ pandas>=2.0.0
9
+ scikit-learn>=1.3.0
10
+
11
+ # Backend Framework
12
+ fastapi>=0.104.0
13
+ uvicorn[standard]>=0.24.0
14
+ python-multipart>=0.0.6
15
+ websockets>=12.0
16
+
17
+ # Database
18
+ sqlalchemy>=2.0.0
19
+ psycopg2-binary>=2.9.0
20
+ alembic>=1.12.0
21
+
22
+ # Alert Services
23
+ twilio>=8.10.0
24
+ python-dotenv>=1.0.0
25
+
26
+ # Utilities
27
+ pydantic>=2.0.0
28
+ python-jose[cryptography]>=3.3.0
29
+ passlib[bcrypt]>=1.7.4
30
+ aiofiles>=23.2.1
31
+
32
+ # Model Management
33
+ huggingface-hub>=0.16.0
34
+ # =======
35
+ torch
36
+ ultralytics
37
+ opencv-python
38
+ numpy
39
+ pandas
40
+ fastapi
41
+ uvicorn
42
+ scikit-learn
test_app_portability.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Test script to verify app.py portability logic
3
+ Simulates app.py being in different locations
4
+ """
5
+
6
+ from pathlib import Path
7
+ import sys
8
+
9
+ def test_portability_logic(app_location):
10
+ """Test the portability logic as if app.py was at app_location"""
11
+
12
+ # Simulate app.py's __file__ being at app_location
13
+ print(f"\nπŸ“ Testing with app.py at: {app_location}")
14
+ print("-" * 60)
15
+
16
+ # This is the exact logic from app.py
17
+ webapp_parent = app_location.parent.parent
18
+ if (webapp_parent / 'config').exists():
19
+ PROJECT_ROOT = webapp_parent
20
+ location_type = "Original location (webapp/)"
21
+ else:
22
+ # app.py was moved - find project root by searching for config/
23
+ PROJECT_ROOT = app_location.parent
24
+ while PROJECT_ROOT != PROJECT_ROOT.parent: # Until root of filesystem
25
+ if (PROJECT_ROOT / 'config').exists() and (PROJECT_ROOT / 'src').exists():
26
+ break
27
+ PROJECT_ROOT = PROJECT_ROOT.parent
28
+ location_type = "Moved location (outside webapp/)"
29
+
30
+ # Determine webapp folder (for templates/static/uploads)
31
+ WEBAPP_FOLDER = PROJECT_ROOT / 'webapp'
32
+
33
+ # Print results
34
+ print(f"Location type: {location_type}")
35
+ print(f"PROJECT_ROOT: {PROJECT_ROOT}")
36
+ print(f"WEBAPP_FOLDER: {WEBAPP_FOLDER}")
37
+
38
+ # Verify all required folders exist
39
+ required_folders = ['config', 'src', 'webapp', 'ai_models', 'docs']
40
+ all_exist = True
41
+ print(f"\nRequired folders check:")
42
+ for folder in required_folders:
43
+ exists = (PROJECT_ROOT / folder).exists()
44
+ status = "βœ“" if exists else "βœ—"
45
+ print(f" {status} {folder}")
46
+ all_exist = all_exist and exists
47
+
48
+ # Check template and static folders
49
+ print(f"\nFlask folders check:")
50
+ templates_exist = (WEBAPP_FOLDER / 'templates').exists()
51
+ static_exist = (WEBAPP_FOLDER / 'static').exists()
52
+ print(f" {'βœ“' if templates_exist else 'βœ—'} templates/")
53
+ print(f" {'βœ“' if static_exist else 'βœ—'} static/")
54
+
55
+ return all_exist and templates_exist and static_exist
56
+
57
+ # Test 1: Original location (webapp/app.py)
58
+ project_root = Path(__file__).parent
59
+ result1 = test_portability_logic(project_root / 'webapp' / 'app.py')
60
+
61
+ # Test 2: Moved to project root (app.py)
62
+ result2 = test_portability_logic(project_root / 'app.py')
63
+
64
+ # Test 3: Moved to src (src/app.py)
65
+ result3 = test_portability_logic(project_root / 'src' / 'app.py')
66
+
67
+ # Summary
68
+ print("\n" + "=" * 60)
69
+ print("PORTABILITY TEST SUMMARY")
70
+ print("=" * 60)
71
+ print(f"βœ“ Original location (webapp/app.py): {'PASS' if result1 else 'FAIL'}")
72
+ print(f"{'βœ“' if result2 else 'βœ—'} Moved to root (app.py): {'PASS' if result2 else 'FAIL'}")
73
+ print(f"{'βœ“' if result3 else 'βœ—'} Moved to src (src/app.py): {'PASS' if result3 else 'FAIL'}")
74
+
75
+ if result1 and result2 and result3:
76
+ print("\nβœ… app.py IS PORTABLE - Can be used anywhere in the project!")
77
+ else:
78
+ print("\n❌ app.py is NOT fully portable")
upload_models.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import HfApi
2
+ from pathlib import Path
3
+ import os
4
+
5
+ api = HfApi()
6
+ repo_id = "itsluckysharma01/NETRA-Models"
7
+
8
+ print("πŸ“ Creating repository on Hugging Face Hub...")
9
+ try:
10
+ api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True)
11
+ print("βœ… Repository ready!\n")
12
+ except Exception as e:
13
+ print(f"Error: {e}\n")
14
+
15
+ # Upload individual models with timeout and retry
16
+ models_dir = Path("ai_models")
17
+
18
+ def upload_with_retry(file_path, max_retries=3):
19
+ """Upload a file with retry logic"""
20
+ for attempt in range(max_retries):
21
+ try:
22
+ print(f"πŸ“€ Uploading: {file_path} (Attempt {attempt+1}/{max_retries})")
23
+ api.upload_file(
24
+ path_or_fileobj=str(file_path),
25
+ path_in_repo=str(file_path),
26
+ repo_id=repo_id,
27
+ repo_type="model",
28
+ commit_message=f"Upload {file_path.name}"
29
+ )
30
+ print(f"βœ… Success: {file_path}\n")
31
+ return True
32
+ except Exception as e:
33
+ if attempt < max_retries - 1:
34
+ print(f"⚠️ Attempt {attempt+1} failed: {str(e)[:100]}")
35
+ print(f" Retrying...\n")
36
+ else:
37
+ print(f"❌ Failed after {max_retries} attempts: {file_path}\n")
38
+ return False
39
+
40
+ # Upload main models
41
+ main_models = [
42
+ "ai_models/activity_recognition/violence_model.h5",
43
+ "ai_models/object_detection/yolov8n.pt",
44
+ "ai_models/pose_detection/yolo11n-pose.pt",
45
+ "ai_models/weapon_detection/best.pt",
46
+ ]
47
+
48
+ print("=" * 60)
49
+ print("UPLOADING MAIN MODELS")
50
+ print("=" * 60 + "\n")
51
+
52
+ for model in main_models:
53
+ if os.path.exists(model):
54
+ upload_with_retry(model)
55
+ else:
56
+ print(f"❌ File not found: {model}\n")
57
+
58
+ # Upload analysis models folder (one file at a time)
59
+ print("=" * 60)
60
+ print("UPLOADING ANALYSIS MODELS")
61
+ print("=" * 60 + "\n")
62
+
63
+ analysis_dir = Path("ai_models/analysis_models")
64
+ if analysis_dir.exists():
65
+ for model_file in analysis_dir.glob("**/*"):
66
+ if model_file.is_file():
67
+ upload_with_retry(model_file)
68
+ else:
69
+ print(f"❌ Directory not found: {analysis_dir}\n")
70
+
71
+ print("\n" + "=" * 60)
72
+ print("πŸŽ‰ UPLOAD PROCESS COMPLETE!")
73
+ print("=" * 60)
74
+ print(f"πŸ“Š View your models: https://huggingface.co/{repo_id}")
verify_gun_detector.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Verify GunDetector.pt is prioritized"""
2
+ from config import get_model_path
3
+
4
+ weapon_gun_path = get_model_path('weapon', 'gun')
5
+ print("=== WEAPON MODEL CHECK ===\n")
6
+ print(f"Primary weapon model: {weapon_gun_path}")
7
+ print(f"Using GunDetector.pt: {'βœ“ YES' if 'GunDetector' in str(weapon_gun_path) else 'βœ— NO'}")
8
+ print(f"File exists: {weapon_gun_path.exists() if weapon_gun_path else False}\n")
9
+
10
+ if 'GunDetector' in str(weapon_gun_path):
11
+ print("βœ… GunDetector.pt is now the primary weapon model!")
12
+ else:
13
+ print("❌ Still using best.pt")