PrashanthB461 commited on
Commit
2b4f925
·
verified ·
1 Parent(s): f36c6cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -18
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 "No file uploaded.", "", "No file uploaded.", "", ""
 
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 result.get("message"):
328
- yield result["message"], "", "", "", ""
 
 
329
  return
330
 
331
- violation_table = "No violations detected."
332
- if result["violations"]:
333
- header = "| Violation | Timestamp (s) | Confidence | Bounding Box |\n"
334
- separator = "|------------------------|---------------|------------|--------------------------|\n"
335
- rows = []
336
- violation_name_map = CONFIG["DISPLAY_NAMES"]
337
- for v in result["violations"]:
338
- display_name = violation_name_map.get(v["violation"], v["violation"])
339
- row = f"| {display_name:<22} | {v['timestamp']:.2f} | {v['confidence']:.2f} | {v['bounding_box']} |"
340
- rows.append(row)
341
- violation_table = header + separator + "\n".join(rows)
342
-
343
- snapshots_text = "No snapshots captured."
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']}: ![]({s['snapshot_base64']})"
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)}", "", "Error in processing.", "", ""
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']}: ![]({s['snapshot_base64']})"
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,