Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load emotion model
|
| 5 |
emotion_pipe = pipeline("image-classification", model="dima806/facial_emotions_image_detection")
|
| 6 |
|
| 7 |
def detect_emotion(image):
|
| 8 |
results = emotion_pipe(image)
|
| 9 |
if results:
|
| 10 |
top = results[0]
|
| 11 |
-
return
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
| 14 |
gr.Interface(
|
| 15 |
fn=detect_emotion,
|
| 16 |
inputs=gr.Image(type="pil"),
|
| 17 |
-
outputs="text"
|
| 18 |
title="High Accuracy Emotion Detector",
|
| 19 |
description="Powered by dima806/facial_emotions_image_detection (~91% accurate)"
|
| 20 |
).launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load emotion detection model
|
| 5 |
emotion_pipe = pipeline("image-classification", model="dima806/facial_emotions_image_detection")
|
| 6 |
|
| 7 |
def detect_emotion(image):
|
| 8 |
results = emotion_pipe(image)
|
| 9 |
if results:
|
| 10 |
top = results[0]
|
| 11 |
+
return {
|
| 12 |
+
"top_prediction": f"{top['label']} ({100*top['score']:.1f}%)",
|
| 13 |
+
"all_predictions": results
|
| 14 |
+
}
|
| 15 |
+
return {"top_prediction": "No face detected", "all_predictions": []}
|
| 16 |
|
| 17 |
+
# Create Gradio interface
|
| 18 |
gr.Interface(
|
| 19 |
fn=detect_emotion,
|
| 20 |
inputs=gr.Image(type="pil"),
|
| 21 |
+
outputs="json", # Changed from "text" to "json"
|
| 22 |
title="High Accuracy Emotion Detector",
|
| 23 |
description="Powered by dima806/facial_emotions_image_detection (~91% accurate)"
|
| 24 |
).launch()
|