awacke1 commited on
Commit
1971026
Β·
1 Parent(s): e342813

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -27,31 +27,32 @@ def display_history():
27
  st.dataframe(df.style.highlight_max(axis=0))
28
 
29
  def run():
30
- search_words = st.text_input('Enter a word or phrase you want to know about')
31
- number_of_tweets = st.number_input('How many tweets do you want to see? (maximum 50)', 1, 50, 50)
32
- submit_button = st.form_submit_button(label='Submit')
 
33
 
34
- if submit_button:
35
- unique_tweets, tweet_list, sentiment_list = set(), [], []
36
- tweets = tw.Cursor(api.search_tweets, q=search_words, lang="en").items(number_of_tweets)
37
- for tweet in tweets:
38
- if tweet.text not in unique_tweets:
39
- unique_tweets.add(tweet.text)
40
- tweet_list.append(tweet.text)
41
- p = classifier(tweet.text)
42
- sentiment_list.append(p[0]['label'])
43
 
44
- df = pd.DataFrame(list(zip(tweet_list, sentiment_list)), columns=['Tweets', 'Sentiment'])
45
- st.write(df)
46
 
47
- summary = df.groupby('Sentiment').size().reset_index(name='Counts')
48
- fig, ax = plt.subplots()
49
- ax.pie(summary['Counts'], labels=summary['Sentiment'], autopct='%1.1f%%', startangle=90)
50
- ax.axis('equal')
51
- st.pyplot(fig)
52
 
53
- with open(FILE_NAME, mode='a', newline='') as file:
54
- df.to_csv(file, header=False, index=False)
55
 
56
  if st.button('Clear History'):
57
  os.remove(FILE_NAME)
 
27
  st.dataframe(df.style.highlight_max(axis=0))
28
 
29
  def run():
30
+ with st.form(key='Enter name'):
31
+ search_words = st.text_input('Enter a word or phrase you want to know about')
32
+ number_of_tweets = st.number_input('How many tweets do you want to see? (maximum 50)', 1, 50, 50)
33
+ submit_button = st.form_submit_button(label='Submit')
34
 
35
+ if submit_button:
36
+ unique_tweets, tweet_list, sentiment_list = set(), [], []
37
+ tweets = tw.Cursor(api.search_tweets, q=search_words, lang="en").items(number_of_tweets)
38
+ for tweet in tweets:
39
+ if tweet.text not in unique_tweets:
40
+ unique_tweets.add(tweet.text)
41
+ tweet_list.append(tweet.text)
42
+ p = classifier(tweet.text)
43
+ sentiment_list.append(p[0]['label'])
44
 
45
+ df = pd.DataFrame(list(zip(tweet_list, sentiment_list)), columns=['Tweets', 'Sentiment'])
46
+ st.write(df)
47
 
48
+ summary = df.groupby('Sentiment').size().reset_index(name='Counts')
49
+ fig, ax = plt.subplots()
50
+ ax.pie(summary['Counts'], labels=summary['Sentiment'], autopct='%1.1f%%', startangle=90)
51
+ ax.axis('equal')
52
+ st.pyplot(fig)
53
 
54
+ with open(FILE_NAME, mode='a', newline='') as file:
55
+ df.to_csv(file, header=False, index=False)
56
 
57
  if st.button('Clear History'):
58
  os.remove(FILE_NAME)