Spaces:
Runtime error
Runtime error
import gradio as gr | |
from deepface import DeepFace | |
import cv2 | |
import numpy as np | |
def analyze_frame(frame): | |
# Convert frame from BGR to RGB format for DeepFace | |
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
result = DeepFace.analyze(frame_rgb, actions=['gender'], enforce_detection=False) | |
if result: | |
gender = result[0]['gender'] | |
else: | |
gender = "No face detected" | |
return frame, gender | |
def process_webcam_image(image): | |
# Convert the image to a format suitable for DeepFace | |
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) | |
frame, gender = analyze_frame(image) | |
return frame, gender | |
demo = gr.Interface( | |
fn=process_webcam_image, | |
inputs=gr.Image(source="webcam", streaming=True), | |
outputs=[gr.Image(), gr.Textbox()], | |
live=True | |
) | |
if __name__ == "__main__": | |
demo.launch() |