Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load the face emotion recognition model | |
emotion_classifier = pipeline("image-classification", model="dima806/facial_emotions_image_detection") | |
def detect_emotion(image): | |
# Perform emotion detection | |
results = emotion_classifier(image) | |
# Format and return the results | |
return {result["label"]: f"{result['score']:.4f}" for result in results} | |
# Create the Gradio interface | |
demo = gr.Interface( | |
fn=detect_emotion, | |
inputs=gr.Image(type="pil"), | |
outputs=gr.Label(num_top_classes=7), | |
title="Facial Expression Recognition", | |
description="Upload an image with a face to detect the emotion/expression. The model can recognize: anger, disgust, fear, happiness, neutral, sadness, and surprise." | |
) | |
# Launch the app | |
if __name__ == "__main__": | |
demo.launch() | |