william1324 commited on
Commit
578a287
·
verified ·
1 Parent(s): c54a782

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -16,12 +16,16 @@ sentiment_model = pipeline(
16
 
17
  # 2️⃣ 主處理流程
18
  def full_pipeline(file, num_clusters):
19
- df = pd.read_csv(file)
20
-
21
- if "text" not in df.columns:
22
- return "❌ 錯誤:CSV 檔案需包含 text 欄位"
23
- if "timestamp" not in df.columns:
24
- return "❌ 錯誤:CSV 檔案需包含 timestamp 欄位(例如新聞時間)"
 
 
 
 
25
 
26
  # 向量化並聚類
27
  texts = df["text"].astype(str).tolist()
 
16
 
17
  # 2️⃣ 主處理流程
18
  def full_pipeline(file, num_clusters):
19
+ try:
20
+ df = pd.read_csv(file, encoding="utf-8")
21
+ except UnicodeDecodeError:
22
+ try:
23
+ df = pd.read_csv(file, encoding="utf-8-sig")
24
+ except UnicodeDecodeError:
25
+ try:
26
+ df = pd.read_csv(file, encoding="big5")
27
+ except Exception as e:
28
+ return f"❌ 無法讀取 CSV 檔案,錯誤原因:{str(e)}"
29
 
30
  # 向量化並聚類
31
  texts = df["text"].astype(str).tolist()