Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,35 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
demo = gr.Interface(
|
7 |
-
fn=
|
8 |
-
inputs=gr.
|
9 |
-
outputs="
|
10 |
)
|
11 |
|
12 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import mediapipe as mp
|
3 |
+
import cv2
|
4 |
+
import numpy as np
|
5 |
|
6 |
+
# Initialize MediaPipe Face Detection
|
7 |
+
mp_face_detection = mp.solutions.face_detection
|
8 |
+
mp_drawing = mp.solutions.drawing_utils
|
9 |
+
face_detection = mp_face_detection.FaceDetection(min_detection_confidence=0.5)
|
10 |
|
11 |
+
def detect_faces(image):
|
12 |
+
# Convert the image from BGR (Gradio's default) to RGB
|
13 |
+
image = cv2.cvtColor(np.array(image), cv2.COLOR_BGR2RGB)
|
14 |
+
|
15 |
+
# Process the image and detect faces
|
16 |
+
results = face_detection.process(image)
|
17 |
+
|
18 |
+
# Draw face detections on the image
|
19 |
+
if results.detections:
|
20 |
+
for detection in results.detections:
|
21 |
+
mp_drawing.draw_detection(image, detection)
|
22 |
+
|
23 |
+
# Convert the image back to BGR
|
24 |
+
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
25 |
+
|
26 |
+
return image
|
27 |
+
|
28 |
+
# Define the Gradio interface
|
29 |
demo = gr.Interface(
|
30 |
+
fn=detect_faces,
|
31 |
+
inputs=gr.inputs.Image(shape=(480, 640), source="webcam"),
|
32 |
+
outputs=gr.outputs.Image(type="numpy", label="Processed Image")
|
33 |
)
|
34 |
|
35 |
demo.launch()
|