PrashanthB461 commited on
Commit
8a4e253
·
verified ·
1 Parent(s): d1c5c67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -13,6 +13,7 @@ from io import BytesIO
13
  import base64
14
  import logging
15
  from retrying import retry
 
16
 
17
  # ==========================
18
  # Configuration
@@ -24,7 +25,7 @@ CONFIG = {
24
  0: "no_helmet",
25
  1: "no_harness",
26
  2: "unsafe_posture",
27
- 3: "unsafe_zone" # Ignored in scoring and table
28
  },
29
  "DISPLAY_NAMES": { # Mapping for user-friendly violation names
30
  "no_helmet": "Missing Helmet",
@@ -108,15 +109,18 @@ def generate_violation_pdf(violations, score):
108
  y_position -= 0.3 * inch
109
  c.drawString(1 * inch, y_position, "Violation Details:")
110
  y_position -= 0.3 * inch
111
- for v in violations:
112
- display_name = CONFIG["DISPLAY_NAMES"].get(v["violation"], v["violation"])
113
- text = f"{display_name} at {v['timestamp']:.2f}s (Confidence: {v['confidence']})"
114
- c.drawString(1 * inch, y_position, text)
115
- y_position -= 0.3 * inch
116
- if y_position < 1 * inch:
117
- c.showPage()
118
- c.setFont("Helvetica", 10)
119
- y_position = 10 * inch
 
 
 
120
 
121
  c.showPage()
122
  c.save()
@@ -260,7 +264,7 @@ def process_video(video_data):
260
  label = CONFIG["VIOLATION_LABELS"].get(cls, f"unknown_class_{cls}")
261
  # Only process specified violations
262
  if label not in ["no_helmet", "no_harness", "unsafe_posture"]:
263
- logger.warning(f"Ignoring detection: {label} (cls: {cls}, conf: {conf}) - not a target violation")
264
  continue
265
  # Apply confidence threshold
266
  if conf < CONFIG["CONFIDENCE_THRESHOLD"]:
 
13
  import base64
14
  import logging
15
  from retrying import retry
16
+ import uuid
17
 
18
  # ==========================
19
  # Configuration
 
25
  0: "no_helmet",
26
  1: "no_harness",
27
  2: "unsafe_posture",
28
+ 3: "unsafe_zone" # Ignored in processing
29
  },
30
  "DISPLAY_NAMES": { # Mapping for user-friendly violation names
31
  "no_helmet": "Missing Helmet",
 
109
  y_position -= 0.3 * inch
110
  c.drawString(1 * inch, y_position, "Violation Details:")
111
  y_position -= 0.3 * inch
112
+ if not violations:
113
+ c.drawString(1 * inch, y_position, "No violations detected.")
114
+ else:
115
+ for v in violations:
116
+ display_name = CONFIG["DISPLAY_NAMES"].get(v["violation"], v["violation"])
117
+ text = f"{display_name} at {v['timestamp']:.2f}s (Confidence: {v['confidence']})"
118
+ c.drawString(1 * inch, y_position, text)
119
+ y_position -= 0.3 * inch
120
+ if y_position < 1 * inch:
121
+ c.showPage()
122
+ c.setFont("Helvetica", 10)
123
+ y_position = 10 * inch
124
 
125
  c.showPage()
126
  c.save()
 
264
  label = CONFIG["VIOLATION_LABELS"].get(cls, f"unknown_class_{cls}")
265
  # Only process specified violations
266
  if label not in ["no_helmet", "no_harness", "unsafe_posture"]:
267
+ logger.info(f"Ignoring detection: {label} (cls: {cls}, conf: {conf}) - not a target violation")
268
  continue
269
  # Apply confidence threshold
270
  if conf < CONFIG["CONFIDENCE_THRESHOLD"]: