-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
165 lines (112 loc) · 4.65 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import streamlit as st
import preprocess
import re
import stats
import matplotlib.pyplot as plt
import numpy as np
st.sidebar.title("Whatsapp Chat Analyzer")
# this is for uploading a file
uploaded_file = st.sidebar.file_uploader("Choose a file")
if uploaded_file is not None:
bytes_data = uploaded_file.getvalue()
# converting the bytecode to the text-file
data = bytes_data.decode("utf-8")
# sending the file data to the preprocess function for further functioning
df = preprocess.preprocess(data)
# displaying the dataframe
# st.dataframe(df)
# fetch unique users
user_list = df['User'].unique().tolist()
# removing the groupnotification
user_list.remove('Group Notification')
# organinsing things
user_list.sort()
# including overall,this will be responsible for showcasing the overall chat group analysis
user_list.insert(0, "Overall")
selected_user = st.sidebar.selectbox(
"Show analysis with respect to", user_list)
st.title("Whats App Chat Analysis for " + selected_user)
if st.sidebar.button("Show Analysis"):
# getting the stats of the selected user from the stats script
num_messages, num_words, media_omitted, links = stats.fetchstats(
selected_user, df)
# first phase is to showcase the basic stats like number of users,number of messages,number of media shared and all,so for that i requrire the 4 columns
col1, col2, col3, col4 = st.beta_columns(4)
with col1:
st.header("Total Messages")
st.title(num_messages)
with col2:
st.header("Total No.of Words")
st.title(num_words)
with col3:
st.header("Media Shared")
st.title(media_omitted)
with col4:
st.header("Total Links Shared")
st.title(links)
# finding the busiest users in the group
if selected_user == 'Overall':
# dividing the space into two columns
# first col is the bar chart and the second col is the dataframe representing the
st.title('Most Busy Users')
busycount, newdf = stats.fetchbusyuser(df)
fig, ax = plt.subplots()
col1, col2 = st.beta_columns(2)
with col1:
ax.bar(busycount.index, busycount.values, color='red')
plt.xticks(rotation='vertical')
st.pyplot(fig)
with col2:
st.dataframe(newdf)
# Word Cloud
st.title('Word Cloud')
df_img = stats.createwordcloud(selected_user, df)
fig, ax = plt.subplots()
ax.imshow(df_img)
st.pyplot(fig)
# most common words in the chat
most_common_df = stats.getcommonwords(selected_user, df)
fig, ax = plt.subplots()
ax.barh(most_common_df[0], most_common_df[1])
plt.xticks(rotation='vertical')
st.title('Most commmon words')
st.pyplot(fig)
# Emoji Analysis
emoji_df = stats.getemojistats(selected_user, df)
emoji_df.columns = ['Emoji', 'Count']
st.title("Emoji Analysis")
col1, col2 = st.beta_columns(2)
with col1:
st.dataframe(emoji_df)
with col2:
emojicount = list(emoji_df['Count'])
perlist = [(i/sum(emojicount))*100 for i in emojicount]
emoji_df['Percentage use'] = np.array(perlist)
st.dataframe(emoji_df)
# Monthly timeline
st.title("Monthly Timeline")
time = stats.monthtimeline(selected_user, df)
fig, ax = plt.subplots()
ax.plot(time['Time'], time['Message'], color='green')
plt.xticks(rotation='vertical')
plt.tight_layout()
st.pyplot(fig)
# Activity maps
st.title("Activity Maps")
col1, col2 = st.beta_columns(2)
with col1:
st.header("Most Busy Day")
busy_day = stats.weekactivitymap(selected_user, df)
fig, ax = plt.subplots()
ax.bar(busy_day.index, busy_day.values, color='purple')
plt.xticks(rotation='vertical')
plt.tight_layout()
st.pyplot(fig)
with col2:
st.header("Most Busy Month")
busy_month = stats.monthactivitymap(selected_user, df)
fig, ax = plt.subplots()
ax.bar(busy_month.index, busy_month.values, color='orange')
plt.xticks(rotation='vertical')
plt.tight_layout()
st.pyplot(fig)