Spaces:
Runtime error
Runtime error
File size: 1,052 Bytes
692f0b0 9e95224 692f0b0 9e95224 692f0b0 9e95224 692f0b0 |
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 36 37 |
import gradio as gr
from deepface import DeepFace
from PIL import Image
import numpy as np
# Function to analyze the uploaded image
def analyze_face(image):
# Convert the image to a numpy array
image_array = np.array(image)
# Perform DeepFace analysis
analysis_result = DeepFace.analyze(img_path=image_array, actions=['age', 'gender', 'race', 'emotion'])
# Extract results
age = analysis_result['age']
gender = analysis_result['gender']
race = analysis_result['dominant_race']
emotion = analysis_result['dominant_emotion']
emotions_detail = analysis_result['emotion']
# Return the results
return age, gender, race, emotion, emotions_detail
# Define the Gradio interface
iface = gr.Interface(
fn=analyze_face,
inputs=gr.Image(type="pil"),
outputs=[gr.Number(label="Age"),
gr.Text(label="Gender"),
gr.Text(label="Race"),
gr.Text(label="Dominant Emotion"),
gr.JSON(label="Emotion Breakdown")]
)
# Launch the Gradio app
iface.launch()
|