88import plotly.express as px
99from wordcloud import WordCloud,STOPWORDS
1010import create_wordcloud
11+ from PIL import Image
1112
1213
1314dataset_loc = "data/Tweets.csv"
1415image_loc = "img/airline.jpeg"
1516pos_loc = "img/pos.png"
1617neg_loc = "img/neg.png"
18+ img_airplane = Image.open(image_loc)
19+ img_pos_wc = Image.open(pos_loc)
20+ img_neg_wc = Image.open(neg_loc)
1721
1822# sidebar
1923def load_sidebar():
@@ -70,8 +74,9 @@ def load_viz(df):
7074 st.header("Data Visualisation")
7175 # show tweet sentiment count
7276 st.subheader("Seaborn - Tweet Sentiment Count")
73- st.write(sns.countplot(x='airline_sentiment', data=df))
74- st.pyplot()
77+ fig = plt.figure()
78+ sns.countplot(x='airline_sentiment', data=df)
79+ st.pyplot(fig)
7580
7681 # ***************
7782 st.subheader("Plotly - Tweet Sentiment Count")
@@ -82,25 +87,27 @@ def load_viz(df):
8287
8388 # show airline count
8489 st.subheader("Airline Count")
85- st.write(sns.countplot(x='airline', data=df))
86- st.pyplot()
90+ fig = plt.figure()
91+ sns.countplot(x='airline', data=df)
92+ st.pyplot(fig)
8793
8894 # Show sentiment based on airline
8995 st.subheader("Airline Count")
9096 airline = st.radio("Choose an Airline?", ("US Airways", "United", "American", "Southwest", "Delta", "Virgin America"))
9197 temp_df = df.loc[df['airline']==airline, :]
92- st.write(sns.countplot(x='airline_sentiment', order=['neutral', 'positive', 'negative'], data=temp_df))
93- st.pyplot()
98+ fig = plt.figure()
99+ sns.countplot(x='airline_sentiment', order=['neutral', 'positive', 'negative'], data=temp_df)
100+ st.pyplot(fig)
94101
95102 # Show WordCloud
96103 st.subheader("Word Cloud")
97104 type = st.radio("Choose the sentiment?", ("positive", "negative"))
98105 if(os.path.isfile(pos_loc)==False or os.path.isfile(neg_loc)==False):
99106 create_wordcloud.main()
100107 if(type=="positive"):
101- st.image(pos_loc , use_column_width = True)
108+ st.image(img_pos_wc , use_column_width = True)
102109 else:
103- st.image(neg_loc , use_column_width = True)
110+ st.image(img_neg_wc , use_column_width = True)
104111
105112
106113
@@ -111,7 +118,7 @@ def main():
111118
112119 # Title/ text
113120 st.title('Airline Sentiment Analysis')
114- st.image(image_loc , use_column_width = True)
121+ st.image(img_airplane , use_column_width = True)
115122 st.text('Analyze how travelers in February 2015 expressed their feelings on Twitter')
116123
117124 # loading the data
0 commit comments