Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
# Initialize the emotion detection pipeline | |
emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base") | |
# Set up the title and description | |
st.title("Emotion Detector in Text") | |
st.write("Type a text below, and the model will predict the emotion behind it.") | |
# Input field for text | |
user_input = st.text_area("Enter your text here:") | |
if st.button("Detect Emotion"): | |
if user_input.strip(): | |
# Get emotion predictions | |
emotion = emotion_model(user_input)[0] | |
label = emotion['label'] | |
score = emotion['score'] | |
# Display emotion and confidence score | |
st.write(f"**Detected Emotion:** {label}") | |
st.write(f"**Confidence Score:** {score:.2f}") | |
else: | |
st.error("Please enter some text.") | |
# Footer | |
st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.") | |