import gradio as gr import torch from transformers import pipeline from PIL import Image import numpy as np # Load emotion model from Hugging Face emotion_pipeline = pipeline( "image-classification", model="dima806/facial_emotions_image_detection" ) def predict_mood(image): if image is None: return "No image uploaded" img = Image.fromarray(image.astype('uint8'), 'RGB') results = emotion_pipeline(img) top_result = max(results, key=lambda x: x["score"]) label = top_result["label"] confidence = round(top_result["score"] * 100, 2) return f"Detected Emotion: {label} ({confidence}%)" interface = gr.Interface( fn=predict_mood, inputs=gr.Image(type="numpy"), outputs="text", title="AI Mood Identifier", description="Upload a face image to detect emotion using Deep Learning." ) interface.launch()