Spaces:
Sleeping
Sleeping
fix
Browse files- app.py +25 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the face emotion recognition model
|
5 |
+
emotion_classifier = pipeline("image-classification", model="dima806/facial_emotions_image_detection")
|
6 |
+
|
7 |
+
def detect_emotion(image):
|
8 |
+
# Perform emotion detection
|
9 |
+
results = emotion_classifier(image)
|
10 |
+
|
11 |
+
# Format and return the results
|
12 |
+
return {result["label"]: f"{result['score']:.4f}" for result in results}
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
demo = gr.Interface(
|
16 |
+
fn=detect_emotion,
|
17 |
+
inputs=gr.Image(type="pil"),
|
18 |
+
outputs=gr.Label(num_top_classes=7),
|
19 |
+
title="Facial Expression Recognition",
|
20 |
+
description="Upload an image with a face to detect the emotion/expression. The model can recognize: anger, disgust, fear, happiness, neutral, sadness, and surprise."
|
21 |
+
)
|
22 |
+
|
23 |
+
# Launch the app
|
24 |
+
if __name__ == "__main__":
|
25 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio>=3.50.2
|
2 |
+
transformers>=4.30.0
|
3 |
+
torch>=2.0.0
|
4 |
+
Pillow>=9.5.0
|