|
|
import streamlit as st |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
@st.cache(allow_output_mutation=True) |
|
|
def load_model(): |
|
|
return pipeline('text-classification', model='SamLowe/roberta-base-go_emotions', return_all_scores=True) |
|
|
|
|
|
|
|
|
def main(): |
|
|
st.title('Emotion Detection Application') |
|
|
|
|
|
model = load_model() |
|
|
|
|
|
st.write("Enter a text below to detect its emotions:") |
|
|
user_input = st.text_area("Text Input", "") |
|
|
|
|
|
if st.button("Analyze"): |
|
|
if user_input: |
|
|
results = model(user_input) |
|
|
st.write("Emotion Scores:") |
|
|
for result in results[0]: |
|
|
st.write(f"{result['label']}: {result['score']:.4f}") |
|
|
else: |
|
|
st.write("Please enter some text to analyze.") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|