Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -315,7 +315,8 @@ def process_video(video_data):
|
|
| 315 |
|
| 316 |
def gradio_interface(video_file):
|
| 317 |
if not video_file:
|
| 318 |
-
return "
|
|
|
|
| 319 |
try:
|
| 320 |
yield "Processing video... please wait.", "", "", "", ""
|
| 321 |
|
|
@@ -324,25 +325,26 @@ def gradio_interface(video_file):
|
|
| 324 |
|
| 325 |
result = process_video(video_data)
|
| 326 |
|
| 327 |
-
if
|
| 328 |
-
|
|
|
|
|
|
|
| 329 |
return
|
| 330 |
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
snapshots_text = "
|
| 344 |
if result["snapshots"]:
|
| 345 |
-
violation_name_map = CONFIG["DISPLAY_NAMES"]
|
| 346 |
snapshots_text = "\n".join(
|
| 347 |
f"- Snapshot for {violation_name_map.get(s['violation'], s['violation'])} at frame {s['frame']}: "
|
| 348 |
for s in result["snapshots"]
|
|
@@ -357,7 +359,7 @@ def gradio_interface(video_file):
|
|
| 357 |
)
|
| 358 |
except Exception as e:
|
| 359 |
logger.error(f"Error in Gradio interface: {e}", exc_info=True)
|
| 360 |
-
yield f"Error: {str(e)}", "", "
|
| 361 |
|
| 362 |
interface = gr.Interface(
|
| 363 |
fn=gradio_interface,
|
|
|
|
| 315 |
|
| 316 |
def gradio_interface(video_file):
|
| 317 |
if not video_file:
|
| 318 |
+
return "", "", "", "", "" # Return empty outputs when no file uploaded
|
| 319 |
+
|
| 320 |
try:
|
| 321 |
yield "Processing video... please wait.", "", "", "", ""
|
| 322 |
|
|
|
|
| 325 |
|
| 326 |
result = process_video(video_data)
|
| 327 |
|
| 328 |
+
# Only output violations if detected, else output nothing or minimal
|
| 329 |
+
if not result["violations"]:
|
| 330 |
+
# No violations detected — return empty or minimal outputs
|
| 331 |
+
yield "", "", "", "", ""
|
| 332 |
return
|
| 333 |
|
| 334 |
+
# Build violation table only if violations exist
|
| 335 |
+
header = "| Violation | Timestamp (s) | Confidence | Bounding Box |\n"
|
| 336 |
+
separator = "|------------------------|---------------|------------|--------------------------|\n"
|
| 337 |
+
rows = []
|
| 338 |
+
violation_name_map = CONFIG["DISPLAY_NAMES"]
|
| 339 |
+
for v in result["violations"]:
|
| 340 |
+
display_name = violation_name_map.get(v["violation"], v["violation"])
|
| 341 |
+
row = f"| {display_name:<22} | {v['timestamp']:.2f} | {v['confidence']:.2f} | {v['bounding_box']} |"
|
| 342 |
+
rows.append(row)
|
| 343 |
+
violation_table = header + separator + "\n".join(rows)
|
| 344 |
+
|
| 345 |
+
# Prepare snapshots if available
|
| 346 |
+
snapshots_text = ""
|
| 347 |
if result["snapshots"]:
|
|
|
|
| 348 |
snapshots_text = "\n".join(
|
| 349 |
f"- Snapshot for {violation_name_map.get(s['violation'], s['violation'])} at frame {s['frame']}: "
|
| 350 |
for s in result["snapshots"]
|
|
|
|
| 359 |
)
|
| 360 |
except Exception as e:
|
| 361 |
logger.error(f"Error in Gradio interface: {e}", exc_info=True)
|
| 362 |
+
yield f"Error: {str(e)}", "", "", "", ""
|
| 363 |
|
| 364 |
interface = gr.Interface(
|
| 365 |
fn=gradio_interface,
|