Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,8 @@ for root, dirs, files in os.walk(base_path):
|
|
| 14 |
break
|
| 15 |
|
| 16 |
# Step 2: If best.pt is not found, use pre-trained weights
|
|
|
|
|
|
|
| 17 |
if best_path is None:
|
| 18 |
print("Trained weights (best.pt) not found.")
|
| 19 |
print("Using pre-trained YOLOv5 weights (yolov5s.pt) instead.")
|
|
@@ -29,6 +31,10 @@ else:
|
|
| 29 |
print(f"Error loading custom model: {e}")
|
| 30 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # Fallback to pre-trained model
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Step 3: Define weapon classes to detect
|
| 33 |
weapon_classes = ['bomb', 'gun', 'pistol', 'Automatic', 'Rifle', 'Bazooka',
|
| 34 |
'Handgun', 'Knife', 'Grenade Launcher', 'Shotgun', 'SMG',
|
|
@@ -85,3 +91,4 @@ iface = gr.Interface(
|
|
| 85 |
|
| 86 |
# Step 5: Launch Gradio App
|
| 87 |
iface.launch()
|
|
|
|
|
|
| 14 |
break
|
| 15 |
|
| 16 |
# Step 2: If best.pt is not found, use pre-trained weights
|
| 17 |
+
model = None # Ensure model is defined
|
| 18 |
+
|
| 19 |
if best_path is None:
|
| 20 |
print("Trained weights (best.pt) not found.")
|
| 21 |
print("Using pre-trained YOLOv5 weights (yolov5s.pt) instead.")
|
|
|
|
| 31 |
print(f"Error loading custom model: {e}")
|
| 32 |
model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # Fallback to pre-trained model
|
| 33 |
|
| 34 |
+
# Ensure the model was loaded properly before proceeding
|
| 35 |
+
if model is None:
|
| 36 |
+
raise RuntimeError("Failed to load YOLOv5 model. Please check the weights or model path.")
|
| 37 |
+
|
| 38 |
# Step 3: Define weapon classes to detect
|
| 39 |
weapon_classes = ['bomb', 'gun', 'pistol', 'Automatic', 'Rifle', 'Bazooka',
|
| 40 |
'Handgun', 'Knife', 'Grenade Launcher', 'Shotgun', 'SMG',
|
|
|
|
| 91 |
|
| 92 |
# Step 5: Launch Gradio App
|
| 93 |
iface.launch()
|
| 94 |
+
v
|