Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -257,11 +257,7 @@ def process_video(video_data):
|
|
| 257 |
"snapshots": snapshots,
|
| 258 |
"score": score,
|
| 259 |
"salesforce_record_id": report_id,
|
| 260 |
-
"violation_details_url": final_pdf_url
|
| 261 |
-
"violation_details_content": "\n".join(
|
| 262 |
-
f"{v['violation']} at {v['timestamp']:.2f}s (Confidence: {v['confidence']})"
|
| 263 |
-
for v in violations
|
| 264 |
-
) or "No violations detected."
|
| 265 |
}
|
| 266 |
except Exception as e:
|
| 267 |
logger.error(f"Error processing video: {e}")
|
|
@@ -270,8 +266,7 @@ def process_video(video_data):
|
|
| 270 |
"snapshots": [],
|
| 271 |
"score": 0,
|
| 272 |
"salesforce_record_id": None,
|
| 273 |
-
"violation_details_url": ""
|
| 274 |
-
"violation_details_content": f"Error: {str(e)}"
|
| 275 |
}
|
| 276 |
|
| 277 |
# ==========================
|
|
@@ -279,7 +274,7 @@ def process_video(video_data):
|
|
| 279 |
# ==========================
|
| 280 |
def gradio_interface(video_file):
|
| 281 |
if not video_file:
|
| 282 |
-
return "No file uploaded.", "", "No file uploaded.", "", "
|
| 283 |
try:
|
| 284 |
with open(video_file, "rb") as f:
|
| 285 |
video_data = f.read()
|
|
@@ -311,12 +306,11 @@ def gradio_interface(video_file):
|
|
| 311 |
f"Safety Score: {result['score']}%",
|
| 312 |
snapshots_text,
|
| 313 |
f"Salesforce Record ID: {result['salesforce_record_id'] or 'N/A'}",
|
| 314 |
-
f"Violation Details URL: {result['violation_details_url'] or 'N/A'}"
|
| 315 |
-
result["violation_details_content"]
|
| 316 |
)
|
| 317 |
except Exception as e:
|
| 318 |
logger.error(f"Error in Gradio interface: {e}")
|
| 319 |
-
return f"Error: {str(e)}", "", "Error in processing.", "", "
|
| 320 |
|
| 321 |
interface = gr.Interface(
|
| 322 |
fn=gradio_interface,
|
|
@@ -326,8 +320,7 @@ interface = gr.Interface(
|
|
| 326 |
gr.Textbox(label="Compliance Score"),
|
| 327 |
gr.Markdown(label="Snapshots"),
|
| 328 |
gr.Textbox(label="Salesforce Record ID"),
|
| 329 |
-
gr.Textbox(label="Violation Details URL")
|
| 330 |
-
gr.Textbox(label="Violation Details Content")
|
| 331 |
],
|
| 332 |
title="Worksite Safety Violation Analyzer",
|
| 333 |
description="Upload short site videos to detect safety violations (e.g., no helmet, no harness, unsafe posture)."
|
|
|
|
| 257 |
"snapshots": snapshots,
|
| 258 |
"score": score,
|
| 259 |
"salesforce_record_id": report_id,
|
| 260 |
+
"violation_details_url": final_pdf_url
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
}
|
| 262 |
except Exception as e:
|
| 263 |
logger.error(f"Error processing video: {e}")
|
|
|
|
| 266 |
"snapshots": [],
|
| 267 |
"score": 0,
|
| 268 |
"salesforce_record_id": None,
|
| 269 |
+
"violation_details_url": ""
|
|
|
|
| 270 |
}
|
| 271 |
|
| 272 |
# ==========================
|
|
|
|
| 274 |
# ==========================
|
| 275 |
def gradio_interface(video_file):
|
| 276 |
if not video_file:
|
| 277 |
+
return "No file uploaded.", "", "No file uploaded.", "", "No file uploaded."
|
| 278 |
try:
|
| 279 |
with open(video_file, "rb") as f:
|
| 280 |
video_data = f.read()
|
|
|
|
| 306 |
f"Safety Score: {result['score']}%",
|
| 307 |
snapshots_text,
|
| 308 |
f"Salesforce Record ID: {result['salesforce_record_id'] or 'N/A'}",
|
| 309 |
+
f"Violation Details URL: {result['violation_details_url'] or 'N/A'}"
|
|
|
|
| 310 |
)
|
| 311 |
except Exception as e:
|
| 312 |
logger.error(f"Error in Gradio interface: {e}")
|
| 313 |
+
return f"Error: {str(e)}", "", "Error in processing.", "", "Error in processing."
|
| 314 |
|
| 315 |
interface = gr.Interface(
|
| 316 |
fn=gradio_interface,
|
|
|
|
| 320 |
gr.Textbox(label="Compliance Score"),
|
| 321 |
gr.Markdown(label="Snapshots"),
|
| 322 |
gr.Textbox(label="Salesforce Record ID"),
|
| 323 |
+
gr.Textbox(label="Violation Details URL")
|
|
|
|
| 324 |
],
|
| 325 |
title="Worksite Safety Violation Analyzer",
|
| 326 |
description="Upload short site videos to detect safety violations (e.g., no helmet, no harness, unsafe posture)."
|