Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,10 +17,6 @@ import streamlit as st
|
|
17 |
import streamlit_webrtc as webrtc
|
18 |
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
app = Flask(__name__)
|
25 |
|
26 |
|
@@ -77,28 +73,58 @@ def attend():
|
|
77 |
|
78 |
csv_writer = csv.writer(csv_file)
|
79 |
|
80 |
-
|
81 |
-
def
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
|
104 |
|
|
|
17 |
import streamlit_webrtc as webrtc
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
20 |
app = Flask(__name__)
|
21 |
|
22 |
|
|
|
73 |
|
74 |
csv_writer = csv.writer(csv_file)
|
75 |
|
76 |
+
# Function to run face recognition
|
77 |
+
def run_face_recognition():
|
78 |
+
video_capture = cv2.VideoCapture(0)
|
79 |
+
s = True
|
80 |
+
|
81 |
+
existing_names = set(row[0] for row in csv.reader(csv_file)) # Collect existing names from the CSV file
|
82 |
+
|
83 |
+
|
84 |
+
while s:
|
85 |
+
_, frame = video_capture.read()
|
86 |
+
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
|
87 |
+
rgb_small_frame = small_frame[:, :, ::-1]
|
88 |
+
|
89 |
+
face_locations = face_recognition.face_locations(rgb_small_frame)
|
90 |
+
face_encodings = face_recognition.face_encodings(small_frame, face_locations)
|
91 |
+
face_names = []
|
92 |
+
|
93 |
+
for face_encoding in face_encodings:
|
94 |
+
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
|
95 |
+
name = ""
|
96 |
+
face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
|
97 |
+
best_match_index = np.argmin(face_distance)
|
98 |
+
if matches[best_match_index]:
|
99 |
+
name = known_faces_names[best_match_index]
|
100 |
+
|
101 |
+
face_names.append(name)
|
102 |
+
|
103 |
+
|
104 |
+
for name in face_names:
|
105 |
+
if name in known_faces_names and name in students and name not in existing_names:
|
106 |
+
students.remove(name)
|
107 |
+
print(students)
|
108 |
+
print(f"Attendance recorded for {name}")
|
109 |
+
current_time = now.strftime("%H-%M-%S")
|
110 |
+
csv_writer.writerow([name, current_time, "Present"])
|
111 |
+
existing_names.add(name) # Add the name to the set of existing names
|
112 |
+
|
113 |
+
s = False # Set s to False to exit the loop after recording attendance
|
114 |
+
break # Break the loop once attendance has been recorded for a name
|
115 |
+
|
116 |
+
cv2.imshow("Attendance System", frame)
|
117 |
+
if cv2.waitKey(1) & 0xFF == ord('q'):
|
118 |
+
break
|
119 |
+
|
120 |
+
video_capture.release()
|
121 |
+
cv2.destroyAllWindows()
|
122 |
+
csv_file.close()
|
123 |
+
|
124 |
+
# Call the function to run face recognition
|
125 |
+
run_face_recognition()
|
126 |
+
|
127 |
+
return redirect(url_for('show_table'))
|
128 |
|
129 |
|
130 |
|