File size: 982 Bytes
e6dec8b
 
 
 
 
 
 
2243385
e6dec8b
 
 
2243385
e6dec8b
 
 
 
2243385
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Import statements
import streamlit as st
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Get Input
models = {"Distilbert": "distilbert-base-uncased-finetuned-sst-2-english", "roBERTa" : "cardiffnlp/twitter-roberta-base-sentiment", "Bert" : "finiteautomata/bertweet-base-sentiment-analysis"}
text = st.text_area('Text to analyze', "On the review aggregation website Rotten Tomatoes, The Super Mario Bros Movie has a critics score of just 54 per cent positive, marking it as Rotten.")
model_name = st.selectbox("What model do you wanna use?",  ("Distilbert", "roBERTa", "Bert"))

# Default Model - DistilBert      
if text and st.button('Submit!'):
  model = AutoModelForSequenceClassification.from_pretrained(models[model_name])
  tokenizer = AutoTokenizer.from_pretrained(models[model_name])
  classifier = pipeline('sentiment-analysis', model = model, tokenizer = tokenizer)
  out = classifier(text)
  st.json(out)