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()