Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,7 @@ import threading
|
|
| 14 |
import time
|
| 15 |
import queue
|
| 16 |
|
| 17 |
-
#
|
| 18 |
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 19 |
|
| 20 |
class AttendanceSystem:
|
|
@@ -44,12 +44,10 @@ class AttendanceSystem:
|
|
| 44 |
try:
|
| 45 |
# Load face embeddings and worker data
|
| 46 |
if os.path.exists("data/workers.pkl"):
|
| 47 |
-
with open("data/workers.pkl"
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
self.known_face_ids = data.get("ids", [])
|
| 52 |
-
self.next_worker_id = data.get("next_id", 1)
|
| 53 |
|
| 54 |
# Load attendance records
|
| 55 |
if os.path.exists("data/attendance.json"):
|
|
@@ -728,15 +726,21 @@ def create_interface():
|
|
| 728 |
|
| 729 |
# Video frame update
|
| 730 |
def update_video_frame():
|
|
|
|
| 731 |
while True:
|
| 732 |
-
|
| 733 |
-
if
|
| 734 |
-
|
| 735 |
-
frame
|
| 736 |
-
|
| 737 |
-
|
|
|
|
|
|
|
| 738 |
|
| 739 |
-
|
|
|
|
|
|
|
|
|
|
| 740 |
|
| 741 |
return demo
|
| 742 |
|
|
|
|
| 14 |
import time
|
| 15 |
import queue
|
| 16 |
|
| 17 |
+
# Suppress TensorFlow oneDNN warning
|
| 18 |
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 19 |
|
| 20 |
class AttendanceSystem:
|
|
|
|
| 44 |
try:
|
| 45 |
# Load face embeddings and worker data
|
| 46 |
if os.path.exists("data/workers.pkl"):
|
| 47 |
+
with open("data/workers.pkl",往 self.known_face_embeddings = data.get("embeddings", [])
|
| 48 |
+
self.known_face_names = data.get("names", [])
|
| 49 |
+
self.known_face_ids = data.get("ids", [])
|
| 50 |
+
self.next_worker_id = data.get("next_id", 1)
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Load attendance records
|
| 53 |
if os.path.exists("data/attendance.json"):
|
|
|
|
| 726 |
|
| 727 |
# Video frame update
|
| 728 |
def update_video_frame():
|
| 729 |
+
start_time = time.time()
|
| 730 |
while True:
|
| 731 |
+
current_time = time.time()
|
| 732 |
+
if current_time - start_time >= 0.03: # Update every 0.03 seconds
|
| 733 |
+
frame = attendance_system.get_current_frame()
|
| 734 |
+
if frame is not None:
|
| 735 |
+
# Convert BGR to RGB
|
| 736 |
+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 737 |
+
return frame
|
| 738 |
+
start_time = current_time
|
| 739 |
|
| 740 |
+
# Start the video frame update as a background thread
|
| 741 |
+
video_thread = threading.Thread(target=lambda: demo.queue()(update_video_frame)())
|
| 742 |
+
video_thread.daemon = True
|
| 743 |
+
video_thread.start()
|
| 744 |
|
| 745 |
return demo
|
| 746 |
|