Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,33 +3,33 @@ from mtcnn.mtcnn import MTCNN
|
|
3 |
import cv2
|
4 |
import numpy as np
|
5 |
|
6 |
-
# Function to
|
7 |
def detect_faces(image):
|
8 |
-
#
|
9 |
-
|
10 |
|
11 |
-
#
|
12 |
detector = MTCNN()
|
|
|
13 |
|
14 |
-
#
|
15 |
-
faces = detector.detect_faces(img)
|
16 |
-
|
17 |
-
# Draw bounding boxes around the faces
|
18 |
for face in faces:
|
19 |
x, y, width, height = face['box']
|
20 |
-
cv2.rectangle(
|
21 |
-
|
22 |
-
# Convert the image to RGB format for Gradio
|
23 |
-
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
24 |
|
25 |
-
return
|
26 |
|
27 |
-
#
|
28 |
iface = gr.Interface(
|
29 |
fn=detect_faces,
|
30 |
-
inputs=gr.Image(),
|
31 |
-
outputs="
|
|
|
|
|
|
|
|
|
|
|
32 |
)
|
33 |
|
34 |
-
# Launch the Gradio
|
35 |
iface.launch()
|
|
|
3 |
import cv2
|
4 |
import numpy as np
|
5 |
|
6 |
+
# Function to detect faces using MTCNN
|
7 |
def detect_faces(image):
|
8 |
+
# Convert image to RGB format
|
9 |
+
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
10 |
|
11 |
+
# Detect faces using MTCNN
|
12 |
detector = MTCNN()
|
13 |
+
faces = detector.detect_faces(image_rgb)
|
14 |
|
15 |
+
# Draw bounding boxes around detected faces
|
|
|
|
|
|
|
16 |
for face in faces:
|
17 |
x, y, width, height = face['box']
|
18 |
+
cv2.rectangle(image, (x, y), (x + width, y + height), (255, 0, 0), 2)
|
|
|
|
|
|
|
19 |
|
20 |
+
return image
|
21 |
|
22 |
+
# Gradio Interface
|
23 |
iface = gr.Interface(
|
24 |
fn=detect_faces,
|
25 |
+
inputs=gr.Image(type="numpy", label="Input Image"),
|
26 |
+
outputs=gr.Image(type="numpy", label="Output Image"),
|
27 |
+
live=True,
|
28 |
+
capture_session=True,
|
29 |
+
interpretation="default",
|
30 |
+
title="MTCNN Face Detection",
|
31 |
+
description="Detect faces in an image using MTCNN.",
|
32 |
)
|
33 |
|
34 |
+
# Launch the Gradio Interface
|
35 |
iface.launch()
|