File size: 670 Bytes
5b974e3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import streamlit as st
from transformers import pipeline

@st.cache_resource(show_spinner="Loading model...")
def load_pipe():
    pipe = pipeline(task="text-classification", model="cnicu/tweet_emotions_classifier")
    return pipe

def classify_emotion(text: str, pipe: pipeline) -> str:
    prediction = pipe(text)
    return prediction

st.title("Tweet emotions classification")

text = st.text_area("Tweet to classify", label_visibility='hidden')

if st.button("Classify tweet", disabled= text == ''):
    with st.spinner("In progress..."):
        prediction = classify_emotion(text, load_pipe())
        st.success(f"Tweet's emotion: **{prediction[0]['label']}**")