File size: 1,918 Bytes
f6fe135
 
 
 
 
 
 
 
 
 
 
 
 
 
b5f0ee1
f6fe135
 
 
 
 
b5f0ee1
2f2fe28
f6fe135
 
 
 
 
 
 
b5f0ee1
f6fe135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
from transformers import pipeline

st.title('Sentiment Analyser')
st.image("https://www.pngall.com/wp-content/uploads/5/Emotion-Transparent.png")

st.write("---")
st.header('Step 1 - Select a language model')
col1, col2 = st.columns(2)

selection = "N/A"
with col1:
    selection = st.radio("Pick one of the four pre-trained models below:",
        key = "modelChoice",
        options = ["DistilBERT", "Toxicity-Classifier", "SiEBERT", "Twitter-roBERTa"],
    )

pipe = pipeline('sentiment-analysis')
if selection == "DistilBERT":
    pipe = pipeline(model = "distilbert-base-uncased-finetuned-sst-2-english")
if selection == "Toxicity-Classifier":
    pipe = pipeline(model = "unitary/toxic-bert")
if selection == "Twitter-roBERTa":
    pipe = pipeline(model = "cardiffnlp/twitter-roberta-base-sentiment-latest")
if selection == "SiEBERT":
    pipe = pipeline(model = "siebert/sentiment-roberta-large-english")

with col2:
    st.caption('DistilBERT - One of the most popular and widely-used language models. Labels text as POSITIVE or NEGATIVE. Developed by Hugging Face.')
    st.caption('Toxicity-Classifier - A model trained to classify tweets under different toxicity-related categories.')
    st.caption('SiEBERT - A model trained on diverse text sources to improve generalization. Labels text as POSITIVE or NEGATIVE. Developed by siebert.')
    st.caption('Twitter-roBERTa - A model trained on over 124M tweets. Labels text as POSITIVE, NEGATIVE or NEUTRAL. Developed by cardiffnlp.')

st.write("---")
st.header('Step 2 - Enter some text')
text = st.text_area('The sentiment of the text entered here will be determined based on the model you chose above.',
                   value = "It was the best of times, it was the worst of times.")

st.write("---")
st.header('Step 3 - View your results')

if text:
    st.write('Model used: ', selection)
    out = pipe(text)
    st.json(out)