PrashanthB461 commited on
Commit
a71c85c
·
verified ·
1 Parent(s): 5b97100

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -211,17 +211,17 @@ CONFIG = {
211
  "improper_tool_use": 0.3
212
  },
213
  "MIN_VIOLATION_FRAMES": 1,
214
- "VIOLATION_COOLDOWN": 30.0, # Increased cooldown period
215
  "WORKER_TRACKING_DURATION": 5.0,
216
  "MAX_PROCESSING_TIME": 60,
217
- "FRAME_SKIP": 2, # Skip more frames for faster processing
218
  "BATCH_SIZE": 16,
219
  "PARALLEL_WORKERS": max(1, cpu_count() - 1),
220
  "TRACK_BUFFER": 30,
221
  "TRACK_THRESH": 0.3,
222
  "MATCH_THRESH": 0.7,
223
- "SNAPSHOT_QUALITY": 95, # Higher quality for better visibility
224
- "MAX_WORKER_DISTANCE": 100 # Maximum pixel distance to consider same worker
225
  }
226
 
227
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
@@ -498,7 +498,7 @@ def push_report_to_salesforce(violations, score, pdf_path, pdf_file):
498
  return None, ""
499
 
500
  def process_video(video_data):
501
- """Process video to detect safety violations"""
502
  try:
503
  os.makedirs(CONFIG["OUTPUT_DIR"], exist_ok=True)
504
  logger.info(f"Output directory ensured: {CONFIG['OUTPUT_DIR']}")
@@ -528,7 +528,7 @@ def process_video(video_data):
528
  )
529
 
530
  # Track unique violations by worker ID
531
- unique_violations = {} # {worker_id: {violation_type: first_detection_time}}
532
  snapshots = []
533
  start_time = time.time()
534
  frame_skip = CONFIG["FRAME_SKIP"]
@@ -620,7 +620,11 @@ def process_video(video_data):
620
  # Check if this violation type has been recorded for this worker
621
  if label not in unique_violations[worker_id]:
622
  # This is a new violation type for this worker
623
- unique_violations[worker_id][label] = current_time
 
 
 
 
624
 
625
  # Create detection object
626
  detection = {
@@ -676,11 +680,13 @@ def process_video(video_data):
676
  # Convert tracked violations to final violation list
677
  violations = []
678
  for worker_id, worker_violations in unique_violations.items():
679
- for label, detection_time in worker_violations.items():
680
  violation = {
681
  "worker_id": worker_id,
682
  "violation": label,
683
- "timestamp": detection_time
 
 
684
  }
685
  violations.append(violation)
686
 
 
211
  "improper_tool_use": 0.3
212
  },
213
  "MIN_VIOLATION_FRAMES": 1,
214
+ "VIOLATION_COOLDOWN": 30.0,
215
  "WORKER_TRACKING_DURATION": 5.0,
216
  "MAX_PROCESSING_TIME": 60,
217
+ "FRAME_SKIP": 2,
218
  "BATCH_SIZE": 16,
219
  "PARALLEL_WORKERS": max(1, cpu_count() - 1),
220
  "TRACK_BUFFER": 30,
221
  "TRACK_THRESH": 0.3,
222
  "MATCH_THRESH": 0.7,
223
+ "SNAPSHOT_QUALITY": 95,
224
+ "MAX_WORKER_DISTANCE": 100
225
  }
226
 
227
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
498
  return None, ""
499
 
500
  def process_video(video_data):
501
+ """Process video to detect safety violations with de-duplication"""
502
  try:
503
  os.makedirs(CONFIG["OUTPUT_DIR"], exist_ok=True)
504
  logger.info(f"Output directory ensured: {CONFIG['OUTPUT_DIR']}")
 
528
  )
529
 
530
  # Track unique violations by worker ID
531
+ unique_violations = {} # {worker_id: {violation_type: {"timestamp": float, "confidence": float, "bbox": list}}}
532
  snapshots = []
533
  start_time = time.time()
534
  frame_skip = CONFIG["FRAME_SKIP"]
 
620
  # Check if this violation type has been recorded for this worker
621
  if label not in unique_violations[worker_id]:
622
  # This is a new violation type for this worker
623
+ unique_violations[worker_id][label] = {
624
+ "timestamp": current_time,
625
+ "confidence": round(conf, 2),
626
+ "bbox": bbox
627
+ }
628
 
629
  # Create detection object
630
  detection = {
 
680
  # Convert tracked violations to final violation list
681
  violations = []
682
  for worker_id, worker_violations in unique_violations.items():
683
+ for label, info in worker_violations.items():
684
  violation = {
685
  "worker_id": worker_id,
686
  "violation": label,
687
+ "timestamp": info["timestamp"],
688
+ "confidence": info["confidence"],
689
+ "bounding_box": info["bbox"]
690
  }
691
  violations.append(violation)
692