File size: 1,327 Bytes
2cc56c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import face_recognition
import cv2
import gradio as gr
from PIL import Image
import numpy as np

def run(image):
    image.thumbnail((1280, 1280))
    image = np.array(image)
    face_locations = face_recognition.face_locations(image, model="cnn")

    for top, right, bottom, left in face_locations:
        face_image = image[top:bottom, left:right]
        face_image = cv2.GaussianBlur(face_image, (99, 99), 30)
        image[top:bottom, left:right] = face_image
    
    return Image.fromarray(image)

content_image_input = gr.inputs.Image(label="Content Image", type="pil")

description="Privacy first! Upload an image of a groupf of people and blur their faces automatically."
article="""
Demo built with the face_recognition package and opencv, based on 
<a href='https://github.com/ageitgey/face_recognition/blob/master/examples/blur_faces_on_webcam.py' target='_blank'>this</a> example.
"""
examples = [["family.jpeg"], ["crowd.jpeg"], ["crowd1.jpeg"]]

app_interface = gr.Interface(fn=run,
                             inputs=[content_image_input],
                             outputs="image",
                             title="Blurry Faces",
                             description=description,
                             examples=examples,
                             article=article)
app_interface.launch()