darthPanda commited on
Commit
f746f70
β€’
1 Parent(s): bd76069
Files changed (1) hide show
  1. app.py +22 -16
app.py CHANGED
@@ -15,8 +15,12 @@ def search_callback():
15
  if len(st.session_state.search_term) == 0:
16
  st.error("Please enter a search term")
17
  return
18
- st.session_state.df = hf.get_tweets(st.session_state.search_term, st.session_state.num_tweets)
19
- st.session_state.df = hf.get_sentiment(st.session_state.df)
 
 
 
 
20
 
21
  def twitter_form():
22
  with st.form(key="search_form"):
@@ -43,7 +47,6 @@ with st.sidebar:
43
  )
44
 
45
  if "df" in st.session_state:
46
-
47
  def make_dashboard(tweet_df, bar_color, wc_color):
48
  # first row
49
  col1, col2, col3 = st.columns([28, 34, 38])
@@ -98,16 +101,19 @@ if "df" in st.session_state:
98
 
99
  st.write(adjust_tab_font, unsafe_allow_html=True)
100
 
101
- tab1, tab2, tab3, tab4 = st.tabs(["All", "Positive 😊", "Negative ☹️", "Neutral 😐"])
102
- with tab1:
103
- tweet_df = st.session_state.df
104
- make_dashboard(tweet_df, bar_color="#1F77B4", wc_color="Blues")
105
- with tab2:
106
- tweet_df = st.session_state.df.query("Sentiment == 'Positive'")
107
- make_dashboard(tweet_df, bar_color="#54A24B", wc_color="Greens")
108
- with tab3:
109
- tweet_df = st.session_state.df.query("Sentiment == 'Negative'")
110
- make_dashboard(tweet_df, bar_color="#FF7F0E", wc_color="Oranges")
111
- with tab4:
112
- tweet_df = st.session_state.df.query("Sentiment == 'Neutral'")
113
- make_dashboard(tweet_df, bar_color="#1F77B4", wc_color="Blues")
 
 
 
 
15
  if len(st.session_state.search_term) == 0:
16
  st.error("Please enter a search term")
17
  return
18
+ try:
19
+ st.session_state.df = hf.get_tweets(st.session_state.search_term, st.session_state.num_tweets)
20
+ st.session_state.df = hf.get_sentiment(st.session_state.df)
21
+ except:
22
+ st.error("Please enter a valid search term")
23
+ return
24
 
25
  def twitter_form():
26
  with st.form(key="search_form"):
 
47
  )
48
 
49
  if "df" in st.session_state:
 
50
  def make_dashboard(tweet_df, bar_color, wc_color):
51
  # first row
52
  col1, col2, col3 = st.columns([28, 34, 38])
 
101
 
102
  st.write(adjust_tab_font, unsafe_allow_html=True)
103
 
104
+ try:
105
+ tab1, tab2, tab3, tab4 = st.tabs(["All", "Positive 😊", "Negative ☹️", "Neutral 😐"])
106
+ with tab1:
107
+ tweet_df = st.session_state.df
108
+ make_dashboard(tweet_df, bar_color="#1F77B4", wc_color="Blues")
109
+ with tab2:
110
+ tweet_df = st.session_state.df.query("Sentiment == 'Positive'")
111
+ make_dashboard(tweet_df, bar_color="#54A24B", wc_color="Greens")
112
+ with tab3:
113
+ tweet_df = st.session_state.df.query("Sentiment == 'Negative'")
114
+ make_dashboard(tweet_df, bar_color="#FF7F0E", wc_color="Oranges")
115
+ with tab4:
116
+ tweet_df = st.session_state.df.query("Sentiment == 'Neutral'")
117
+ make_dashboard(tweet_df, bar_color="#1F77B4", wc_color="Blues")
118
+ except:
119
+ st.error("No plots to display.")