Di12 commited on
Commit
402a262
·
1 Parent(s): 04ae991

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -225,12 +225,14 @@ def process_input(text_input, file):
225
  file_name = file.name
226
 
227
  if file_name.endswith('.txt'):
228
- file.seek(0) # Đảm bảo con trỏ file ở đầu
229
- content = file.read()
230
- if isinstance(content, bytes):
231
- content = content.decode('utf-8') # Giải mã nếu cần
232
- comments += [line.strip() for line in content.splitlines() if line.strip()]
233
-
 
 
234
  elif file_name.endswith('.csv'):
235
  df = pd.read_csv(file)
236
  comments += df.iloc[:, 0].dropna().astype(str).tolist()
 
225
  file_name = file.name
226
 
227
  if file_name.endswith('.txt'):
228
+ try:
229
+ content = file.read()
230
+ if isinstance(content, bytes):
231
+ content = content.decode('utf-8')
232
+ except UnicodeDecodeError:
233
+ content = file.read().decode('utf-8-sig')
234
+ comments += [line.strip() for line in content.splitlines() if line.strip()]
235
+
236
  elif file_name.endswith('.csv'):
237
  df = pd.read_csv(file)
238
  comments += df.iloc[:, 0].dropna().astype(str).tolist()