Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -82,47 +82,49 @@ with about_tab:
|
|
82 |
""")
|
83 |
|
84 |
with app_tab:
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
st.warning("No face detected in the captured image.")
|
95 |
-
else:
|
96 |
-
# st.write("Similarity Scores:", prediction_scores)
|
97 |
-
for match in matches:
|
98 |
-
x1, y1, x2, y2 = match['bbox']
|
99 |
-
name = match['name']
|
100 |
-
color = (0, 255, 0) if name != "Unknown" else (0, 0, 255)
|
101 |
-
cv2.rectangle(image_bgr, (x1, y1), (x2, y2), color, 2)
|
102 |
-
cv2.putText(image_bgr, name, (x1, y2 + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2)
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
#
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
""")
|
83 |
|
84 |
with app_tab:
|
85 |
+
col1, col2 = st.columns(2)
|
86 |
+
with col1:
|
87 |
+
enable = st.checkbox("Enable camera")
|
88 |
+
picture = st.camera_input("Take a picture", disabled=not enable)
|
89 |
+
with col2:
|
90 |
+
if picture is not None:
|
91 |
+
with st.spinner("Analyzing face..."):
|
92 |
+
image_pil = Image.open(picture)
|
93 |
+
matches, image_bgr = prod_function(app, image_paths, image_pil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
+
if not matches:
|
96 |
+
st.warning("No face detected in the captured image.")
|
97 |
+
else:
|
98 |
+
# st.write("Similarity Scores:", prediction_scores)
|
99 |
+
for match in matches:
|
100 |
+
x1, y1, x2, y2 = match['bbox']
|
101 |
+
name = match['name']
|
102 |
+
color = (0, 255, 0) if name != "Unknown" else (0, 0, 255)
|
103 |
+
cv2.rectangle(image_bgr, (x1, y1), (x2, y2), color, 2)
|
104 |
+
cv2.putText(image_bgr, name, (x1, y2 + 20), cv2.FONT_HERSHEY_SIMPLEX, 0.8, color, 2)
|
105 |
+
|
106 |
+
if name != "Unknown":
|
107 |
+
# recognized = False
|
108 |
+
# for score, idx in matches:
|
109 |
+
# if matched_score >= 0.6:
|
110 |
+
# matched_name = os.path.basename(image_paths[match_idx]).split('.')[0]
|
111 |
+
# st.success(f"β
Welcome: {matched_name}")
|
112 |
+
# recognizes=True
|
113 |
+
|
114 |
+
# Send attendance via POST
|
115 |
+
url = "https://nielit-attendance.glitch.me/adds"
|
116 |
+
data = {'rno': 15, 'sname': matched_name, 'sclass': 7}
|
117 |
+
try:
|
118 |
+
response = requests.post(url, data=data)
|
119 |
+
if response.status_code == 200:
|
120 |
+
st.success(f"Attendance marked successfully for {matched_name}.")
|
121 |
+
else:
|
122 |
+
st.warning(f"Failed to update attendance for {matched_name}.")
|
123 |
+
except Exception as e:
|
124 |
+
st.error(f"Request failed: {e}")
|
125 |
+
else:
|
126 |
+
st.warning("β Face match not found or too low confidence.")
|
127 |
+
|
128 |
+
# Convert back to RGB for display
|
129 |
+
image_rgb = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2RGB)
|
130 |
+
st.image(image_rgb, caption="Detected Faces", use_container_width=True)
|