Ptato commited on
Commit
6bc3901
·
1 Parent(s): 524b2c9

everything

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import time
3
+ from transformers import pipeline
4
+ import os
5
+
6
+ os.environ['KMP_DUPLICATE_LIB_OK'] = "True"
7
+
8
+
9
+
10
+ st.title("Sentiment Analysis App")
11
+
12
+ form = st.form(key='Sentiment Analysis')
13
+ box = form.selectbox('Select Pre-trained Model:', ['bertweet-base-sentiment-analysis',
14
+ 'distilbert-base-uncased-finetuned-sst-2-english',
15
+ 'twitter-roberta-base-sentiment'
16
+ ], key=1)
17
+ tweet = form.text_input(label='Enter text to analyze:', value="\"We've seen in the last few months, unprecedented amounts of Voter Fraud.\" @SenTedCruz True!")
18
+ submit = form.form_submit_button(label='Submit')
19
+
20
+ if submit and tweet:
21
+ with st.spinner('Analyzing...'):
22
+ time.sleep(1)
23
+ # st.header(tweet)
24
+
25
+ if tweet is not None:
26
+ col1, col2, col3 = st.columns(3)
27
+ if box == 'bertweet-base-sentiment-analysis':
28
+ pipeline = pipeline(task="sentiment-analysis", model="finiteautomata/bertweet-base-sentiment-analysis")
29
+ elif box == 'twitter-xlm-roberta-base-sentiment':
30
+ pipeline = pipeline(task="sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment")
31
+ else:
32
+ pipeline = pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
33
+ predictions = pipeline(tweet)
34
+ print(predictions)
35
+ col1.header("Tweet")
36
+ col1.subheader(tweet)
37
+ col2.header("Judgement")
38
+ col3.header("Probability")
39
+ for p in predictions:
40
+ if box == 'bertweet-base-sentiment-analysis':
41
+ if p['label'] == "POS":
42
+ col2.success(f"{ p['label'] }")
43
+ col3.success(f"{ round(p['score'] * 100, 1)}%")
44
+ elif p['label'] == "NEU":
45
+ col2.warning(f"{ p['label'] }")
46
+ col3.warning(f"{round(p['score'] * 100, 1)}%")
47
+ else:
48
+ col2.error(f"{p['label']}")
49
+ col3.error(f"{round(p['score'] * 100, 1)}%")
50
+ elif box == 'distilbert-base-uncased-finetuned-sst-2-english':
51
+ if p['label'] == "POSITIVE":
52
+ col2.success(f"{p['label']}")
53
+ col3.success(f"{round(p['score'] * 100, 1)}%")
54
+ else:
55
+ col2.error(f"{p['label']}")
56
+ col3.error(f"{round(p['score'] * 100, 1)}%")
57
+ else:
58
+ if p['label'] == "POSITIVE":
59
+ col2.success(f"{p['label']}")
60
+ col3.success(f"{round(p['score'] * 100, 1)}%")
61
+ else:
62
+ col2.error(f"{p['label']}")
63
+ col3.error(f"{round(p['score'] * 100, 1)}%")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ transformers