SurajJha21 commited on
Commit
b448d70
·
verified ·
1 Parent(s): 2aa76f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +138 -139
app.py CHANGED
@@ -1,139 +1,138 @@
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
-
109
- fig,ax = plt.subplots()
110
-
111
- ax.barh(most_common_df[0],most_common_df[1])
112
- plt.xticks(rotation='vertical')
113
-
114
- st.title('Most commmon words')
115
- st.pyplot(fig)
116
-
117
- # emoji analysis
118
- emoji_df = helper.emoji_helper(selected_user,df)
119
- st.title("Emoji Analysis")
120
-
121
- col1,col2 = st.columns(2)
122
-
123
- with col1:
124
- st.dataframe(emoji_df)
125
- with col2:
126
- fig,ax = plt.subplots()
127
- ax.pie(emoji_df[1].head(),labels=emoji_df[0].head(),autopct="%0.2f")
128
- st.pyplot(fig)
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
 
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
+
17
+ user_list.insert(0,"Overall")
18
+
19
+ selected_user = st.sidebar.selectbox("Show analysis wrt",user_list)
20
+
21
+ if st.sidebar.button("Show Analysis"):
22
+
23
+ # Stats Area
24
+ num_messages, words, num_media_messages, num_links = helper.fetch_stats(selected_user,df)
25
+ st.title("Top Statistics")
26
+ col1, col2, col3, col4 = st.columns(4)
27
+
28
+ with col1:
29
+ st.header("Total Messages")
30
+ st.title(num_messages)
31
+ with col2:
32
+ st.header("Total Words")
33
+ st.title(words)
34
+ with col3:
35
+ st.header("Media Shared")
36
+ st.title(num_media_messages)
37
+ with col4:
38
+ st.header("Links Shared")
39
+ st.title(num_links)
40
+
41
+ # monthly timeline
42
+ st.title("Monthly Timeline")
43
+ timeline = helper.monthly_timeline(selected_user,df)
44
+ fig,ax = plt.subplots()
45
+ ax.plot(timeline['time'], timeline['message'],color='green')
46
+ plt.xticks(rotation='vertical')
47
+ st.pyplot(fig)
48
+
49
+ # daily timeline
50
+ st.title("Daily Timeline")
51
+ daily_timeline = helper.daily_timeline(selected_user, df)
52
+ fig, ax = plt.subplots()
53
+ ax.plot(daily_timeline['only_date'], daily_timeline['message'], color='black')
54
+ plt.xticks(rotation='vertical')
55
+ st.pyplot(fig)
56
+
57
+ # activity map
58
+ st.title('Activity Map')
59
+ col1,col2 = st.columns(2)
60
+
61
+ with col1:
62
+ st.header("Most busy day")
63
+ busy_day = helper.week_activity_map(selected_user,df)
64
+ fig,ax = plt.subplots()
65
+ ax.bar(busy_day.index,busy_day.values,color='purple')
66
+ plt.xticks(rotation='vertical')
67
+ st.pyplot(fig)
68
+
69
+ with col2:
70
+ st.header("Most busy month")
71
+ busy_month = helper.month_activity_map(selected_user, df)
72
+ fig, ax = plt.subplots()
73
+ ax.bar(busy_month.index, busy_month.values,color='orange')
74
+ plt.xticks(rotation='vertical')
75
+ st.pyplot(fig)
76
+
77
+ st.title("Weekly Activity Map")
78
+ user_heatmap = helper.activity_heatmap(selected_user,df)
79
+ fig,ax = plt.subplots()
80
+ ax = sns.heatmap(user_heatmap)
81
+ st.pyplot(fig)
82
+
83
+ # finding the busiest users in the group(Group level)
84
+ if selected_user == 'Overall':
85
+ st.title('Most Busy Users')
86
+ x,new_df = helper.most_busy_users(df)
87
+ fig, ax = plt.subplots()
88
+
89
+ col1, col2 = st.columns(2)
90
+
91
+ with col1:
92
+ ax.bar(x.index, x.values,color='red')
93
+ plt.xticks(rotation='vertical')
94
+ st.pyplot(fig)
95
+ with col2:
96
+ st.dataframe(new_df)
97
+
98
+ # WordCloud
99
+ st.title("Wordcloud")
100
+ df_wc = helper.create_wordcloud(selected_user,df)
101
+ fig,ax = plt.subplots()
102
+ ax.imshow(df_wc)
103
+ st.pyplot(fig)
104
+
105
+ # most common words
106
+ most_common_df = helper.most_common_words(selected_user,df)
107
+
108
+ fig,ax = plt.subplots()
109
+
110
+ ax.barh(most_common_df[0],most_common_df[1])
111
+ plt.xticks(rotation='vertical')
112
+
113
+ st.title('Most commmon words')
114
+ st.pyplot(fig)
115
+
116
+ # emoji analysis
117
+ emoji_df = helper.emoji_helper(selected_user,df)
118
+ st.title("Emoji Analysis")
119
+
120
+ col1,col2 = st.columns(2)
121
+
122
+ with col1:
123
+ st.dataframe(emoji_df)
124
+ with col2:
125
+ fig,ax = plt.subplots()
126
+ ax.pie(emoji_df[1].head(),labels=emoji_df[0].head(),autopct="%0.2f")
127
+ st.pyplot(fig)
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+