Spaces:
Runtime error
Runtime error
Delete app (1).py
Browse files- app (1).py +0 -73
app (1).py
DELETED
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import streamlit.components.v1 as com
|
| 3 |
-
#import libraries
|
| 4 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig
|
| 5 |
-
import numpy as np
|
| 6 |
-
#convert logits to probabilities
|
| 7 |
-
from scipy.special import softmax
|
| 8 |
-
from transformers import pipeline
|
| 9 |
-
|
| 10 |
-
#Set the page configs
|
| 11 |
-
st.set_page_config(page_title='Sentiments Analysis',page_icon='😎',layout='wide')
|
| 12 |
-
|
| 13 |
-
#welcome Animation
|
| 14 |
-
com.iframe("https://embed.lottiefiles.com/animation/149093")
|
| 15 |
-
st.markdown("<h1 style='text-align: center'> Covid Vaccine Tweet Sentiments </h1>",unsafe_allow_html=True)
|
| 16 |
-
st.write("<h2 style='font-size: 24px;'> These models were trained to detect how a user feels about the covid vaccines based on their tweets(text) </h2>",unsafe_allow_html=True)
|
| 17 |
-
|
| 18 |
-
#Create a form to take user inputs
|
| 19 |
-
with st.form(key='tweet',clear_on_submit=True):
|
| 20 |
-
#input text
|
| 21 |
-
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')
|
| 22 |
-
#Set examples
|
| 23 |
-
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'))
|
| 24 |
-
#Select a model
|
| 25 |
-
models={'Bert':'UholoDala/tweet_sentiments_analysis_bert',
|
| 26 |
-
'Distilbert':'UholoDala/tweet_sentiments_analysis_distilbert',
|
| 27 |
-
'Roberta':'UholoDala/tweet_sentiments_analysis_roberta'}
|
| 28 |
-
model=st.selectbox('Which model would you want to Use?',('Bert','Distilbert','Roberta'))
|
| 29 |
-
#Submit
|
| 30 |
-
submit=st.form_submit_button('Predict','Continue processing input')
|
| 31 |
-
|
| 32 |
-
selected_model=models[model]
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
#create columns to show outputs
|
| 36 |
-
col1,col2,col3=st.columns(3)
|
| 37 |
-
col1.write('<h2 style="font-size: 24px;"> Sentiment Emoji </h2>',unsafe_allow_html=True)
|
| 38 |
-
col2.write('<h2 style="font-size: 24px;"> How this user feels about the vaccine </h2>',unsafe_allow_html=True)
|
| 39 |
-
col3.write('<h2 style="font-size: 24px;"> Confidence of this prediction </h2>',unsafe_allow_html=True)
|
| 40 |
-
|
| 41 |
-
if submit:
|
| 42 |
-
#Check text
|
| 43 |
-
if text=="":
|
| 44 |
-
text=alt_text
|
| 45 |
-
st.success(f"input text is set to '{text}'")
|
| 46 |
-
else:
|
| 47 |
-
st.success('Text received',icon='✅')
|
| 48 |
-
|
| 49 |
-
#import the model
|
| 50 |
-
pipe=pipeline(model=selected_model)
|
| 51 |
-
|
| 52 |
-
#pass text to model
|
| 53 |
-
output=pipe(text)
|
| 54 |
-
output_dict=output[0]
|
| 55 |
-
lable=output_dict['label']
|
| 56 |
-
score=output_dict['score']
|
| 57 |
-
|
| 58 |
-
#output
|
| 59 |
-
if lable=='NEGATIVE' or lable=='LABEL_0':
|
| 60 |
-
with col1:
|
| 61 |
-
com.iframe("https://embed.lottiefiles.com/animation/125694")
|
| 62 |
-
col2.write('NEGATIVE')
|
| 63 |
-
col3.write(f'{score:.2%}')
|
| 64 |
-
elif lable=='POSITIVE'or lable=='LABEL_2':
|
| 65 |
-
with col1:
|
| 66 |
-
com.iframe("https://embed.lottiefiles.com/animation/148485")
|
| 67 |
-
col2.write('POSITIVE')
|
| 68 |
-
col3.write(f'{score:.2%}')
|
| 69 |
-
else:
|
| 70 |
-
with col1:
|
| 71 |
-
com.iframe("https://embed.lottiefiles.com/animation/136052")
|
| 72 |
-
col2.write('NEUTRAL')
|
| 73 |
-
col3.write(f'{score:.2%}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|