Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -279,30 +279,43 @@ def process_video(video_data):
|
|
| 279 |
# ==========================
|
| 280 |
def gradio_interface(video_file):
|
| 281 |
if not video_file:
|
| 282 |
-
return
|
| 283 |
try:
|
| 284 |
with open(video_file, "rb") as f:
|
| 285 |
video_data = f.read()
|
| 286 |
result = process_video(video_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
return (
|
| 288 |
-
|
| 289 |
f"Safety Score: {result['score']}%",
|
| 290 |
-
|
| 291 |
f"Salesforce Record ID: {result['salesforce_record_id'] or 'N/A'}",
|
| 292 |
f"Violation Details URL: {result['violation_details_url'] or 'N/A'}",
|
| 293 |
result["violation_details_content"]
|
| 294 |
)
|
| 295 |
except Exception as e:
|
| 296 |
logger.error(f"Error in Gradio interface: {e}")
|
| 297 |
-
return
|
| 298 |
|
| 299 |
interface = gr.Interface(
|
| 300 |
fn=gradio_interface,
|
| 301 |
inputs=gr.Video(label="Upload Site Video"),
|
| 302 |
outputs=[
|
| 303 |
-
gr.
|
| 304 |
gr.Textbox(label="Compliance Score"),
|
| 305 |
-
gr.
|
| 306 |
gr.Textbox(label="Salesforce Record ID"),
|
| 307 |
gr.Textbox(label="Violation Details URL"),
|
| 308 |
gr.Textbox(label="Violation Details Content")
|
|
|
|
| 279 |
# ==========================
|
| 280 |
def gradio_interface(video_file):
|
| 281 |
if not video_file:
|
| 282 |
+
return "No video file uploaded.", "", "No snapshots.", "", "", "No file uploaded."
|
| 283 |
try:
|
| 284 |
with open(video_file, "rb") as f:
|
| 285 |
video_data = f.read()
|
| 286 |
result = process_video(video_data)
|
| 287 |
+
|
| 288 |
+
# Convert violations to text format
|
| 289 |
+
violations_text = "\n".join(
|
| 290 |
+
f"Violation: {v['violation']}, Timestamp: {v['timestamp']:.2f}s, Confidence: {v['confidence']}, Bounding Box: {v['bounding_box']}"
|
| 291 |
+
for v in result["violations"]
|
| 292 |
+
) or "No violations detected."
|
| 293 |
+
|
| 294 |
+
# Convert snapshots to text format
|
| 295 |
+
snapshots_text = "\n".join(
|
| 296 |
+
f"Violation: {s['violation']}, Frame: {s['frame']}, Snapshot URL: {s['snapshot_url']}"
|
| 297 |
+
for s in result["snapshots"]
|
| 298 |
+
) or "No snapshots captured."
|
| 299 |
+
|
| 300 |
return (
|
| 301 |
+
violations_text,
|
| 302 |
f"Safety Score: {result['score']}%",
|
| 303 |
+
snapshots_text,
|
| 304 |
f"Salesforce Record ID: {result['salesforce_record_id'] or 'N/A'}",
|
| 305 |
f"Violation Details URL: {result['violation_details_url'] or 'N/A'}",
|
| 306 |
result["violation_details_content"]
|
| 307 |
)
|
| 308 |
except Exception as e:
|
| 309 |
logger.error(f"Error in Gradio interface: {e}")
|
| 310 |
+
return f"Error: {str(e)}", "", "No snapshots.", "", "", "Error in processing."
|
| 311 |
|
| 312 |
interface = gr.Interface(
|
| 313 |
fn=gradio_interface,
|
| 314 |
inputs=gr.Video(label="Upload Site Video"),
|
| 315 |
outputs=[
|
| 316 |
+
gr.Textbox(label="Detected Safety Violations"),
|
| 317 |
gr.Textbox(label="Compliance Score"),
|
| 318 |
+
gr.Textbox(label="Snapshots"),
|
| 319 |
gr.Textbox(label="Salesforce Record ID"),
|
| 320 |
gr.Textbox(label="Violation Details URL"),
|
| 321 |
gr.Textbox(label="Violation Details Content")
|