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()