Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -49,10 +49,23 @@ def process_image(image):
|
|
49 |
# Detect objects (e.g., helmets) in the frame
|
50 |
items = detect_objects(frame)
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
if items: # If objects are detected, save the data
|
53 |
save_data(frame, items)
|
54 |
|
55 |
-
return {"items_detected": items}
|
56 |
|
57 |
def save_data(frame, items):
|
58 |
"""Save image and extract plate number."""
|
@@ -76,7 +89,7 @@ def save_to_database(image_filename, plate_number, items):
|
|
76 |
# Define the Gradio interface using updated syntax
|
77 |
interface = gr.Interface(fn=process_image,
|
78 |
inputs=gr.Image(type="pil"),
|
79 |
-
outputs=gr.JSON(),
|
80 |
live=True)
|
81 |
|
82 |
# Launch the Gradio app
|
|
|
49 |
# Detect objects (e.g., helmets) in the frame
|
50 |
items = detect_objects(frame)
|
51 |
|
52 |
+
# Check if helmet is detected (you can adapt this based on your model's labels)
|
53 |
+
helmet_detected = False
|
54 |
+
for score, label, box in items:
|
55 |
+
if model.config.id2label[label] == "helmet": # Replace "helmet" with the actual class name in your model
|
56 |
+
helmet_detected = True
|
57 |
+
|
58 |
+
# If no helmet detected, show a traffic violation notification
|
59 |
+
if not helmet_detected:
|
60 |
+
violation_message = "Serious Traffic Violation: Rider not wearing a helmet!"
|
61 |
+
else:
|
62 |
+
violation_message = "Helmet detected: No violation."
|
63 |
+
|
64 |
+
# Save the image with detected items
|
65 |
if items: # If objects are detected, save the data
|
66 |
save_data(frame, items)
|
67 |
|
68 |
+
return {"items_detected": items, "violation_message": violation_message}
|
69 |
|
70 |
def save_data(frame, items):
|
71 |
"""Save image and extract plate number."""
|
|
|
89 |
# Define the Gradio interface using updated syntax
|
90 |
interface = gr.Interface(fn=process_image,
|
91 |
inputs=gr.Image(type="pil"),
|
92 |
+
outputs=[gr.JSON(), gr.Textbox()],
|
93 |
live=True)
|
94 |
|
95 |
# Launch the Gradio app
|