File size: 994 Bytes
692f0b0
9e95224
692f0b0
 
9e95224
692f0b0
55338f0
9e95224
692f0b0
55338f0
 
692f0b0
 
af37cdf
55338f0
692f0b0
55338f0
692f0b0
 
 
 
 
af37cdf
692f0b0
 
68a8260
692f0b0
 
8314d9c
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
import gradio as gr
from deepface import DeepFace
from PIL import Image
import numpy as np

def analyze_face(image):
    analysis_result = DeepFace.analyze(img_path=np.array(image), actions=['age', 'gender', 'race', 'emotion'])[0]

    age = analysis_result['age']
    gender = max(analysis_result['gender'], key=analysis_result['gender'].get)
    gender_prob = f"{analysis_result['gender'][gender]:.2f}%"
    race = analysis_result['dominant_race']
    emotion = analysis_result['dominant_emotion']

    emotions_detail = ', '.join([f"{k}: {v:.2f}%" for k, v in analysis_result['emotion'].items()])

    return age, f"{gender} ({gender_prob})", race, emotion, emotions_detail

iface = gr.Interface(
    fn=analyze_face,
    inputs=gr.Image(type="pil"),
    outputs=[gr.Number(label="Age"), 
             gr.Text(label="Gender Probability"), 
             gr.Text(label="Race"), 
             gr.Text(label="Dominant Emotion"),
             gr.Text(label="Emotion Breakdown")]
)

iface.launch()