File size: 655 Bytes
ec3bc2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
from transformers import pipeline

# Load a pre-trained emotion detection model
emotion = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")

def detect_emotion(text):
    if not text.strip():
        return "Please enter some text."
    result = emotion(text)[0]
    return f"Emotion: {result['label']} (Confidence: {round(result['score'], 2)})"

app = gr.Interface(
    fn=detect_emotion,
    inputs=gr.Textbox(lines=2, placeholder="Type your feeling..."),
    outputs="text",
    title="💬 Emotion Detector",
    description="Type a sentence and find out the emotion behind it!"
)

app.launch()