Spaces:
Build error
Build error
Commit ·
49591f1
1
Parent(s): 4ce9c81
Added webcam and image tabs
Browse files- app.py +47 -15
- examples/face1.jpg +0 -0
- examples/face2.jpg +0 -0
- examples/face3.jpg +0 -0
app.py
CHANGED
|
@@ -1,10 +1,15 @@
|
|
| 1 |
from model_utils import detect_face
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
|
| 5 |
# Function to run the app
|
| 6 |
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def run_model(image: np.ndarray):
|
| 9 |
return gr.Image.update(value=detect_face(image))
|
| 10 |
|
|
@@ -36,25 +41,52 @@ def interface() -> None:
|
|
| 36 |
"""
|
| 37 |
)
|
| 38 |
with gr.Group():
|
| 39 |
-
with gr.
|
| 40 |
-
with gr.
|
| 41 |
-
with gr.Row():
|
| 42 |
-
webcam_image_in = gr.Webcam(label="Webcam input")
|
| 43 |
-
with gr.Row():
|
| 44 |
-
gr.Text(
|
| 45 |
-
label="⚠️ Reminder ", value="Do not forget to click the camera button to freeze and get the webcam image 📷!", interactive=False)
|
| 46 |
-
with gr.Column():
|
| 47 |
with gr.Row():
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
app.launch()
|
| 57 |
|
| 58 |
|
| 59 |
if __name__ == '__main__':
|
| 60 |
-
interface() # Run the interface
|
|
|
|
| 1 |
from model_utils import detect_face
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
+
import os
|
| 5 |
|
| 6 |
# Function to run the app
|
| 7 |
|
| 8 |
|
| 9 |
+
def set_image(image):
|
| 10 |
+
return gr.Image.update(value=image[0][0])
|
| 11 |
+
|
| 12 |
+
|
| 13 |
def run_model(image: np.ndarray):
|
| 14 |
return gr.Image.update(value=detect_face(image))
|
| 15 |
|
|
|
|
| 41 |
"""
|
| 42 |
)
|
| 43 |
with gr.Group():
|
| 44 |
+
with gr.Tabs():
|
| 45 |
+
with gr.TabItem("Image input 🖼️"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
with gr.Row():
|
| 47 |
+
with gr.Column():
|
| 48 |
+
with gr.Row():
|
| 49 |
+
image_in = gr.Image(
|
| 50 |
+
label="Image input", interative=True)
|
| 51 |
+
with gr.Row():
|
| 52 |
+
paths = [["examples/" + example]
|
| 53 |
+
for example in os.listdir("examples")]
|
| 54 |
+
example_images = gr.Dataset(components=([image_in]), label="Example images", samples=[[path]
|
| 55 |
+
for path in paths])
|
| 56 |
+
with gr.Row():
|
| 57 |
+
detect_image_button = gr.Button(
|
| 58 |
+
value="Detect face 👤")
|
| 59 |
+
with gr.Column():
|
| 60 |
+
with gr.Row():
|
| 61 |
+
face_detected_image_out = gr.Image(
|
| 62 |
+
label="Face detected", interactive=False)
|
| 63 |
+
|
| 64 |
+
example_images.click(fn=set_image, inputs=[
|
| 65 |
+
example_images], outputs=[image_in])
|
| 66 |
+
detect_image_button.click(fn=run_model, inputs=[
|
| 67 |
+
image_in], outputs=face_detected_image_out)
|
| 68 |
|
| 69 |
+
with gr.TabItem("Webcam input 📷"):
|
| 70 |
+
with gr.Row():
|
| 71 |
+
with gr.Column():
|
| 72 |
+
with gr.Row():
|
| 73 |
+
webcam_image_in = gr.Webcam(
|
| 74 |
+
label="Webcam input")
|
| 75 |
+
with gr.Row():
|
| 76 |
+
gr.Text(
|
| 77 |
+
label="⚠️ Reminder ", value="Do not forget to click the camera button to freeze and get the webcam image 📷!", interactive=False)
|
| 78 |
+
with gr.Row():
|
| 79 |
+
detect_button = gr.Button(
|
| 80 |
+
value="Detect face 👤")
|
| 81 |
+
with gr.Column():
|
| 82 |
+
with gr.Row():
|
| 83 |
+
face_detected_webcam_out = gr.Image(
|
| 84 |
+
label="Face detected", interactive=False)
|
| 85 |
+
detect_button.click(fn=run_model, inputs=[
|
| 86 |
+
webcam_image_in], outputs=face_detected_webcam_out)
|
| 87 |
|
| 88 |
app.launch()
|
| 89 |
|
| 90 |
|
| 91 |
if __name__ == '__main__':
|
| 92 |
+
interface() # Run the interface
|
examples/face1.jpg
ADDED
|
examples/face2.jpg
ADDED
|
examples/face3.jpg
ADDED
|