SandhyaRaghav commited on
Commit
93e42c9
·
verified ·
1 Parent(s): 2072224

Upload streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +141 -0
src/streamlit_app.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import preprocessor,helper
3
+ import matplotlib.pyplot as plt
4
+
5
+ st.markdown(
6
+ "<h1 style='text-align: center;'>Chat Analysis Space</h1>",
7
+ unsafe_allow_html=True
8
+ )
9
+
10
+ st.sidebar.title("Whatsapp Chat Analyzer")
11
+ uploaded_file = st.sidebar.file_uploader("Choose a file")
12
+ if uploaded_file is not None:
13
+ bytes_data = uploaded_file.getvalue()
14
+ data = bytes_data.decode("utf-8")
15
+ df = preprocessor.preprocess(data)
16
+
17
+
18
+ #fetch uniquw users
19
+ user_list=df["user"].unique().tolist()
20
+ user_list.remove("group_notification")
21
+ user_list.sort()
22
+ user_list.insert(0,"Overall")
23
+ selected_user=st.sidebar.selectbox("Show Analysis wrt",user_list)
24
+
25
+ if st.sidebar.button("Show Analysis"):
26
+ num_messages,words, num_media_messages,links=helper.fetch_stats(selected_user,df)
27
+ st.title("Top Statistics")
28
+ col1, col2, col3, col4 = st.columns(4)
29
+
30
+ with col1:
31
+ st.header("Total Message")
32
+ st.title(num_messages)
33
+
34
+ with col2:
35
+ st.header("Total Words")
36
+ st.title(words)
37
+
38
+ with col3:
39
+ st.header("Media Shared")
40
+ st.title(num_media_messages)
41
+
42
+ with col4:
43
+ st.header("Links Shared")
44
+ st.title(links)
45
+
46
+ if selected_user=="overall":
47
+ col1,col2=st.beta_columns(2)
48
+
49
+ # monthly timeline
50
+ st.title("Monthly Timeline")
51
+ timeline = helper.monthly_timeline(selected_user,df)
52
+ fig,ax = plt.subplots()
53
+ ax.plot(timeline['time'], timeline['message'],color='green')
54
+ plt.xticks(rotation='vertical')
55
+ st.pyplot(fig)
56
+
57
+ # daily timeline
58
+ st.title("Daily Timeline")
59
+ daily_timeline = helper.daily_timeline(selected_user, df)
60
+ fig, ax = plt.subplots()
61
+ ax.plot(daily_timeline['only_date'], daily_timeline['message'], color='black')
62
+ plt.xticks(rotation='vertical')
63
+ st.pyplot(fig)
64
+
65
+
66
+ # activity map
67
+ st.title('Activity Map')
68
+ col1,col2 = st.columns(2)
69
+
70
+ with col1:
71
+ st.header("Most busy day")
72
+ busy_day = helper.week_activity_map(selected_user,df)
73
+ fig,ax = plt.subplots()
74
+ ax.bar(busy_day.index,busy_day.values,color='purple')
75
+ plt.xticks(rotation='vertical')
76
+ st.pyplot(fig)
77
+
78
+ with col2:
79
+ st.header("Most busy month")
80
+ busy_month = helper.month_activity_map(selected_user, df)
81
+ fig, ax = plt.subplots()
82
+ ax.bar(busy_month.index, busy_month.values,color='orange')
83
+ plt.xticks(rotation='vertical')
84
+ st.pyplot(fig)
85
+
86
+
87
+
88
+ # finding the busiest users in the group(Group level)
89
+ if selected_user == 'Overall':
90
+ st.title('Most Busy Users')
91
+
92
+ x, new_df = helper.most_busy_users(df)
93
+ fig, ax = plt.subplots()
94
+
95
+ col1, col2 = st.columns(2)
96
+
97
+ with col1:
98
+ ax.bar(x.index, x.values, color='red')
99
+ #ax.set_xlabel('Users')
100
+ #ax.set_ylabel('Message Count')
101
+ #ax.set_title('Top 5 Most Active Users')
102
+ plt.xticks(rotation='vertical')
103
+ st.pyplot(fig)
104
+
105
+ with col2:
106
+ st.dataframe(new_df)
107
+
108
+ # WordCloud
109
+ st.title("Wordcloud")
110
+ df_wc = helper.create_wordcloud(selected_user,df)
111
+ fig,ax = plt.subplots()
112
+ ax.imshow(df_wc)
113
+ st.pyplot(fig)
114
+
115
+
116
+ # most common words
117
+ most_common_df = helper.most_common_words(selected_user,df)
118
+
119
+ fig,ax = plt.subplots()
120
+
121
+ ax.barh(most_common_df[0],most_common_df[1])
122
+ plt.xticks(rotation='vertical')
123
+
124
+ st.title('Most commmon words')
125
+ st.pyplot(fig)
126
+
127
+ # emoji analysis
128
+ emoji_df = helper.emoji_helper(selected_user,df)
129
+ st.title("Emoji Analysis")
130
+
131
+ col1,col2 = st.columns(2)
132
+
133
+ with col1:
134
+ st.dataframe(emoji_df)
135
+ with col2:
136
+ fig,ax = plt.subplots()
137
+ ax.pie(emoji_df[1].head(),labels=emoji_df[0].head(),autopct="%0.2f")
138
+ st.pyplot(fig)
139
+
140
+
141
+