Spaces:
Running
Running
Phase 2:修復 Bug2——格式驗證失敗後可重新上傳
Browse files- run_format_check 失敗分支改為只清除驗證失敗的檔案,保留已通過的
- on_upload_confirm 失敗分支的 upload_row 改回 visible=True(原本寫死
False 導致使用者被要求重傳卻沒有上傳欄位可用)
- handle_uploaded_files 改成依檔名合併新舊上傳清單而非整批覆蓋,
否則前兩項修復會在下一次上傳時被覆蓋掉、無法真正只補傳壞檔
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- app_agent.py +10 -3
app_agent.py
CHANGED
|
@@ -1468,7 +1468,13 @@ def handle_uploaded_files(files, state: dict):
|
|
| 1468 |
shutil.copy2(str(src), str(dst))
|
| 1469 |
saved_paths.append(str(dst))
|
| 1470 |
|
| 1471 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1472 |
state["state"] = "FORMAT_CHECK"
|
| 1473 |
|
| 1474 |
# 工作程序 Agent 說明開始檢查
|
|
@@ -1530,7 +1536,8 @@ def run_format_check(state: dict):
|
|
| 1530 |
"請使用 [ckip_segmentation_sumin](https://github.com/suhsiung/ckip_segmentation_sumin) "
|
| 1531 |
"工具完成斷詞後,重新上傳檔案。"
|
| 1532 |
)
|
| 1533 |
-
|
|
|
|
| 1534 |
state["state"] = "UPLOAD_WAIT"
|
| 1535 |
return msg, state, True
|
| 1536 |
|
|
@@ -3227,7 +3234,7 @@ def create_app():
|
|
| 3227 |
if has_errors:
|
| 3228 |
log_history = _log_append(log_history, "⚠️ STEP 4 格式不符,請重新上傳")
|
| 3229 |
state["current_step"] = 3
|
| 3230 |
-
yield chat_history, log_history, state, gr.update(visible=
|
| 3231 |
return
|
| 3232 |
|
| 3233 |
state["done_steps"] = list(set(state.get("done_steps", []) + [4]))
|
|
|
|
| 1468 |
shutil.copy2(str(src), str(dst))
|
| 1469 |
saved_paths.append(str(dst))
|
| 1470 |
|
| 1471 |
+
# 格式驗證失敗時只會清掉不合格的檔案(見 run_format_check),這裡補傳
|
| 1472 |
+
# 要跟先前保留下來、已通過驗證的檔案合併,而不是整批覆蓋掉,使用者才
|
| 1473 |
+
# 只需要補傳有問題的那幾個檔案,同名檔案則視為修正版本直接取代舊的
|
| 1474 |
+
existing = state.get("uploaded_files", [])
|
| 1475 |
+
new_names = {Path(p).name for p in saved_paths}
|
| 1476 |
+
merged_paths = [p for p in existing if Path(p).name not in new_names] + saved_paths
|
| 1477 |
+
state["uploaded_files"] = merged_paths
|
| 1478 |
state["state"] = "FORMAT_CHECK"
|
| 1479 |
|
| 1480 |
# 工作程序 Agent 說明開始檢查
|
|
|
|
| 1536 |
"請使用 [ckip_segmentation_sumin](https://github.com/suhsiung/ckip_segmentation_sumin) "
|
| 1537 |
"工具完成斷詞後,重新上傳檔案。"
|
| 1538 |
)
|
| 1539 |
+
failed_names = set(failed.keys())
|
| 1540 |
+
state["uploaded_files"] = [fp for fp in state["uploaded_files"] if Path(fp).name not in failed_names]
|
| 1541 |
state["state"] = "UPLOAD_WAIT"
|
| 1542 |
return msg, state, True
|
| 1543 |
|
|
|
|
| 3234 |
if has_errors:
|
| 3235 |
log_history = _log_append(log_history, "⚠️ STEP 4 格式不符,請重新上傳")
|
| 3236 |
state["current_step"] = 3
|
| 3237 |
+
yield chat_history, log_history, state, gr.update(visible=True), _todo_update(state)
|
| 3238 |
return
|
| 3239 |
|
| 3240 |
state["done_steps"] = list(set(state.get("done_steps", []) + [4]))
|