Spaces:
Sleeping
Sleeping
上傳機制改回拖曳/點擊上傳卡片,對話輸入框回歸純展示
Browse files千卉實測 Phase 8-A 後回頭調整:業主原本設計是拖曳上傳卡片,且對話輸入框
目前沒有其他打字用途,決定上傳正式入口改回 upload_row(Phase 7 保留的舊
元件,處理邏輯完全沒動,只是把可見性開關從 chat_upload_col 換回這裡)。
upload_hint_md(格式要求文字)跟著搬進 upload_row。
chat_upload(MultimodalTextbox)改成永久可見的純展示輸入框,拿掉
sources=["upload"]避免顯示沒有作用的附加檔案按鈕,placeholder 改為
「對話輸入框(功能開發中)」;chat_upload.submit() 的 wiring 停用(函式
定義保留,之後對話框有真正用途時可直接接回去)。
新增 .upload-zone-plain CSS class,刻意用低視覺重量的樣式跟 .upload-zone
的醒目卡片拉開差異,避免使用者誤以為對話框也是可操作的上傳入口。
已用 Playwright 驗證完整流程:拖曳卡片上傳 A_01.txt+B_01.txt →格式驗證
通過→Metadata表單正確顯示 A/B 兩組;開始新分析可正確清空 upload_row/
file_input 並返回首頁。
- app_agent.py +42 -46
app_agent.py
CHANGED
|
@@ -2382,6 +2382,17 @@ div[role="log"][aria-label="chatbot conversation"],
|
|
| 2382 |
.upload-zone:hover, .upload-zone:focus-within {
|
| 2383 |
border-color: rgba(var(--c-accent-rgb),.6) !important;
|
| 2384 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2385 |
/* chat-col 是 gap:0 的 flex 欄,上傳卡片搬到「對話視窗+技術執行紀錄」
|
| 2386 |
這組下方後,要用明顯留白跟上面那組分開,不能只靠卡片自己 .6rem 的
|
| 2387 |
預設頂距(那個距離是設計給同張卡片內部元件用的,太窄) */
|
|
@@ -2970,18 +2981,19 @@ def create_app():
|
|
| 2970 |
elem_id="exec_log",
|
| 2971 |
elem_classes=["exec-log"],
|
| 2972 |
)
|
| 2973 |
-
# Phase
|
| 2974 |
-
#
|
| 2975 |
-
# 對話
|
| 2976 |
-
#
|
| 2977 |
-
#
|
| 2978 |
-
#
|
| 2979 |
-
|
| 2980 |
-
|
|
|
|
| 2981 |
chat_upload = gr.MultimodalTextbox(
|
| 2982 |
-
file_types=[".txt"],
|
| 2983 |
-
sources=[
|
| 2984 |
-
placeholder="
|
| 2985 |
show_label=False,
|
| 2986 |
)
|
| 2987 |
|
|
@@ -2996,11 +3008,12 @@ def create_app():
|
|
| 2996 |
with gr.Column(elem_classes=["scenario-buttons"]) as scenario_btn_col:
|
| 2997 |
pass
|
| 2998 |
|
| 2999 |
-
# Phase
|
| 3000 |
-
# 設
|
| 3001 |
-
#
|
| 3002 |
-
#
|
| 3003 |
with gr.Column(visible=False, elem_id="upload_zone", elem_classes=["upload-zone"]) as upload_row:
|
|
|
|
| 3004 |
file_input = gr.File(
|
| 3005 |
label="上傳已斷詞文本(.txt,可多選)",
|
| 3006 |
file_types=[".txt"], file_count="multiple",
|
|
@@ -3359,7 +3372,7 @@ def create_app():
|
|
| 3359 |
|
| 3360 |
demo.load(
|
| 3361 |
fn=on_load_init,
|
| 3362 |
-
outputs=[chatbot, exec_log, session_state,
|
| 3363 |
).then(
|
| 3364 |
fn=on_load_ready,
|
| 3365 |
inputs=[chatbot, exec_log, session_state],
|
|
@@ -3448,7 +3461,7 @@ def create_app():
|
|
| 3448 |
_sc_btn.click(
|
| 3449 |
fn=functools.partial(on_scenario_pick, _sc_num),
|
| 3450 |
inputs=[chatbot, exec_log, session_state],
|
| 3451 |
-
outputs=[chatbot, exec_log, session_state,
|
| 3452 |
upload_hint_md, homepage_col, workspace_row],
|
| 3453 |
).then(
|
| 3454 |
fn=_populate_tabs,
|
|
@@ -3474,8 +3487,8 @@ def create_app():
|
|
| 3474 |
state, # session_state
|
| 3475 |
gr.update(value=_build_header_html()), # app_header_html
|
| 3476 |
gr.update(visible=True), # scenario_btn_col(Bug1 關鍵一行)
|
| 3477 |
-
gr.update(visible=False), #
|
| 3478 |
-
gr.update(value=None), # chat_upload(
|
| 3479 |
gr.update(visible=False), # metadata_row
|
| 3480 |
gr.update(visible=False), # tab2 語言指標分析
|
| 3481 |
gr.update(visible=False), # tab3 統計比較分析
|
|
@@ -3484,6 +3497,7 @@ def create_app():
|
|
| 3484 |
_accordion_update(state, new_log), # exec_log_accordion(收合並更新摘要文字)
|
| 3485 |
gr.update(visible=True), # homepage_col(Phase 8:重新開始=回到首頁選情境)
|
| 3486 |
gr.update(visible=False), # workspace_row
|
|
|
|
| 3487 |
)
|
| 3488 |
|
| 3489 |
reset_btn.click(fn=lambda: gr.update(visible=True), outputs=[reset_confirm_row])
|
|
@@ -3491,8 +3505,8 @@ def create_app():
|
|
| 3491 |
reset_confirm_btn.click(
|
| 3492 |
fn=on_reset_confirm,
|
| 3493 |
outputs=[chatbot, exec_log, session_state, app_header_html,
|
| 3494 |
-
scenario_btn_col,
|
| 3495 |
-
reset_confirm_row, exec_log_accordion, homepage_col, workspace_row],
|
| 3496 |
)
|
| 3497 |
|
| 3498 |
# ── 檔案上傳確認(streaming generator)──────────────────────────────
|
|
@@ -3637,35 +3651,17 @@ def create_app():
|
|
| 3637 |
outputs=[upload_row, file_input],
|
| 3638 |
)
|
| 3639 |
|
| 3640 |
-
# ── Phase 7
|
| 3641 |
-
#
|
| 3642 |
-
#
|
| 3643 |
-
#
|
| 3644 |
-
#
|
|
|
|
|
|
|
| 3645 |
def on_chat_upload_submit(mm_value, chat_history, log_history, state):
|
| 3646 |
files = (mm_value or {}).get("files", [])
|
| 3647 |
yield from on_upload_confirm(files, chat_history, log_history, state)
|
| 3648 |
|
| 3649 |
-
def _lock_chat_upload():
|
| 3650 |
-
return gr.update(interactive=False)
|
| 3651 |
-
|
| 3652 |
-
def _unlock_chat_upload():
|
| 3653 |
-
return gr.update(interactive=True, value=None)
|
| 3654 |
-
|
| 3655 |
-
chat_upload.submit(
|
| 3656 |
-
fn=_lock_chat_upload, inputs=None, outputs=[chat_upload],
|
| 3657 |
-
).then(
|
| 3658 |
-
fn=on_chat_upload_submit,
|
| 3659 |
-
inputs=[chat_upload, chatbot, exec_log, session_state],
|
| 3660 |
-
outputs=[chatbot, exec_log, session_state, chat_upload_col, app_header_html],
|
| 3661 |
-
).then(
|
| 3662 |
-
fn=_unlock_chat_upload, inputs=None, outputs=[chat_upload],
|
| 3663 |
-
).then(
|
| 3664 |
-
fn=_show_metadata_form,
|
| 3665 |
-
inputs=[session_state],
|
| 3666 |
-
outputs=[metadata_row, meta_group_df, meta_indiv_df, meta_compare_group],
|
| 3667 |
-
)
|
| 3668 |
-
|
| 3669 |
_ANALYSIS_START_MSG = (
|
| 3670 |
"已收到,開始計算語言指標與統計分析,這個步驟可能需要數分鐘,請耐心等候……\n"
|
| 3671 |
"(可於下方「技術執行紀錄」查看執行進度)"
|
|
|
|
| 2382 |
.upload-zone:hover, .upload-zone:focus-within {
|
| 2383 |
border-color: rgba(var(--c-accent-rgb),.6) !important;
|
| 2384 |
}
|
| 2385 |
+
/* 對話輸入框(Phase 8:不再負責上傳,改回純展示用的常駐輸入框):
|
| 2386 |
+
刻意跟上面「醒目卡片」風格的 .upload-zone 拉開視覺重量差異,
|
| 2387 |
+
不用強調色框線/陰影/彈出動畫,也不掛 ::before 的標題文字,
|
| 2388 |
+
避免使用者誤以為這裡也是一個可操作的上傳入口 */
|
| 2389 |
+
.upload-zone-plain {
|
| 2390 |
+
border: 1px solid var(--c-border) !important;
|
| 2391 |
+
border-radius: 12px !important;
|
| 2392 |
+
padding: .3rem .5rem !important;
|
| 2393 |
+
margin: .6rem 0 0 !important;
|
| 2394 |
+
width: 100% !important;
|
| 2395 |
+
}
|
| 2396 |
/* chat-col 是 gap:0 的 flex 欄,上傳卡片搬到「對話視窗+技術執行紀錄」
|
| 2397 |
這組下方後,要用明顯留白跟上面那組分開,不能只靠卡片自己 .6rem 的
|
| 2398 |
預設頂距(那個距離是設計給同張卡片內部元件用的,太窄) */
|
|
|
|
| 2981 |
elem_id="exec_log",
|
| 2982 |
elem_classes=["exec-log"],
|
| 2983 |
)
|
| 2984 |
+
# Phase 8(千卉實測後回頭調整):對話輸入框改回「常駐顯示、
|
| 2985 |
+
# 不負責上傳」——業主原本設計就是用拖曳/點擊上傳的卡片
|
| 2986 |
+
# (見下方 upload_row),對話框目前也沒有其他打字用途
|
| 2987 |
+
# (全站掃過沒有任何地方會解析使用者自由輸入文字),暫時
|
| 2988 |
+
# 只留著當畫面元素,不接 sources=["upload"],避免顯示
|
| 2989 |
+
# 附加檔案的迴紋針卻沒有作用。chat_upload.submit() 的
|
| 2990 |
+
# wiring 已停用(見下方 on_chat_upload_submit 註解),
|
| 2991 |
+
# 函式保留、之後如果對話框有真正用途要復活直接接回去即可。
|
| 2992 |
+
with gr.Column(visible=True, elem_id="chat_upload_zone", elem_classes=["upload-zone-plain"]) as chat_upload_col:
|
| 2993 |
chat_upload = gr.MultimodalTextbox(
|
| 2994 |
+
file_types=[".txt"],
|
| 2995 |
+
sources=[],
|
| 2996 |
+
placeholder="對話輸入框(功能開發中)",
|
| 2997 |
show_label=False,
|
| 2998 |
)
|
| 2999 |
|
|
|
|
| 3008 |
with gr.Column(elem_classes=["scenario-buttons"]) as scenario_btn_col:
|
| 3009 |
pass
|
| 3010 |
|
| 3011 |
+
# Phase 8(千卉實測後回頭調整):這張卡片改回正式使用中的
|
| 3012 |
+
# 上傳入口(拖曳/點擊上傳),符合業主原本設計;Phase 7
|
| 3013 |
+
# 曾經把它永久隱藏、改用對話框上傳,這次反過來。程式邏輯
|
| 3014 |
+
# 完全沒動,只是把可見性開關從 chat_upload_col 換回這裡。
|
| 3015 |
with gr.Column(visible=False, elem_id="upload_zone", elem_classes=["upload-zone"]) as upload_row:
|
| 3016 |
+
upload_hint_md = gr.Markdown(value="", elem_classes=["upload-hint"])
|
| 3017 |
file_input = gr.File(
|
| 3018 |
label="上傳已斷詞文本(.txt,可多選)",
|
| 3019 |
file_types=[".txt"], file_count="multiple",
|
|
|
|
| 3372 |
|
| 3373 |
demo.load(
|
| 3374 |
fn=on_load_init,
|
| 3375 |
+
outputs=[chatbot, exec_log, session_state, upload_row, app_header_html],
|
| 3376 |
).then(
|
| 3377 |
fn=on_load_ready,
|
| 3378 |
inputs=[chatbot, exec_log, session_state],
|
|
|
|
| 3461 |
_sc_btn.click(
|
| 3462 |
fn=functools.partial(on_scenario_pick, _sc_num),
|
| 3463 |
inputs=[chatbot, exec_log, session_state],
|
| 3464 |
+
outputs=[chatbot, exec_log, session_state, upload_row, app_header_html, scenario_btn_col,
|
| 3465 |
upload_hint_md, homepage_col, workspace_row],
|
| 3466 |
).then(
|
| 3467 |
fn=_populate_tabs,
|
|
|
|
| 3487 |
state, # session_state
|
| 3488 |
gr.update(value=_build_header_html()), # app_header_html
|
| 3489 |
gr.update(visible=True), # scenario_btn_col(Bug1 關鍵一行)
|
| 3490 |
+
gr.update(visible=False), # upload_row(Phase 8:正式上傳入口改這張卡片)
|
| 3491 |
+
gr.update(value=None), # chat_upload(對話框仍清空一下,雖然目前不接上傳)
|
| 3492 |
gr.update(visible=False), # metadata_row
|
| 3493 |
gr.update(visible=False), # tab2 語言指標分析
|
| 3494 |
gr.update(visible=False), # tab3 統計比較分析
|
|
|
|
| 3497 |
_accordion_update(state, new_log), # exec_log_accordion(收合並更新摘要文字)
|
| 3498 |
gr.update(visible=True), # homepage_col(Phase 8:重新開始=回到首頁選情境)
|
| 3499 |
gr.update(visible=False), # workspace_row
|
| 3500 |
+
gr.update(value=None), # file_input(Phase 8:upload_row 變正式入口後一併清空)
|
| 3501 |
)
|
| 3502 |
|
| 3503 |
reset_btn.click(fn=lambda: gr.update(visible=True), outputs=[reset_confirm_row])
|
|
|
|
| 3505 |
reset_confirm_btn.click(
|
| 3506 |
fn=on_reset_confirm,
|
| 3507 |
outputs=[chatbot, exec_log, session_state, app_header_html,
|
| 3508 |
+
scenario_btn_col, upload_row, chat_upload, metadata_row, tab2, tab3, tab6,
|
| 3509 |
+
reset_confirm_row, exec_log_accordion, homepage_col, workspace_row, file_input],
|
| 3510 |
)
|
| 3511 |
|
| 3512 |
# ── 檔案上傳確認(streaming generator)──────────────────────────────
|
|
|
|
| 3651 |
outputs=[upload_row, file_input],
|
| 3652 |
)
|
| 3653 |
|
| 3654 |
+
# ── Phase 7 產物,Phase 8 停用 ──────────────────────────────────────
|
| 3655 |
+
# on_chat_upload_submit 原本是 MultimodalTextbox 送出時的薄轉接生成器
|
| 3656 |
+
# (拆 {"text":...,"files":[...]} 丟給 on_upload_confirm)。千卉實測
|
| 3657 |
+
# 現行版本後,決定上傳改回正式走 upload_row 拖曳卡片(業主原本設計),
|
| 3658 |
+
# 對話輸入框回歸純展示、不接上傳,所以這裡不再呼叫 chat_upload.submit()
|
| 3659 |
+
# 綁定;函式本體保留,之後對話框如果有真正用途要接上傳,直接把下面
|
| 3660 |
+
# 這段 wiring 恢復即可,邏輯不用重寫。
|
| 3661 |
def on_chat_upload_submit(mm_value, chat_history, log_history, state):
|
| 3662 |
files = (mm_value or {}).get("files", [])
|
| 3663 |
yield from on_upload_confirm(files, chat_history, log_history, state)
|
| 3664 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3665 |
_ANALYSIS_START_MSG = (
|
| 3666 |
"已收到,開始計算語言指標與統計分析,這個步驟可能需要數分鐘,請耐心等候……\n"
|
| 3667 |
"(可於下方「技術執行紀錄」查看執行進度)"
|