Update app.py
Browse files
app.py
CHANGED
@@ -8,16 +8,6 @@ from scipy.special import softmax
|
|
8 |
from transformers import pipeline
|
9 |
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
#import the model
|
14 |
-
pipe=pipeline(model="Junr-syl/sentiments_analysis_DISTILBERT")
|
15 |
-
# tokenizer = AutoTokenizer.from_pretrained('Junr-syl/sentiments_analysis_DISTILBERT')
|
16 |
-
|
17 |
-
# model_path = f"Junr-syl/sentiments_analysis_DISTILBERT"
|
18 |
-
# config = AutoConfig.from_pretrained(model_path)
|
19 |
-
# model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
20 |
-
|
21 |
#Set the page configs
|
22 |
st.set_page_config(page_title='Sentiments Analysis',page_icon='π',layout='centered')
|
23 |
|
@@ -29,52 +19,42 @@ st.markdown("<h1 style='text-align: center'> Tweet Sentiments </h1>",unsafe_allo
|
|
29 |
with st.form(key='tweet',clear_on_submit=True):
|
30 |
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')
|
31 |
submit=st.form_submit_button('submit')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
#create columns to show outputs
|
34 |
col1,col2,col3=st.columns(3)
|
35 |
-
col1.
|
36 |
-
col2.
|
37 |
-
col3.
|
38 |
|
39 |
-
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
# #set username to @user
|
48 |
-
# t = '@user' if t.startswith('@') and len(t) > 1 else t
|
49 |
-
# #set tweet source to http
|
50 |
-
# t = 'http' if t.startswith('http') else t
|
51 |
-
# #store text in the list
|
52 |
-
# new_text.append(t)
|
53 |
-
# #change text from list back to string
|
54 |
-
# return " ".join(new_text)
|
55 |
-
|
56 |
|
57 |
-
|
|
|
58 |
output=pipe(text)
|
59 |
output_dict=output[0]
|
60 |
lable=output_dict['label']
|
61 |
score=output_dict['score']
|
62 |
-
# #change label id
|
63 |
-
# #config.id2label = {0: 'NEGATIVE', 1: 'NEUTRAL', 2: 'POSITIVE'}
|
64 |
-
|
65 |
-
# text = preprocess(text)
|
66 |
-
|
67 |
-
# # PyTorch-based models
|
68 |
-
# encoded_input = tokenizer(text, return_tensors='pt')
|
69 |
-
# output = model(**encoded_input)
|
70 |
-
# scores = output[0][0].detach().numpy()
|
71 |
-
# scores = softmax(scores)
|
72 |
-
|
73 |
-
# #Process scores
|
74 |
-
# ranking = np.argsort(scores)
|
75 |
-
# ranking = ranking[::-1]
|
76 |
-
# l = config.id2label[ranking[0]]
|
77 |
-
# s = scores[ranking[0]]
|
78 |
|
79 |
#output
|
80 |
if lable=='NEGATIVE':
|
|
|
8 |
from transformers import pipeline
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
#Set the page configs
|
12 |
st.set_page_config(page_title='Sentiments Analysis',page_icon='π',layout='centered')
|
13 |
|
|
|
19 |
with st.form(key='tweet',clear_on_submit=True):
|
20 |
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')
|
21 |
submit=st.form_submit_button('submit')
|
22 |
+
if submit:
|
23 |
+
st.success('Text received',icon='β
')
|
24 |
+
#Select a model
|
25 |
+
exp=st.expander(label='Choose a model and Click Continue or go ahead and Click continue to use default')
|
26 |
+
models={'Roberta': 'Junr-syl/sentiments_analysis_Roberta',
|
27 |
+
'Bert': 'Junr-syl/sentiments_analysis_upgrade',
|
28 |
+
'Distilbert':'Junr-syl/sentiments_analysis_DISTILBERT'}
|
29 |
+
|
30 |
+
with exp:
|
31 |
+
model=st.selectbox('Which model would you want to Use?',('Bert','Roberta','Distilbert'))
|
32 |
+
|
33 |
+
selected_model=models[model]
|
34 |
+
#Click continue if no model is selected
|
35 |
+
Cont=st.button('Continue','Continue processing input')
|
36 |
|
37 |
#create columns to show outputs
|
38 |
col1,col2,col3=st.columns(3)
|
39 |
+
col1.write('<h2 style="font-size: 24px;"> Sentiment Emoji </h2>',unsafe_allow_html=True)
|
40 |
+
col2.write('<h2 style="font-size: 24px;"> How this user feels about the vaccine </h2>',unsafe_allow_html=True)
|
41 |
+
col3.write('<h2 style="font-size: 24px;"> Confidence of this prediction </h2>',unsafe_allow_html=True)
|
42 |
|
43 |
+
if Cont:
|
44 |
+
#import the model
|
45 |
+
pipe=pipeline(model=selected_model)
|
46 |
+
tokenizer = AutoTokenizer.from_pretrained('selected_model')
|
47 |
+
|
48 |
+
model_path = f"Junr-syl/sentiments_analysis_DISTILBERT"
|
49 |
+
config = AutoConfig.from_pretrained(model_path)
|
50 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
|
53 |
+
#pass text to model
|
54 |
output=pipe(text)
|
55 |
output_dict=output[0]
|
56 |
lable=output_dict['label']
|
57 |
score=output_dict['score']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
#output
|
60 |
if lable=='NEGATIVE':
|