Sivainti commited on
Commit
fcd2674
·
verified ·
1 Parent(s): 90c32a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -364,18 +364,22 @@ class AttendanceSystem:
364
  def _processing_loop(self, source):
365
  video_capture = cv2.VideoCapture(source)
366
  if not video_capture.isOpened():
367
- self.error_message = "❌ Error: Could not open video source."
 
368
  self.is_processing.clear()
369
  return
370
 
371
  tracker = FaceTracker(self)
 
372
  while self.is_processing.is_set():
373
  ret, frame = video_capture.read()
374
  if not ret:
 
375
  break
376
 
377
  self.current_frame = frame.copy()
378
  annotated_frame = tracker.update(self.current_frame)
 
379
 
380
  if not self.frame_queue.full():
381
  self.frame_queue.put(annotated_frame)
@@ -386,6 +390,7 @@ class AttendanceSystem:
386
  pass
387
  self.frame_queue.put(annotated_frame)
388
 
 
389
  time.sleep(0.01)
390
 
391
  video_capture.release()
@@ -478,8 +483,10 @@ def create_interface():
478
 
479
  def start_wrapper(tab_index, cam_src, vid_path):
480
  source = int(cam_src) if tab_index == 0 else vid_path
481
- return "Please provide an input source." if source is None else attendance_system.start_processing(source)
482
-
 
 
483
  start_btn.click(fn=start_wrapper, inputs=[selected_tab_index, camera_source, video_file], outputs=[status_box])
484
  stop_btn.click(fn=attendance_system.stop_processing, inputs=None, outputs=[status_box])
485
 
@@ -489,7 +496,7 @@ def create_interface():
489
  def update_ui_generator():
490
  last_frame = None
491
  while True:
492
- status_text = "Status: Processing..."
493
  present_md = "\n".join(attendance_system.session_log_present) or "Awaiting detections..."
494
  new_md = "\n".join(attendance_system.session_log_new) or "Awaiting new registrations..."
495
  frame = None
@@ -498,10 +505,11 @@ def create_interface():
498
  try:
499
  frame = attendance_system.frame_queue.get_nowait()
500
  last_frame = frame
 
501
  except queue.Empty:
502
  frame = last_frame
 
503
  else:
504
- status_text = "Status: Stopped."
505
  present_md = "Processing stopped. Final Present Log:\n\n" + present_md
506
  new_md = "Processing stopped. Final New Workers Log:\n\n" + new_md
507
 
 
364
  def _processing_loop(self, source):
365
  video_capture = cv2.VideoCapture(source)
366
  if not video_capture.isOpened():
367
+ self.error_message = f"❌ Error: Could not open video source: {source}"
368
+ logger.error(self.error_message)
369
  self.is_processing.clear()
370
  return
371
 
372
  tracker = FaceTracker(self)
373
+ frame_count = 0
374
  while self.is_processing.is_set():
375
  ret, frame = video_capture.read()
376
  if not ret:
377
+ logger.info("Video ended or failed to read frame.")
378
  break
379
 
380
  self.current_frame = frame.copy()
381
  annotated_frame = tracker.update(self.current_frame)
382
+ logger.debug(f"Processed frame {frame_count}, queue size: {self.frame_queue.qsize()}")
383
 
384
  if not self.frame_queue.full():
385
  self.frame_queue.put(annotated_frame)
 
390
  pass
391
  self.frame_queue.put(annotated_frame)
392
 
393
+ frame_count += 1
394
  time.sleep(0.01)
395
 
396
  video_capture.release()
 
483
 
484
  def start_wrapper(tab_index, cam_src, vid_path):
485
  source = int(cam_src) if tab_index == 0 else vid_path
486
+ if tab_index == 1 and vid_path is None:
487
+ return "❌ Please upload a video file."
488
+ return attendance_system.start_processing(source) if source is not None else "Please provide an input source."
489
+
490
  start_btn.click(fn=start_wrapper, inputs=[selected_tab_index, camera_source, video_file], outputs=[status_box])
491
  stop_btn.click(fn=attendance_system.stop_processing, inputs=None, outputs=[status_box])
492
 
 
496
  def update_ui_generator():
497
  last_frame = None
498
  while True:
499
+ status_text = "Status: Processing..." if attendance_system.is_processing.is_set() else "Status: Stopped."
500
  present_md = "\n".join(attendance_system.session_log_present) or "Awaiting detections..."
501
  new_md = "\n".join(attendance_system.session_log_new) or "Awaiting new registrations..."
502
  frame = None
 
505
  try:
506
  frame = attendance_system.frame_queue.get_nowait()
507
  last_frame = frame
508
+ logger.debug("Retrieved frame from queue for UI update")
509
  except queue.Empty:
510
  frame = last_frame
511
+ logger.debug("Using last frame due to empty queue")
512
  else:
 
513
  present_md = "Processing stopped. Final Present Log:\n\n" + present_md
514
  new_md = "Processing stopped. Final New Workers Log:\n\n" + new_md
515