Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -398,6 +398,10 @@ class AttendanceSystem:
|
|
| 398 |
buffer_key = f"{x}_{y}_{w}_{h}"
|
| 399 |
current_time = time.time()
|
| 400 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
if self.known_face_embeddings:
|
| 402 |
# Find best match using euclidean distance
|
| 403 |
match_index, match_distance = self._find_best_match(embedding_array)
|
|
@@ -410,6 +414,15 @@ class AttendanceSystem:
|
|
| 410 |
worker_name = self.known_face_names[match_index]
|
| 411 |
color = (0, 255, 0) # Green for recognized
|
| 412 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
# Use buffer for consistent detections
|
| 414 |
if buffer_key not in self.face_recognition_buffer:
|
| 415 |
self.face_recognition_buffer[buffer_key] = {'count': 1, 'last_time': current_time, 'worker_id': worker_id}
|
|
@@ -434,13 +447,10 @@ class AttendanceSystem:
|
|
| 434 |
color = (0, 165, 255) # Orange for potential new worker
|
| 435 |
print(f" -> Attempting auto-registration...")
|
| 436 |
new_worker = self._register_worker_auto(face_image, embedding)
|
| 437 |
-
if new_worker:
|
| 438 |
worker_id, worker_name = new_worker[0], new_worker[1]
|
| 439 |
color = (0, 255, 0) # Change to green after successful registration
|
| 440 |
if self.mark_attendance(worker_id, worker_name):
|
| 441 |
self.last_recognition_time[worker_id] = time.time()
|
| 442 |
-
else:
|
| 443 |
-
print(" -> Auto-registration skipped (duplicate or session limit)")
|
| 444 |
else:
|
| 445 |
print(" -> Distance too close to existing faces, skipping auto-registration.")
|
| 446 |
else:
|
|
@@ -448,13 +458,10 @@ class AttendanceSystem:
|
|
| 448 |
color = (0, 165, 255) # Orange for new worker
|
| 449 |
print(" -> No known faces in database. Auto-registering...")
|
| 450 |
new_worker = self._register_worker_auto(face_image, embedding)
|
| 451 |
-
if new_worker:
|
| 452 |
worker_id, worker_name = new_worker[0], new_worker[1]
|
| 453 |
color = (0, 255, 0) # Change to green after successful registration
|
| 454 |
if self.mark_attendance(worker_id, worker_name):
|
| 455 |
self.last_recognition_time[worker_id] = time.time()
|
| 456 |
-
else:
|
| 457 |
-
print(" -> Auto-registration failed")
|
| 458 |
|
| 459 |
# Clean old buffer entries
|
| 460 |
current_time = time.time()
|
|
|
|
| 398 |
buffer_key = f"{x}_{y}_{w}_{h}"
|
| 399 |
current_time = time.time()
|
| 400 |
|
| 401 |
+
# Create a buffer key for this face location
|
| 402 |
+
buffer_key = f"{x}_{y}_{w}_{h}"
|
| 403 |
+
current_time = time.time()
|
| 404 |
+
|
| 405 |
if self.known_face_embeddings:
|
| 406 |
# Find best match using euclidean distance
|
| 407 |
match_index, match_distance = self._find_best_match(embedding_array)
|
|
|
|
| 414 |
worker_name = self.known_face_names[match_index]
|
| 415 |
color = (0, 255, 0) # Green for recognized
|
| 416 |
|
| 417 |
+
# Use buffer for consistent detections
|
| 418 |
+
if buffer_key not in self.face_recognition_buffer:
|
| 419 |
+
self.face_recognition_buffer[buffer_key] = {'count': 1, 'last_time': current_time, 'worker_id': worker_id}
|
| 420 |
+
else:
|
| 421 |
+
self.face_recognition_buffer[buffer_key]['count'] += 1
|
| 422 |
+
self.face_recognition_buffer[buffer_key]['last_time'] = current_time
|
| 423 |
+
|
| 424 |
+
color = (0, 255, 0) # Green for recognized
|
| 425 |
+
|
| 426 |
# Use buffer for consistent detections
|
| 427 |
if buffer_key not in self.face_recognition_buffer:
|
| 428 |
self.face_recognition_buffer[buffer_key] = {'count': 1, 'last_time': current_time, 'worker_id': worker_id}
|
|
|
|
| 447 |
color = (0, 165, 255) # Orange for potential new worker
|
| 448 |
print(f" -> Attempting auto-registration...")
|
| 449 |
new_worker = self._register_worker_auto(face_image, embedding)
|
|
|
|
| 450 |
worker_id, worker_name = new_worker[0], new_worker[1]
|
| 451 |
color = (0, 255, 0) # Change to green after successful registration
|
| 452 |
if self.mark_attendance(worker_id, worker_name):
|
| 453 |
self.last_recognition_time[worker_id] = time.time()
|
|
|
|
|
|
|
| 454 |
else:
|
| 455 |
print(" -> Distance too close to existing faces, skipping auto-registration.")
|
| 456 |
else:
|
|
|
|
| 458 |
color = (0, 165, 255) # Orange for new worker
|
| 459 |
print(" -> No known faces in database. Auto-registering...")
|
| 460 |
new_worker = self._register_worker_auto(face_image, embedding)
|
|
|
|
| 461 |
worker_id, worker_name = new_worker[0], new_worker[1]
|
| 462 |
color = (0, 255, 0) # Change to green after successful registration
|
| 463 |
if self.mark_attendance(worker_id, worker_name):
|
| 464 |
self.last_recognition_time[worker_id] = time.time()
|
|
|
|
|
|
|
| 465 |
|
| 466 |
# Clean old buffer entries
|
| 467 |
current_time = time.time()
|