import gradio as gr import cv2 import numpy as np from PIL import Image from retinaface import RetinaFace def detect_and_blur_faces(image): resp = RetinaFace.detect_faces(image) output_image = image.copy() for i in range(len(resp)): [x, y, w, h] = resp[f'face_{i+1}']['facial_area'] # Blur the detected face. face = output_image[y:h, x:w] blurred_face = cv2.GaussianBlur(face, (99, 99), 30) output_image[y:h, x:w] = blurred_face return output_image # Set up the Gradio interface. image_input = gr.inputs.Image(shape=(None, None)) image_output = gr.outputs.Image(type='numpy') gr.Interface(fn=detect_and_blur_faces, inputs=image_input, outputs=image_output, title="Face Detection and Blurring").launch()