Skip to content

Commit 4d0bfe8

Browse files
authored
Add files via upload
1 parent b54f7c7 commit 4d0bfe8

File tree

1 file changed

+16
-9
lines changed
  • Case Studies/2. Airline Sentiment Analyser/web_app

1 file changed

+16
-9
lines changed

Case Studies/2. Airline Sentiment Analyser/web_app/data_app.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
import plotly.express as px
99
from wordcloud import WordCloud,STOPWORDS
1010
import create_wordcloud
11+
from PIL import Image
1112

1213

1314
dataset_loc = "data/Tweets.csv"
1415
image_loc = "img/airline.jpeg"
1516
pos_loc = "img/pos.png"
1617
neg_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
1923
def 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

Comments
 (0)