Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -297,6 +297,10 @@ def push_report_to_salesforce(violations, score, pdf_path, pdf_file):
|
|
| 297 |
|
| 298 |
def process_video(video_data):
|
| 299 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
# Create temp video file
|
| 301 |
video_path = os.path.join(CONFIG["OUTPUT_DIR"], f"temp_{int(time.time())}.mp4")
|
| 302 |
with open(video_path, "wb") as f:
|
|
@@ -306,6 +310,7 @@ def process_video(video_data):
|
|
| 306 |
# Open video file
|
| 307 |
cap = cv2.VideoCapture(video_path)
|
| 308 |
if not cap.isOpened():
|
|
|
|
| 309 |
raise ValueError("Could not open video file")
|
| 310 |
|
| 311 |
# Get video properties
|
|
@@ -419,7 +424,8 @@ def process_video(video_data):
|
|
| 419 |
violation_tracker[worker_id][label].append(detection)
|
| 420 |
|
| 421 |
cap.release()
|
| 422 |
-
os.
|
|
|
|
| 423 |
processing_time = time.time() - start_time
|
| 424 |
logger.info(f"Processing complete in {processing_time:.2f}s")
|
| 425 |
|
|
@@ -482,6 +488,8 @@ def process_video(video_data):
|
|
| 482 |
|
| 483 |
except Exception as e:
|
| 484 |
logger.error(f"Error processing video: {e}", exc_info=True)
|
|
|
|
|
|
|
| 485 |
yield f"Error processing video: {e}", "", "", "", ""
|
| 486 |
|
| 487 |
def gradio_interface(video_file):
|
|
|
|
| 297 |
|
| 298 |
def process_video(video_data):
|
| 299 |
try:
|
| 300 |
+
# Ensure output directory exists
|
| 301 |
+
os.makedirs(CONFIG["OUTPUT_DIR"], exist_ok=True)
|
| 302 |
+
logger.info(f"Output directory ensured: {CONFIG['OUTPUT_DIR']}")
|
| 303 |
+
|
| 304 |
# Create temp video file
|
| 305 |
video_path = os.path.join(CONFIG["OUTPUT_DIR"], f"temp_{int(time.time())}.mp4")
|
| 306 |
with open(video_path, "wb") as f:
|
|
|
|
| 310 |
# Open video file
|
| 311 |
cap = cv2.VideoCapture(video_path)
|
| 312 |
if not cap.isOpened():
|
| 313 |
+
os.remove(video_path)
|
| 314 |
raise ValueError("Could not open video file")
|
| 315 |
|
| 316 |
# Get video properties
|
|
|
|
| 424 |
violation_tracker[worker_id][label].append(detection)
|
| 425 |
|
| 426 |
cap.release()
|
| 427 |
+
if os.path.exists(video_path):
|
| 428 |
+
os.remove(video_path)
|
| 429 |
processing_time = time.time() - start_time
|
| 430 |
logger.info(f"Processing complete in {processing_time:.2f}s")
|
| 431 |
|
|
|
|
| 488 |
|
| 489 |
except Exception as e:
|
| 490 |
logger.error(f"Error processing video: {e}", exc_info=True)
|
| 491 |
+
if 'video_path' in locals() and os.path.exists(video_path):
|
| 492 |
+
os.remove(video_path)
|
| 493 |
yield f"Error processing video: {e}", "", "", "", ""
|
| 494 |
|
| 495 |
def gradio_interface(video_file):
|