Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load a pre-trained emotion detection model
|
| 5 |
+
emotion = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
|
| 6 |
+
|
| 7 |
+
def detect_emotion(text):
|
| 8 |
+
if not text.strip():
|
| 9 |
+
return "Please enter some text."
|
| 10 |
+
result = emotion(text)[0]
|
| 11 |
+
return f"Emotion: {result['label']} (Confidence: {round(result['score'], 2)})"
|
| 12 |
+
|
| 13 |
+
app = gr.Interface(
|
| 14 |
+
fn=detect_emotion,
|
| 15 |
+
inputs=gr.Textbox(lines=2, placeholder="Type your feeling..."),
|
| 16 |
+
outputs="text",
|
| 17 |
+
title="💬 Emotion Detector",
|
| 18 |
+
description="Type a sentence and find out the emotion behind it!"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
app.launch()
|