Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Initialize the emotion detection pipeline
|
5 |
+
emotion_model = pipeline("text-classification", model="j-hartmann/emotion-english-distilroberta-base")
|
6 |
+
|
7 |
+
# Set up the title and description
|
8 |
+
st.title("Emotion Detector in Text")
|
9 |
+
st.write("Type a text below, and the model will predict the emotion behind it.")
|
10 |
+
|
11 |
+
# Input field for text
|
12 |
+
user_input = st.text_area("Enter your text here:")
|
13 |
+
|
14 |
+
if st.button("Detect Emotion"):
|
15 |
+
if user_input.strip():
|
16 |
+
# Get emotion predictions
|
17 |
+
emotion = emotion_model(user_input)[0]
|
18 |
+
label = emotion['label']
|
19 |
+
score = emotion['score']
|
20 |
+
|
21 |
+
# Display emotion and confidence score
|
22 |
+
st.write(f"**Detected Emotion:** {label}")
|
23 |
+
st.write(f"**Confidence Score:** {score:.2f}")
|
24 |
+
else:
|
25 |
+
st.error("Please enter some text.")
|
26 |
+
|
27 |
+
# Footer
|
28 |
+
st.markdown("Developed by [Your Name]. Deployed on Hugging Face Spaces.")
|