|
import streamlit as st |
|
import streamlit.components.v1 as com |
|
|
|
from transformers import AutoModelForSequenceClassification,AutoTokenizer, AutoConfig |
|
import numpy as np |
|
|
|
from scipy.special import softmax |
|
from transformers import pipeline |
|
|
|
|
|
|
|
st.set_page_config(page_title='Sentiments Analysis',page_icon='π',layout='centered') |
|
|
|
|
|
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.markdown("<h2 style='text-align: center'> These models were trained to detect how a user feel about the covid vaccines based on their tweets(text) </h2>",unsafe_allow_html=True) |
|
|
|
|
|
with st.form(key='tweet',clear_on_submit=False): |
|
|
|
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') |
|
|
|
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')) |
|
|
|
submit=st.form_submit_button('submit') |
|
if submit: |
|
|
|
if text=="": |
|
st.write(f'input text is set to {alt_text}') |
|
text=alt_text |
|
else: |
|
st.success('Text received',icon='β
') |
|
|
|
exp=st.expander(label='Choose a model and Click Continue or go ahead and Click continue to use default') |
|
models={'Roberta': 'Junr-syl/sentiments_analysis_Roberta', |
|
'Bert': 'Junr-syl/sentiments_analysis_upgrade', |
|
'Distilbert':'Junr-syl/sentiments_analysis_DISTILBERT'} |
|
|
|
with exp: |
|
model=st.selectbox('Which model would you want to Use?',('Distilbert','Bert','Roberta')) |
|
|
|
selected_model=models[model] |
|
|
|
Cont=st.button('Continue','Continue processing input') |
|
|
|
|
|
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 Cont: |
|
|
|
pipe=pipeline(model=selected_model) |
|
|
|
|
|
|
|
output=pipe(text) |
|
output_dict=output[0] |
|
lable=output_dict['label'] |
|
score=output_dict['score'] |
|
|
|
|
|
if lable=='NEGATIVE': |
|
with col1: |
|
com.iframe("https://embed.lottiefiles.com/animation/125694") |
|
col2.write('NEGATIVE') |
|
col3.write(f'{score*100:.2f}%') |
|
elif lable=='POSITIVE': |
|
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}%') |
|
|
|
|
|
|