File size: 3,121 Bytes
9f65e0d
 
 
 
 
 
 
0aaefc8
9f65e0d
 
 
6ed966a
9f65e0d
 
 
cace45a
4fcc1e7
9f65e0d
 
8c94476
cace45a
9f65e0d
cace45a
6a63bea
7fc522d
 
defb642
 
3d3386f
7fc522d
 
 
defb642
9f65e0d
 
 
defb642
 
 
9f65e0d
7fc522d
 
 
 
6a63bea
7fc522d
 
 
defb642
 
780e5cb
defb642
7a34d4d
 
 
 
 
 
 
0017c12
7a34d4d
 
 
 
0017c12
7a34d4d
 
 
 
 
 
 
 
 
9f65e0d
fda4b3f
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import streamlit as st
import streamlit.components.v1 as com
#import libraries
from transformers import AutoModelForSequenceClassification,AutoTokenizer, AutoConfig
import numpy as np
#convert logits to probabilities
from scipy.special import softmax
from transformers import pipeline


#Set the page configs
st.set_page_config(page_title='Sentiments Analysis',page_icon='😎',layout='centered')

#welcome Animation
com.iframe("https://embed.lottiefiles.com/animation/149093")
st.markdown("<h1 style='text-align: center'> Covid Vaccine Tweet Sentiments </h1>",unsafe_allow_html=True)
st.write("<h2 style='font-size: 24px;'> These models were trained to detect how a user feel about the covid vaccines based on their tweets(text) </h2>",unsafe_allow_html=True)

#Create a form to take user inputs
with st.form(key='tweet',clear_on_submit=True):
    #input text
    text=st.text_area('Copy and paste a tweet or type one',placeholder='I find it quite amusing how people ignore the effects of not taking the vaccine')
    #Set examples
    alt_text=st.selectbox("Can't Type?  Select an Example below",('I hate the vaccines','Vaccines made from dead human tissues','Take the vaccines or regret the consequences','Covid is a Hoax','Making the vaccines is a huge step forward for humanity. Just take them'))
    #Select a model
    models={'Roberta': 'Junr-syl/sentiments_analysis_Roberta',
        'Bert':    'Junr-syl/sentiments_analysis_upgrade',
        'Distilbert':'Junr-syl/sentiments_analysis_DISTILBERT'}
    model=st.selectbox('Which model would you want to Use? Distilbert is Recommended',('Distilbert','Bert','Roberta'))
     #Submit
    submit=st.form_submit_button('Predict','Continue processing input')
    
selected_model=models[model]

#create columns to show outputs
col1,col2,col3=st.columns(3)
col1.write('<h2 style="font-size: 24px;"> Sentiment Emoji </h2>',unsafe_allow_html=True)
col2.write('<h2 style="font-size: 24px;"> How this user feels about the vaccine </h2>',unsafe_allow_html=True)
col3.write('<h2 style="font-size: 24px;"> Confidence of this prediction </h2>',unsafe_allow_html=True)

if submit:
    #Check text
    if text=="":
        text=alt_text
        st.success(f"input text is set to '{text}'")    
    else:
        st.success('Text received',icon='βœ…')
        
    #import the model
    pipe=pipeline(model=selected_model)
    
    
    #pass text to model
    output=pipe(text)
    output_dict=output[0]
    lable=output_dict['label']
    score=output_dict['score']
    
        #output
    if lable=='NEGATIVE' or lable=='LABEL_0':
        with col1:
            com.iframe("https://embed.lottiefiles.com/animation/125694")
        col2.write('NEGATIVE')
        col3.write(f'{score*100:.2f}%')
    elif lable=='POSITIVE'or lable=='LABEL_2':
        with col1:
            com.iframe("https://embed.lottiefiles.com/animation/148485")
        col2.write('POSITIVE')
        col3.write(f'{score*100:.2f}%')
    else:
        with col1:
            com.iframe("https://embed.lottiefiles.com/animation/136052")
        col2.write('NEUTRAL')
        col3.write(f'{score*100:.2f}%')