|
|
|
import streamlit as st |
|
import transformers |
|
import torch |
|
from transformers import pipeline |
|
|
|
|
|
st.title("Emotion Detection with Transformers") |
|
|
|
|
|
user_input = st.text_area("Enter your text:") |
|
|
|
|
|
|
|
@st.cache(allow_output_mutation=True) |
|
def load_model(): |
|
return pipeline("sentiment-analysis") |
|
|
|
|
|
|
|
sentiment_analyzer = load_model() |
|
|
|
|
|
if st.button("Analyze Emotion"): |
|
if user_input: |
|
|
|
result = sentiment_analyzer(user_input) |
|
|
|
|
|
emotion = result[0]['label'] |
|
st.write(f"Emotion: {emotion}") |
|
else: |
|
st.warning("Please enter some text to analyze.") |
|
|