-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
165 lines (120 loc) · 6.1 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
# Libraries Imported
import streamlit as st
import time
import io
import csv
import sys
import os
from custom_modules import func_use_extract_data as func
from custom_modules import func_analysis as analysis
st.set_option('deprecation.showfileUploaderEncoding', False)
st.title("WhatsApp Chat Analyzer 😃")
st.markdown(
"This app is use to analyze your WhatsApp Chat using the exported text file 📁.")
st.sidebar.image("./assets/images/banner.jpeg",use_column_width=True)
st.sidebar.title("Analyze:")
st.sidebar.markdown(
"This app is use to analyze your WhatsApp Chat using the exported text file 📁.")
st.sidebar.markdown('**How to export chat text file?**')
st.sidebar.text('Follow the steps 👇:')
st.sidebar.text('1) Open the individual or group chat.')
st.sidebar.text('2) Tap options > More > Export chat.')
st.sidebar.text('3) Choose export without media.')
st.sidebar.markdown('*You are all set to go 😃*.')
st.sidebar.markdown('**Upload your chat text file:**')
date_format = st.sidebar.selectbox('Please select the date format of your file:',
('mm/dd/yyyy', 'mm/dd/yy',
'dd/mm/yyyy', 'dd/mm/yy',
'yyyy/mm/dd', 'yy/mm/dd'), key='0')
filename = st.sidebar.file_uploader("", type=["txt"])
st.sidebar.markdown("**Don't worry your data is not stored!**")
st.sidebar.markdown("**feel free to use 😊.**")
if filename is not None:
@st.cache_data
def load_data(date_format=date_format):
file_contents = []
if filename is not None:
content = filename.read().decode('utf-8')
with io.StringIO(content) as f:
reader = csv.reader(f, delimiter='\n')
for each in reader:
if len(each) > 0:
file_contents.append(each[0])
else:
file_contents.append('')
else:
st.error("Please upload the WhatsApp chat dataset!")
return func.read_data(file_contents, date_format)
try:
data = load_data()
if data.empty:
st.error("Please upload the WhatsApp chat dataset!")
if st.sidebar.checkbox("Show raw data", True):
st.write(data)
st.sidebar.markdown("### To Analyze select")
names = analysis.authors_name(data)
names.append('All')
member = st.sidebar.selectbox("Member Name", names, key='1')
if not st.sidebar.checkbox("Hide", True):
try:
if member == "All":
st.markdown(
"### Analyze {} members together:".format(member))
st.markdown(analysis.stats(data), unsafe_allow_html=True)
st.write("**Top 10 frequent use emoji:**")
emoji = analysis.popular_emoji(data)
for e in emoji[:10]:
st.markdown('**{}** : {}'.format(e[0], e[1]))
st.write('**Visualize emoji distribution in pie chart:**')
st.plotly_chart(analysis.visualize_emoji(data))
st.markdown('**Word Cloud:**')
st.text(
"This will show the cloud of words which you use, larger the word size most often you use.")
st.pyplot(analysis.word_cloud(data))
time.sleep(0.2)
st.write('**Most active date:**')
st.pyplot(analysis.active_date(data))
time.sleep(0.2)
st.write('**Most active time for chat:**')
st.pyplot(analysis.active_time(data))
st.write(
'**Day wise distribution of messages for {}:**'.format(member))
st.plotly_chart(analysis.day_wise_count(data))
st.write('**Number of messages as times move on**')
st.plotly_chart(analysis.num_messages(data))
st.write('**Chatter:**')
st.plotly_chart(analysis.chatter(data))
else:
member_data = data[data['Author'] == member]
st.markdown("### Analyze {} chat:".format(member))
st.markdown(analysis.stats(member_data),
unsafe_allow_html=False)
st.write("**Top 10 Popular emoji:**")
emoji = analysis.popular_emoji(member_data)
for e in emoji[:10]:
st.markdown('**{}** : {}'.format(e[0], e[1]))
st.write('**Visualize emoji distribution in pie chart:**')
st.plotly_chart(analysis.visualize_emoji(member_data))
st.markdown('**Word Cloud:**')
st.text(
"This will show the cloud of words which you use, larger the word size most often you use.")
st.pyplot(analysis.word_cloud(member_data))
time.sleep(0.2)
st.write(
'**Most active date of {} on WhatsApp:**'.format(member))
st.pyplot(analysis.active_date(member_data))
time.sleep(0.2)
st.write('**When {} is active for chat:**'.format(member))
st.pyplot(analysis.active_time(member_data))
st.write(
'**Day wise distribution of messages for {}:**'.format(member))
st.plotly_chart(analysis.day_wise_count(member_data))
st.write('**Number of messages as times move on**')
st.plotly_chart(analysis.num_messages(member_data))
except:
e = sys.exc_info()[0]
st.error("It seems that something is wrong! Try Again. Error Type: {}".format(
e.__name__))
except:
e = sys.exc_info()
st.error("Something is wrong in loading the data! Please select the correct date format or Try again. Error Type: {}.\n \n **For Detail Error Info: {}**".format(e[0].__name__, e[1]))