Spaces:
Runtime error
Runtime error
add subheaders to improve formatting
Browse files
app.py
CHANGED
@@ -4,9 +4,7 @@
|
|
4 |
# imports
|
5 |
import streamlit as st
|
6 |
import pandas as pd
|
7 |
-
import numpy as np
|
8 |
import os
|
9 |
-
import matplotlib.pyplot as plt
|
10 |
import seaborn as sns
|
11 |
import plotly.express as px
|
12 |
import pickle
|
@@ -66,7 +64,7 @@ sentiment_results, zero_shot_results = read_climate_change_results()
|
|
66 |
|
67 |
|
68 |
# write title of app
|
69 |
-
st.title('
|
70 |
st.markdown('''---''')
|
71 |
|
72 |
|
@@ -247,6 +245,8 @@ fig = px.pie(
|
|
247 |
)
|
248 |
st.plotly_chart(fig, use_container_width=True)
|
249 |
st.markdown('''---''')
|
|
|
|
|
250 |
|
251 |
|
252 |
|
@@ -261,6 +261,7 @@ st.write('''
|
|
261 |
''')
|
262 |
st.write('\n')
|
263 |
|
|
|
264 |
st.write(f'''
|
265 |
Here we have {len(tokyo):,} tweets from the Tokyo Olympics, going through them manually and coming up with topics would not be practical.
|
266 |
''')
|
@@ -271,10 +272,10 @@ st.dataframe(tokyo)
|
|
271 |
st.write('\n')
|
272 |
st.write('\n')
|
273 |
|
|
|
274 |
st.write('''
|
275 |
Lets generate some topics without performing any cleaning to the data.
|
276 |
''')
|
277 |
-
st.write('\n')
|
278 |
|
279 |
# load and plot topics using unclean data
|
280 |
with open('data/topics_tokyo_unclean.pickle', 'rb') as pkl:
|
@@ -325,6 +326,7 @@ st.write(f'''
|
|
325 |
st.dataframe(topics_df)
|
326 |
st.write('\n')
|
327 |
|
|
|
328 |
st.write('''
|
329 |
One point to also note is that the machine is not only picking out keywords in a tweet to determine its topic.
|
330 |
The model has an understanding of the relationship between words, e.g. 'Andy Murray' is related to 'tennis'.
|
@@ -353,7 +355,8 @@ st.write(f'''
|
|
353 |
# display tweets from selected topic
|
354 |
st.dataframe(topic_results.loc[(topic_results['Topic'] == inspect_topic)])
|
355 |
st.markdown('''---''')
|
356 |
-
|
|
|
357 |
|
358 |
|
359 |
|
@@ -369,9 +372,14 @@ st.write(f'''
|
|
369 |
''')
|
370 |
st.write('\n')
|
371 |
|
|
|
|
|
|
|
|
|
372 |
# rename column
|
373 |
sentiment_results = sentiment_results.rename(columns={'sequence':'Tweet'})
|
374 |
st.dataframe(sentiment_results[['Tweet']])
|
|
|
375 |
|
376 |
@st.cache(allow_output_mutation=True)
|
377 |
def load_transfomer_pipelines():
|
@@ -405,6 +413,7 @@ tweet_index = sentiment_results.index
|
|
405 |
first_tweet = tweet_index[0]
|
406 |
last_tweet = tweet_index[-1]
|
407 |
|
|
|
408 |
st.write(f'''
|
409 |
As a demonstration, we'll define some categories and pick a tweet to classify and determine its sentiment.
|
410 |
Feel free to add your own categories or even input your own text!
|
@@ -428,8 +437,8 @@ with st.form('classify_tweets'):
|
|
428 |
|
429 |
# submit form
|
430 |
submit = st.form_submit_button('Classify Tweet')
|
431 |
-
|
432 |
st.write('\n')
|
|
|
433 |
st.write(f'''
|
434 |
Here are the results:
|
435 |
''')
|
@@ -461,6 +470,8 @@ st.write('\n')
|
|
461 |
# drop unused columns and rename columns
|
462 |
zero_shot_results = zero_shot_results.drop('labels_scores', axis=1)
|
463 |
zero_shot_results = zero_shot_results.rename(columns={'sequence':'tweet', 'label':'category'})
|
|
|
|
|
464 |
st.write(f'''
|
465 |
Lets review all the tweets and how they fall into the categories of finance, politics, technology, and wildlife.
|
466 |
''')
|
|
|
4 |
# imports
|
5 |
import streamlit as st
|
6 |
import pandas as pd
|
|
|
7 |
import os
|
|
|
8 |
import seaborn as sns
|
9 |
import plotly.express as px
|
10 |
import pickle
|
|
|
64 |
|
65 |
|
66 |
# write title of app
|
67 |
+
st.title('Survey Analytic Techniques')
|
68 |
st.markdown('''---''')
|
69 |
|
70 |
|
|
|
245 |
)
|
246 |
st.plotly_chart(fig, use_container_width=True)
|
247 |
st.markdown('''---''')
|
248 |
+
st.write('\n')
|
249 |
+
st.write('\n')
|
250 |
|
251 |
|
252 |
|
|
|
261 |
''')
|
262 |
st.write('\n')
|
263 |
|
264 |
+
st.subheader('Sample Tweets - Tokyo Olympics')
|
265 |
st.write(f'''
|
266 |
Here we have {len(tokyo):,} tweets from the Tokyo Olympics, going through them manually and coming up with topics would not be practical.
|
267 |
''')
|
|
|
272 |
st.write('\n')
|
273 |
st.write('\n')
|
274 |
|
275 |
+
st.subheader('Visualising Topics')
|
276 |
st.write('''
|
277 |
Lets generate some topics without performing any cleaning to the data.
|
278 |
''')
|
|
|
279 |
|
280 |
# load and plot topics using unclean data
|
281 |
with open('data/topics_tokyo_unclean.pickle', 'rb') as pkl:
|
|
|
326 |
st.dataframe(topics_df)
|
327 |
st.write('\n')
|
328 |
|
329 |
+
st.subheader('Inspecting Individual Topics')
|
330 |
st.write('''
|
331 |
One point to also note is that the machine is not only picking out keywords in a tweet to determine its topic.
|
332 |
The model has an understanding of the relationship between words, e.g. 'Andy Murray' is related to 'tennis'.
|
|
|
355 |
# display tweets from selected topic
|
356 |
st.dataframe(topic_results.loc[(topic_results['Topic'] == inspect_topic)])
|
357 |
st.markdown('''---''')
|
358 |
+
st.write('\n')
|
359 |
+
st.write('\n')
|
360 |
|
361 |
|
362 |
|
|
|
372 |
''')
|
373 |
st.write('\n')
|
374 |
|
375 |
+
st.subheader('Sample Tweets - Climate Change')
|
376 |
+
st.write(f'''
|
377 |
+
We'll use a different set of {len(sentiment_results):,} tweets related to climate change.
|
378 |
+
''')
|
379 |
# rename column
|
380 |
sentiment_results = sentiment_results.rename(columns={'sequence':'Tweet'})
|
381 |
st.dataframe(sentiment_results[['Tweet']])
|
382 |
+
st.write('\n')
|
383 |
|
384 |
@st.cache(allow_output_mutation=True)
|
385 |
def load_transfomer_pipelines():
|
|
|
413 |
first_tweet = tweet_index[0]
|
414 |
last_tweet = tweet_index[-1]
|
415 |
|
416 |
+
st.subheader('Classifying Text')
|
417 |
st.write(f'''
|
418 |
As a demonstration, we'll define some categories and pick a tweet to classify and determine its sentiment.
|
419 |
Feel free to add your own categories or even input your own text!
|
|
|
437 |
|
438 |
# submit form
|
439 |
submit = st.form_submit_button('Classify Tweet')
|
|
|
440 |
st.write('\n')
|
441 |
+
|
442 |
st.write(f'''
|
443 |
Here are the results:
|
444 |
''')
|
|
|
470 |
# drop unused columns and rename columns
|
471 |
zero_shot_results = zero_shot_results.drop('labels_scores', axis=1)
|
472 |
zero_shot_results = zero_shot_results.rename(columns={'sequence':'tweet', 'label':'category'})
|
473 |
+
|
474 |
+
st.subheader('Zero-Shot Classification and Sentiment Analysis Results')
|
475 |
st.write(f'''
|
476 |
Lets review all the tweets and how they fall into the categories of finance, politics, technology, and wildlife.
|
477 |
''')
|