justinahsu commited on
Commit
5ef472a
·
verified ·
1 Parent(s): e8ea050

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -116,25 +116,25 @@ def plot_confusion_matrix(y_true, y_pred, labels=("負面(0)", "正面(1)")):
116
  def use_sample_dataset():
117
  df = SAMPLE_DF.copy()
118
  msg = f"✅ 已載入內建示範資料,共 {len(df)} 筆。"
119
- return df, df, msg
120
 
121
  def append_example(df, new_text, new_label):
122
  """把一筆 (text, label) 追加到現有資料集"""
123
  if df is None or not isinstance(df, pd.DataFrame) or df.empty:
124
  df = SAMPLE_DF.copy() # 保險:尚未載入時以內建資料起始
125
  if not new_text or not str(new_text).strip():
126
- return df, df, "❌ 請先輸入文字。"
127
  try:
128
  y = int(new_label)
129
  if y not in (0, 1):
130
  raise ValueError
131
  except Exception:
132
- return df, df, "❌ 標籤須為 0 或 1。"
133
 
134
  new_row = pd.DataFrame([[str(new_text).strip(), y]], columns=["text", "label"])
135
  df2 = pd.concat([df, new_row], ignore_index=True)
136
  msg = f"✅ 已加入 1 筆,目前共 {len(df2)} 筆。"
137
- return df2, df2, msg
138
 
139
 
140
  # -------------------------
@@ -211,7 +211,7 @@ with gr.Blocks(title="情感分類小幫手(LogReg + 字 n-gram)", theme=gr.
211
  label="資料預覽(全部資料)",
212
  wrap=True,
213
  interactive=False,
214
- value=SAMPLE_DF
215
  )
216
 
217
  # 綁定事件
 
116
  def use_sample_dataset():
117
  df = SAMPLE_DF.copy()
118
  msg = f"✅ 已載入內建示範資料,共 {len(df)} 筆。"
119
+ return df, df.iloc[::-1], msg
120
 
121
  def append_example(df, new_text, new_label):
122
  """把一筆 (text, label) 追加到現有資料集"""
123
  if df is None or not isinstance(df, pd.DataFrame) or df.empty:
124
  df = SAMPLE_DF.copy() # 保險:尚未載入時以內建資料起始
125
  if not new_text or not str(new_text).strip():
126
+ return df, df.iloc[::-1], "❌ 請先輸入文字。"
127
  try:
128
  y = int(new_label)
129
  if y not in (0, 1):
130
  raise ValueError
131
  except Exception:
132
+ return df, df.iloc[::-1], "❌ 標籤須為 0 或 1。"
133
 
134
  new_row = pd.DataFrame([[str(new_text).strip(), y]], columns=["text", "label"])
135
  df2 = pd.concat([df, new_row], ignore_index=True)
136
  msg = f"✅ 已加入 1 筆,目前共 {len(df2)} 筆。"
137
+ return df2, df2.iloc[::-1],msg
138
 
139
 
140
  # -------------------------
 
211
  label="資料預覽(全部資料)",
212
  wrap=True,
213
  interactive=False,
214
+ value=SAMPLE_DF.iloc[::-1]
215
  )
216
 
217
  # 綁定事件