-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
156 lines (125 loc) · 5.01 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
import streamlit as st
import preprocessor
import modify
import matplotlib.pyplot as plt
import seaborn as sns
st.sidebar.title("Chat Analyzer")
uploaded_file = st.sidebar.file_uploader("Choose a File")
if uploaded_file is not None:
bytes_data = uploaded_file.getvalue()
data = bytes_data.decode("utf-8")
df = preprocessor.preprocess(data)
user_list = df['user'].unique().tolist()
user_list.remove('group_notification')
user_list.sort()
user_list.insert(0, 'Overall')
selected_user = st.sidebar.selectbox("Show Analysis wrt", user_list)
if st.sidebar.button("Show Analysis"):
st.title('Top Statistics')
if selected_user == 'Overall':
tol_users = modify.total_users(df)
st.header("Total Users in Groups: " + str(tol_users))
tol_messages, words, media_msg, tol_links = modify.fetch_stats(selected_user, df)
col1, col2, col3, col4 = st.columns(4)
with col1:
st.header("Total Messages")
st.title(tol_messages)
with col2:
st.header("Total Words")
st.title(words)
with col3:
st.header("Total Media Shared")
st.title(media_msg)
with col4:
st.header("Total Links Shared")
st.title(tol_links)
# Monthly_TimeLine
st.title("Monthly Timeline")
timeline = modify.monthly_timeline(selected_user, df)
fig, ax = plt.subplots()
ax.plot(timeline['time'], timeline['message'], color='#6dc2ae')
plt.xticks(rotation='vertical')
st.pyplot(fig)
# Daily_Timeline
st.title("Daily Timeline")
daily_timelines = modify.daily_timeline(selected_user, df)
fig, ax = plt.subplots()
ax.plot(daily_timelines['Date_num'], daily_timelines['message'], color='black')
plt.xticks(rotation='vertical')
st.pyplot(fig)
# Activity map
st.title('Activity Map')
col1, col2 = st.columns(2)
with col1:
st.header("Most Busy Day")
busy_day = modify.weekly_activity_map(selected_user, df)
fig, ax = plt.subplots()
ax.bar(busy_day.index, busy_day.values, color='#c97c65')
plt.xticks(rotation='vertical')
st.pyplot(fig)
with col2:
st.header("Most Busy month")
busy_month = modify.monthly_activity_map(selected_user, df)
fig, ax = plt.subplots()
ax.bar(busy_month.index, busy_month.values, color='#98bf62')
plt.xticks(rotation='vertical')
st.pyplot(fig)
st.title("Weekly Activity Map")
user_heatmap = modify.activity_heatmap(selected_user, df)
fig, ax = plt.subplots()
ax = sns.heatmap(user_heatmap)
st.pyplot(fig)
if selected_user == 'Overall':
st.title('Most Active Users')
x, new_df = modify.most_active_users(df)
fig, ax = plt.subplots()
col1, col2 = st.columns(2)
with col1:
ax.bar(x.index, x.values, color='#575FE8')
plt.xticks(rotation='vertical')
plt.xlabel('Users')
plt.ylabel('No. of messages')
st.pyplot(fig)
with col2:
st.dataframe(new_df)
if selected_user == 'Overall':
st.title('Top-10 media contributor of Group')
x, new_df = modify.most_media_contributor(df)
fig, ax = plt.subplots()
col1, col2 = st.columns(2)
with col1:
ax.bar(x.index, x.values, color='#79a832')
plt.xticks(rotation='vertical')
plt.xlabel('Users')
plt.ylabel('No. of media')
st.pyplot(fig)
with col2:
st.dataframe(new_df)
st.title('WordCloud')
df_wc = modify.create_word(selected_user, df)
fig, ax = plt.subplots()
ax.imshow(df_wc)
st.pyplot(fig)
# most Common Words
mcw_df = modify.most_common_words(selected_user, df)
fig, ax = plt.subplots()
ax.barh(mcw_df[0], mcw_df[1], color='#C9EAB8')
plt.xticks(rotation='vertical')
st.title('Most Common Words')
st.pyplot(fig)
wpm = modify.words_per_message(selected_user, df)
st.title('Average Words per Message')
st.header(wpm)
emoji_df = modify.all_emoji(selected_user, df)
st.title("Emoji's Analysis")
col1, col2 = st.columns(2)
with col1:
if emoji_df.shape[0] == 0:
st.subheader("No emoji's used.")
else:
st.dataframe(emoji_df)
with col2:
if emoji_df.shape[0] != 0:
fig, ax = plt.subplots()
ax.pie(emoji_df[1].head(), labels=emoji_df[0].head(), autopct="%0.2f")
st.pyplot(fig)