Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,16 +9,25 @@ st.sidebar.title("Whatsapp Chat Analyzer")
|
|
9 |
uploaded_file = st.sidebar.file_uploader("Choose a file")
|
10 |
if uploaded_file is not None:
|
11 |
bytes_data = uploaded_file.read()
|
12 |
-
|
13 |
-
# Detect encoding
|
14 |
result = chardet.detect(bytes_data)
|
15 |
encoding = result['encoding']
|
16 |
-
|
17 |
-
#
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
df = preprocessor.preprocess(data)
|
20 |
|
21 |
-
#
|
22 |
user_list = df['user'].unique().tolist()
|
23 |
user_list.remove('group_notification')
|
24 |
user_list.sort()
|
|
|
9 |
uploaded_file = st.sidebar.file_uploader("Choose a file")
|
10 |
if uploaded_file is not None:
|
11 |
bytes_data = uploaded_file.read()
|
12 |
+
|
13 |
+
# Detect the encoding
|
14 |
result = chardet.detect(bytes_data)
|
15 |
encoding = result['encoding']
|
16 |
+
|
17 |
+
# Fallback to utf-8 if encoding is None
|
18 |
+
if encoding is None:
|
19 |
+
encoding = 'utf-8' # or 'latin1' if utf-8 fails
|
20 |
+
|
21 |
+
# Decode with the detected or fallback encoding
|
22 |
+
try:
|
23 |
+
data = bytes_data.decode(encoding)
|
24 |
+
except UnicodeDecodeError:
|
25 |
+
# If utf-8 decoding fails, fallback to latin1
|
26 |
+
data = bytes_data.decode('latin1')
|
27 |
+
|
28 |
df = preprocessor.preprocess(data)
|
29 |
|
30 |
+
# Fetch unique users
|
31 |
user_list = df['user'].unique().tolist()
|
32 |
user_list.remove('group_notification')
|
33 |
user_list.sort()
|