Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -169,12 +169,20 @@ def recognize_faces(video_frame):
|
|
| 169 |
|
| 170 |
# --- GRADIO INTERFACE (ENHANCED WITH BLOCKS) ---
|
| 171 |
|
| 172 |
-
def recognize_and_return(frame: np.ndarray):
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
name_str = ", ".join(names) if names else "No known faces"
|
| 175 |
return annotated_frame, name_str
|
| 176 |
|
| 177 |
with gr.Blocks(css=".gr-button {background-color: #2c3e50; color: white;}") as demo:
|
|
|
|
| 178 |
gr.Markdown("# 🧠 Advanced Real-Time Facial Recognition")
|
| 179 |
gr.Markdown(
|
| 180 |
"""
|
|
@@ -193,14 +201,16 @@ with gr.Blocks(css=".gr-button {background-color: #2c3e50; color: white;}") as d
|
|
| 193 |
video_output = gr.Image(label="🧾 Annotated Output Frame")
|
| 194 |
names_output = gr.Textbox(label="👤 Recognition Log", interactive=False)
|
| 195 |
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
|
| 198 |
-
|
|
|
|
|
|
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
clear_button.click(fn=clear_outputs, outputs=[video_output, names_output])
|
| 204 |
|
| 205 |
gr.Markdown("---")
|
| 206 |
gr.Markdown(
|
|
|
|
| 169 |
|
| 170 |
# --- GRADIO INTERFACE (ENHANCED WITH BLOCKS) ---
|
| 171 |
|
| 172 |
+
def recognize_and_return(frame: np.ndarray, recognition_enabled: bool):
|
| 173 |
+
if not recognition_enabled:
|
| 174 |
+
return frame, "Recognition Paused"
|
| 175 |
+
|
| 176 |
+
result = recognize_faces(frame)
|
| 177 |
+
if result is None:
|
| 178 |
+
return frame, "No faces detected"
|
| 179 |
+
|
| 180 |
+
annotated_frame, names = result
|
| 181 |
name_str = ", ".join(names) if names else "No known faces"
|
| 182 |
return annotated_frame, name_str
|
| 183 |
|
| 184 |
with gr.Blocks(css=".gr-button {background-color: #2c3e50; color: white;}") as demo:
|
| 185 |
+
recognition_enabled = gr.State(True) # Shared state
|
| 186 |
gr.Markdown("# 🧠 Advanced Real-Time Facial Recognition")
|
| 187 |
gr.Markdown(
|
| 188 |
"""
|
|
|
|
| 201 |
video_output = gr.Image(label="🧾 Annotated Output Frame")
|
| 202 |
names_output = gr.Textbox(label="👤 Recognition Log", interactive=False)
|
| 203 |
|
| 204 |
+
with gr.Row():
|
| 205 |
+
toggle = gr.Checkbox(value=True, label="Enable Recognition")
|
| 206 |
+
clear_btn = gr.Button("🧹 Clear Output")
|
| 207 |
|
| 208 |
+
video_input.stream(fn=recognize_and_return,
|
| 209 |
+
inputs=[video_input, recognition_enabled],
|
| 210 |
+
outputs=[video_output, names_output])
|
| 211 |
|
| 212 |
+
toggle.change(lambda v: v, inputs=toggle, outputs=recognition_enabled)
|
| 213 |
+
clear_btn.click(lambda: (None, ""), outputs=[video_output, names_output])
|
|
|
|
|
|
|
| 214 |
|
| 215 |
gr.Markdown("---")
|
| 216 |
gr.Markdown(
|