Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -248,20 +248,13 @@ def process_input(text_input, file):
|
|
| 248 |
# raise gr.Error(f"Lỗi khi đọc tệp: {str(e)}")
|
| 249 |
|
| 250 |
# Đọc file CSV hoặc TXT
|
| 251 |
-
|
| 252 |
-
if isinstance(file,
|
| 253 |
-
# thử đọc CSV
|
| 254 |
-
try:
|
| 255 |
-
df = pd.read_csv(io.BytesIO(file), header=None, names=["Comment"], sep=',', quotechar='"', engine='python', skipinitialspace=True, encoding="utf-8")
|
| 256 |
-
except Exception:
|
| 257 |
-
# fallback: đọc như text, rồi tách câu
|
| 258 |
-
content = io.BytesIO(file).read().decode('utf-8', errors='ignore')
|
| 259 |
-
parts = re.split(r'[.?!]\s*|\n+', content)
|
| 260 |
-
comments = [p.strip() for p in parts if p.strip()]
|
| 261 |
-
elif isinstance(file, str):
|
| 262 |
# file path
|
| 263 |
if file.lower().endswith('.csv'):
|
| 264 |
-
|
|
|
|
|
|
|
| 265 |
else:
|
| 266 |
content = open(file, 'r', encoding='utf-8').read()
|
| 267 |
parts = re.split(r'[.?!]\s*|\n+', content)
|
|
@@ -269,13 +262,6 @@ def process_input(text_input, file):
|
|
| 269 |
else:
|
| 270 |
raise gr.Error("Định dạng tệp không được hỗ trợ.")
|
| 271 |
|
| 272 |
-
# Nếu đọc được CSV, chuyển mỗi dòng thành comment nguyên bản
|
| 273 |
-
if df is not None:
|
| 274 |
-
df = df.dropna(subset=["Comment"])
|
| 275 |
-
if df["Comment"].empty:
|
| 276 |
-
raise gr.Error("File CSV không chứa comment hợp lệ.")
|
| 277 |
-
comments = df["Comment"].astype(str).tolist()
|
| 278 |
-
|
| 279 |
if len(comments) == 0:
|
| 280 |
raise gr.Error("Vui lòng nhập ít nhất một bình luận hoặc tải lên tệp chứa bình luận.")
|
| 281 |
|
|
|
|
| 248 |
# raise gr.Error(f"Lỗi khi đọc tệp: {str(e)}")
|
| 249 |
|
| 250 |
# Đọc file CSV hoặc TXT
|
| 251 |
+
|
| 252 |
+
if isinstance(file, str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
# file path
|
| 254 |
if file.lower().endswith('.csv'):
|
| 255 |
+
content = open(file, 'r', encoding='utf-8', errors='ignore').read()
|
| 256 |
+
lines = content.splitlines()
|
| 257 |
+
comments = [line.strip() for line in lines if line.strip()]
|
| 258 |
else:
|
| 259 |
content = open(file, 'r', encoding='utf-8').read()
|
| 260 |
parts = re.split(r'[.?!]\s*|\n+', content)
|
|
|
|
| 262 |
else:
|
| 263 |
raise gr.Error("Định dạng tệp không được hỗ trợ.")
|
| 264 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
if len(comments) == 0:
|
| 266 |
raise gr.Error("Vui lòng nhập ít nhất một bình luận hoặc tải lên tệp chứa bình luận.")
|
| 267 |
|