PrashanthB461 commited on
Commit
3a06ab6
·
verified ·
1 Parent(s): 8ecd397

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -40,7 +40,8 @@ CONFIG = {
40
  "PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo2/resolve/main/static/output/",
41
  "FRAME_SKIP": 1, # Process every frame (set to 1 for full video processing)
42
  "MAX_PROCESSING_TIME": 30,
43
- "CONFIDENCE_THRESHOLD": 0.5
 
44
  }
45
 
46
  # Setup logging
@@ -226,6 +227,7 @@ def process_video(video_data):
226
  fps = video.get(cv2.CAP_PROP_FPS)
227
 
228
  snapshot_taken = {label: False for label in CONFIG["VIOLATION_LABELS"].values()}
 
229
 
230
  while True:
231
  ret, frame = video.read()
@@ -254,10 +256,12 @@ def process_video(video_data):
254
  if label not in CONFIG["VIOLATION_LABELS"].values() or conf < CONFIG["CONFIDENCE_THRESHOLD"]:
255
  continue
256
 
257
- if label in seen_violations:
258
- continue # Avoid duplicates in the same frame
259
-
260
- seen_violations.add(label)
 
 
261
 
262
  # Save the violation data
263
  violation = {
@@ -389,4 +393,4 @@ interface = gr.Interface(
389
 
390
  if __name__ == "__main__":
391
  logger.info("Launching Safety Analyzer App...")
392
- interface.launch()
 
40
  "PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo2/resolve/main/static/output/",
41
  "FRAME_SKIP": 1, # Process every frame (set to 1 for full video processing)
42
  "MAX_PROCESSING_TIME": 30,
43
+ "CONFIDENCE_THRESHOLD": 0.5,
44
+ "TEMPORAL_THRESHOLD": 1.0 # Time threshold in seconds to avoid counting the same violation
45
  }
46
 
47
  # Setup logging
 
227
  fps = video.get(cv2.CAP_PROP_FPS)
228
 
229
  snapshot_taken = {label: False for label in CONFIG["VIOLATION_LABELS"].values()}
230
+ last_detected = {label: 0 for label in CONFIG["VIOLATION_LABELS"].values()} # Tracks last violation time
231
 
232
  while True:
233
  ret, frame = video.read()
 
256
  if label not in CONFIG["VIOLATION_LABELS"].values() or conf < CONFIG["CONFIDENCE_THRESHOLD"]:
257
  continue
258
 
259
+ # Skip if the same violation is detected again within the temporal threshold
260
+ if time.time() - last_detected[label] < CONFIG["TEMPORAL_THRESHOLD"]:
261
+ continue
262
+
263
+ # Update last detected time
264
+ last_detected[label] = time.time()
265
 
266
  # Save the violation data
267
  violation = {
 
393
 
394
  if __name__ == "__main__":
395
  logger.info("Launching Safety Analyzer App...")
396
+ interface.launch()