PrashanthB461 commited on
Commit
969dec6
·
verified ·
1 Parent(s): 937ffb2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -34,7 +34,6 @@ CONFIG = {
34
  },
35
  "PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo1/resolve/main/static/output/",
36
  "FRAME_SKIP": 5,
37
- "MAX_FRAMES": 100,
38
  "MAX_PROCESSING_TIME": 30
39
  }
40
 
@@ -206,10 +205,10 @@ def process_video(video_data):
206
  raise ValueError("Could not open video file")
207
 
208
  violations, snapshots = [], []
209
- frame_count, processed_frames = 0, 0
210
  start_time = time.time()
211
 
212
- while processed_frames < CONFIG["MAX_FRAMES"]:
213
  ret, frame = video.read()
214
  if not ret:
215
  break
@@ -241,7 +240,6 @@ def process_video(video_data):
241
  })
242
 
243
  frame_count += 1
244
- processed_frames += 1
245
  if time.time() - start_time > CONFIG["MAX_PROCESSING_TIME"]:
246
  logger.warning("Processing time limit exceeded")
247
  break
@@ -288,24 +286,19 @@ def gradio_interface(video_file):
288
  rows = []
289
  for v in result["violations"]:
290
  violation_name = v["violation"]
291
- # Replace specific violation names for display
292
  if violation_name == "no_helmet":
293
- violation_name = "no helmet"
294
- elif violation_name == "no_harness":
295
- violation_name = "no harness"
296
- elif violation_name == "unsafe_posture":
297
- violation_name = "unsafe posture"
298
- elif violation_name == "unsafe_zone":
299
- violation_name = "unsafe zone"
300
- row = f"| {violation_name:<13} | {v['timestamp']:.2f}s | {v['confidence']:.2f} | {v['bounding_box']} | [Details]({result['violation_details_url']}) |"
301
  rows.append(row)
302
  violation_table = header + separator + "\n".join(rows)
303
 
304
- # Format snapshots as a bullet list with clickable image links
305
  snapshots_text = "No snapshots captured."
306
  if result["snapshots"]:
307
  snapshots_text = "\n".join(
308
- f"- Snapshot for {s['violation'].replace('no_', '').replace('unsafe_', '')} at frame {s['frame']}: [![Snapshot]({s['snapshot_url']})]({s['snapshot_url']})"
309
  for s in result["snapshots"]
310
  )
311
 
@@ -314,7 +307,7 @@ def gradio_interface(video_file):
314
  f"Safety Score: {result['score']}%",
315
  snapshots_text,
316
  f"Salesforce Record ID: {result['salesforce_record_id'] or 'N/A'}",
317
- result["violation_details_url"] or 'N/A'
318
  )
319
  except Exception as e:
320
  logger.error(f"Error in Gradio interface: {e}")
 
34
  },
35
  "PUBLIC_URL_BASE": "https://huggingface.co/spaces/PrashanthB461/AI_Safety_Demo1/resolve/main/static/output/",
36
  "FRAME_SKIP": 5,
 
37
  "MAX_PROCESSING_TIME": 30
38
  }
39
 
 
205
  raise ValueError("Could not open video file")
206
 
207
  violations, snapshots = [], []
208
+ frame_count = 0
209
  start_time = time.time()
210
 
211
+ while True:
212
  ret, frame = video.read()
213
  if not ret:
214
  break
 
240
  })
241
 
242
  frame_count += 1
 
243
  if time.time() - start_time > CONFIG["MAX_PROCESSING_TIME"]:
244
  logger.warning("Processing time limit exceeded")
245
  break
 
286
  rows = []
287
  for v in result["violations"]:
288
  violation_name = v["violation"]
 
289
  if violation_name == "no_helmet":
290
+ violation_name = "no_helmet"
291
+ else:
292
+ violation_name = violation_name.replace("no_", "").replace("unsafe_", "")
293
+ row = f"| {violation_name:<13} | {v['timestamp']:.2f}s | {v['confidence']:.2f} | {v['bounding_box']} | {result['violation_details_url']} |"
 
 
 
 
294
  rows.append(row)
295
  violation_table = header + separator + "\n".join(rows)
296
 
297
+ # Format snapshots as a bullet list
298
  snapshots_text = "No snapshots captured."
299
  if result["snapshots"]:
300
  snapshots_text = "\n".join(
301
+ f"- Snapshot for {s['violation'].replace('no_', '').replace('unsafe_', '')} at frame {s['frame']}: [{s['snapshot_url']}]({s['snapshot_url']})"
302
  for s in result["snapshots"]
303
  )
304
 
 
307
  f"Safety Score: {result['score']}%",
308
  snapshots_text,
309
  f"Salesforce Record ID: {result['salesforce_record_id'] or 'N/A'}",
310
+ result["violation_details_url"] or "N/A"
311
  )
312
  except Exception as e:
313
  logger.error(f"Error in Gradio interface: {e}")