Jainesh212 commited on
Commit
0465686
·
1 Parent(s): 56e18b5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from textblob import TextBlob
2
+ import pandas as pd
3
+ import streamlit as st
4
+ import cleantext
5
+
6
+
7
+ st.header('Sentiment Analysis')
8
+ with st.expander('Analyze Text'):
9
+ text = st.text_input('Text here: ')
10
+ if text:
11
+ blob = TextBlob(text)
12
+ st.write('Polarity: ', round(blob.sentiment.polarity,2))
13
+ st.write('Subjectivity: ', round(blob.sentiment.subjectivity,2))
14
+
15
+
16
+ pre = st.text_input('Clean Text: ')
17
+ if pre:
18
+ st.write(cleantext.clean(pre, clean_all= False, extra_spaces=True ,
19
+ stopwords=True ,lowercase=True ,numbers=True , punct=True))
20
+
21
+ with st.expander('Analyze CSV'):
22
+ upl = st.file_uploader('Upload file')
23
+
24
+ def score(x):
25
+ blob1 = TextBlob(x)
26
+ return blob1.sentiment.polarity
27
+
28
+ #
29
+ def analyze(x):
30
+ if x >= 0.5:
31
+ return 'Positive'
32
+ elif x <= -0.5:
33
+ return 'Negative'
34
+ else:
35
+ return 'Neutral'
36
+
37
+ #
38
+ if upl:
39
+ df = pd.read_excel(upl)
40
+ del df['Unnamed: 0']
41
+ df['score'] = df['tweets'].apply(score)
42
+ df['analysis'] = df['score'].apply(analyze)
43
+ st.write(df.head(10))
44
+
45
+ @st.cache
46
+ def convert_df(df):
47
+ # IMPORTANT: Cache the conversion to prevent computation on every rerun
48
+ return df.to_csv().encode('utf-8')
49
+
50
+ csv = convert_df(df)
51
+
52
+ st.download_button(
53
+ label="Download data as CSV",
54
+ data=csv,
55
+ file_name='sentiment.csv',
56
+ mime='text/csv',
57
+ )
58
+
59
+