File size: 1,102 Bytes
6060e42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from streamlit import session_state
# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import pipeline

tokenizer = AutoTokenizer.from_pretrained("themeetjani/tweet-classification")
model = AutoModelForSequenceClassification.from_pretrained("themeetjani/tweet-classification")

classifier = pipeline("text-classification", model= model,  tokenizer = tokenizer, truncation=True, max_length=512)

st.set_page_config(page_title="Classification", page_icon="📈")
if 'tweet_class' not in session_state:
    session_state['tweet_class']= ""

def classify(tweet):
    predicted_classes= session_state['tweet_class']= classifier(tweet, top_k=1)
    print (tweet)
    print (predicted_classes)
    session_state['tweet_class'] = predicted_classes[0]['label']

st.title("Tweet Classifier")

tweet= st.text_area(label= "Please write the tweet bellow", 
              placeholder="What does the tweet say?")

st.text_area("result", value=session_state['tweet_class'])

st.button("Classify", on_click=classify, args=[tweet])