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