import gradio as gr import cv2 import numpy as np face_cascade = cv2.CascadeClassifier( cv2.data.haarcascades + 'haarcascade_frontalface_default.xml' ) def mask_image(image): """Apply mask to a single image (not streaming)""" if image is None: return None # Convert to BGR for OpenCV frame = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in faces: # Zorro mask cv2.rectangle(frame, (x, y + int(h*0.35)), (x + w, y + int(h*0.65)), (0, 0, 0), -1) # Eye holes cv2.circle(frame, (x + int(w*0.35), y + int(h*0.5)), int(w*0.1), (255, 255, 255), -1) cv2.circle(frame, (x + int(w*0.65), y + int(h*0.5)), int(w*0.1), (255, 255, 255), -1) return cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # Simple interface - user clicks "Capture" then "Submit" demo = gr.Interface( fn=mask_image, inputs=gr.Image(sources=["webcam"], type="numpy"), outputs=gr.Image(), title="Zorro Mask", description="1. Allow camera access\n2. Click 'Capture'\n3. Click 'Submit'\n4. See the mask!", examples=None ) demo.launch()