Spaces:
Running
Running
mmkuznecov
commited on
Commit
•
33f5378
1
Parent(s):
e1ff707
Add application file
Browse files- app.py +31 -0
- requirements.txt +5 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
from PIL import Image
|
5 |
+
from retinaface import RetinaFace
|
6 |
+
|
7 |
+
|
8 |
+
def detect_and_blur_faces(image):
|
9 |
+
|
10 |
+
resp = RetinaFace.detect_faces(image)
|
11 |
+
|
12 |
+
output_image = image.copy()
|
13 |
+
|
14 |
+
|
15 |
+
for i in range(len(resp)):
|
16 |
+
|
17 |
+
[x, y, w, h] = resp[f'face_{i+1}']['facial_area']
|
18 |
+
|
19 |
+
# Blur the detected face.
|
20 |
+
face = output_image[y:h, x:w]
|
21 |
+
blurred_face = cv2.GaussianBlur(face, (99, 99), 30)
|
22 |
+
output_image[y:h, x:w] = blurred_face
|
23 |
+
|
24 |
+
return output_image
|
25 |
+
|
26 |
+
|
27 |
+
# Set up the Gradio interface.
|
28 |
+
image_input = gr.inputs.Image(shape=(None, None))
|
29 |
+
image_output = gr.outputs.Image(type='numpy')
|
30 |
+
|
31 |
+
gr.Interface(fn=detect_and_blur_faces, inputs=image_input, outputs=image_output, title="Face Detection and Blurring").launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
opencv-python-headless
|
3 |
+
numpy
|
4 |
+
pillow
|
5 |
+
retinaface
|