johnowhitaker commited on
Commit
6796bfc
1 Parent(s): 1cf959e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
  import twint
4
  import nest_asyncio
5
  import multiprocessing.pool
@@ -13,6 +14,8 @@ import csv
13
  import urllib.request
14
  import IPython.display as ipd
15
 
 
 
16
  # Preprocess text (username and link placeholders)
17
  def preprocess(text):
18
  new_text = []
@@ -76,11 +79,11 @@ def get_tweets(username, limit=500, save_name=None):
76
  df.to_csv(save_name)
77
  return df
78
 
79
- st.title('Test')
80
 
81
 
82
  with st.form("my_form"):
83
- st.write("Inside the form")
84
  user = st.text_input("Twitter Username")
85
  n_tweets = st.slider('How Many Tweets', 20, 2000, 20)
86
 
@@ -94,5 +97,8 @@ if submitted:
94
  st.write("Calculating sentiments...")
95
  tweets['sentiment'] = tweets['tweet'].map(lambda s: combined_score(s))
96
  st.write("Average sentiment:", tweets.sentiment.mean())
97
- st.pyplot.hexbin(tweets['tweet_length'], tweets['sentiment']*1,
98
- gridsize=20, bins=12, cmap='inferno')
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ from matplotlib import pyplot as plt
4
  import twint
5
  import nest_asyncio
6
  import multiprocessing.pool
 
14
  import urllib.request
15
  import IPython.display as ipd
16
 
17
+ title = st.title('Loading')
18
+
19
  # Preprocess text (username and link placeholders)
20
  def preprocess(text):
21
  new_text = []
 
79
  df.to_csv(save_name)
80
  return df
81
 
82
+ title = st.title('Twitter Sentiment Map Thingee')
83
 
84
 
85
  with st.form("my_form"):
86
+ st.write("Parameters:")
87
  user = st.text_input("Twitter Username")
88
  n_tweets = st.slider('How Many Tweets', 20, 2000, 20)
89
 
 
97
  st.write("Calculating sentiments...")
98
  tweets['sentiment'] = tweets['tweet'].map(lambda s: combined_score(s))
99
  st.write("Average sentiment:", tweets.sentiment.mean())
100
+ fig, axs = plt.subplots(1, 2)
101
+ axs[0].hexbin(tweets['tweet_length'], tweets['sentiment']*1,
102
+ gridsize=20, bins=12, cmap='inferno')
103
+ axs[1].scatter(tweets['tweet_length'], tweets['sentiment'])
104
+ st.pyplot(fig)