blurry-faces / app.py
Francesco Pochetti
adding files
30cf04a
raw
history blame
1.42 kB
import face_recognition
import cv2
import gradio as gr
from PIL import Image
from scipy.ndimage.filters import gaussian_filter
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 = gaussian_filter(face_image, sigma=10) #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()