Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -27,31 +27,32 @@ def display_history():
|
|
27 |
st.dataframe(df.style.highlight_max(axis=0))
|
28 |
|
29 |
def run():
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
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)
|