Spaces:
Sleeping
Phase 8-D:左側結果導覽 + 運算中提示
Browse files- 新增 result_nav_col(回到上傳/表單、語言指標分析、統計比較分析+4個
子按鈕、LLM輔助分析),情境選定後顯示。這幾顆按鈕不掛 Python
.click(),純粹是捲動到 Canvas 對應區塊+切換巢狀子分頁的畫面操作,
改用跟首頁情境卡片同一套 _APP_HEAD_SCRIPT JS 注入手法處理,不用走
Gradio queue 來回
- 新增運算中提示:單一 gr.HTML(elem_id="computing_zone") 元件,空字串
即不顯示,判斷邏輯比照既有 _accordion_update(current_step 在
5/6/7 之間),接在 _run_computation/on_metadata_confirm/
on_metadata_skip 既有呼叫點旁邊
- 圖示(Heroicons SVG)與 nav-col 下載捷徑延後到下一輪視覺打磨,這次
先用純文字標籤把功能做對
修復兩個真實 bug:
1. JS 綁定時機:result_nav_col 建構時 visible=False,不能像
bindScenarioCards() 用 setTimeout 固定時間點抓按鈕(同 8-A 的
sc_btn_1..4 踩過的坑),改用 document 事件代理,不管元件何時掛載
都能正確處理
2. 全站沿用的 .tabs > .tab-nav 選擇器在目前這版 Gradio 完全不會命中
(實際 DOM 是 .tabs > .tab-wrapper > .tab-container:not(.visually-hidden),
用 devtools 逐層排查後才發現),導致巢狀子分頁的 JS 切換與字級 CSS
都失效。已修 #canvas_stat 相關的巢狀分頁部分;全站分頁列的 sticky/
背景/hover/選中底色那組(可能從寫下來就是死規則)留給下一輪視覺
打磨處理,已加註解標記
已用 Playwright 驗證:情境1完整跑一次分析,運算中提示 3 階段文字依序
顯示並在完成後清空;點擊監督式學習子按鈕同時完成捲動+切換巢狀分頁;
開始新分析 reset 後正確清空無殘留。
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- app_agent.py +230 -26
|
@@ -2037,7 +2037,18 @@ _CUSTOM_CSS = """
|
|
| 2037 |
/* 注意:這裡原本用 backdrop-filter 做毛玻璃效果,搭配 position: sticky
|
| 2038 |
會讓瀏覽器每個捲動影格都要重新計算模糊,頁面一長(大表格、多張圖)就會
|
| 2039 |
卡很久(見使用者回報「滑鼠往下滑畫面會卡住好久」)。改用不透明背景取代
|
| 2040 |
-
模糊,視覺上仍有「浮在內容上方」的區隔感,但渲染成本低很多
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2041 |
.tabs > .tab-nav {
|
| 2042 |
background: var(--c-surface) !important;
|
| 2043 |
border-bottom: 1px solid var(--c-border) !important;
|
|
@@ -2071,8 +2082,13 @@ _CUSTOM_CSS = """
|
|
| 2071 |
/* 巢狀子分頁(統計比較分析內,敘述統計/差異性分析/監督式學習/非監督式學習)
|
| 2072 |
維持原字級。Phase 8-C 前這裡靠 .tabitem 祖先跟外層分頁列的 .tabs 區分;
|
| 2073 |
外層 gr.Tabs() 拿掉後,這是全站唯一剩下的 .tabs,改用 canvas_stat_col
|
| 2074 |
-
的 elem_id 精準定位,避免套用上面給「全頁分頁列」設計的 1.20rem 大字級
|
| 2075 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2076 |
|
| 2077 |
/* ── 4. CHATBOT ────────────────────────────────────────────────── */
|
| 2078 |
.chatbot {
|
|
@@ -2547,6 +2563,52 @@ div[role="log"][aria-label="chatbot conversation"],
|
|
| 2547 |
padding: 1rem 1.2rem !important;
|
| 2548 |
margin-top: .6rem !important;
|
| 2549 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2550 |
/* 語料 Metadata 說明表單卡片 */
|
| 2551 |
.metadata-zone {
|
| 2552 |
border: 1px solid rgba(var(--c-accent-rgb),.40) !important;
|
|
@@ -2562,6 +2624,31 @@ div[role="log"][aria-label="chatbot conversation"],
|
|
| 2562 |
從原本的 gr.Tab()(自帶 .tabitem padding)改成 gr.Column,這裡補上
|
| 2563 |
跟上��� upload-zone/metadata-zone 一致的垂直間距,避免緊貼在一起 */
|
| 2564 |
.canvas-result { margin-top: 1.2rem !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2565 |
.upload-area, [data-testid="droparea"] {
|
| 2566 |
border: 2px dashed rgba(var(--c-accent-rgb),.28) !important;
|
| 2567 |
border-radius: 12px !important;
|
|
@@ -2960,6 +3047,55 @@ _APP_HEAD_SCRIPT = """
|
|
| 2960 |
}
|
| 2961 |
[300, 800, 1500, 3000].forEach(function(t) { setTimeout(bindScenarioCards, t); });
|
| 2962 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2963 |
/* 持續監聽 DOM 變化(每次訊息更新後重設) */
|
| 2964 |
var mo = new MutationObserver(function(mutations) {
|
| 2965 |
var needsFix = mutations.some(function(m) {
|
|
@@ -3122,8 +3258,32 @@ def create_app():
|
|
| 3122 |
with gr.Row(elem_classes=["upload-actions"]):
|
| 3123 |
reset_cancel_btn = gr.Button("取消", scale=1, variant="secondary")
|
| 3124 |
reset_confirm_btn = gr.Button("確定重新開始", scale=2, variant="primary")
|
| 3125 |
-
|
| 3126 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3127 |
|
| 3128 |
with gr.Column(scale=4, min_width=300, elem_classes=["chat-col"]):
|
| 3129 |
chatbot = gr.Chatbot(
|
|
@@ -3230,6 +3390,12 @@ def create_app():
|
|
| 3230 |
meta_cancel_btn = gr.Button("略過", scale=1, variant="secondary")
|
| 3231 |
meta_confirm_btn = gr.Button("確認並開始分析", scale=2, variant="primary")
|
| 3232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3233 |
# Phase 8-C:結果內容從 tab2/tab3/tab6(原本 gr.Tabs() 分頁頁面)搬進
|
| 3234 |
# Canvas,改成三個互斥可見性的 gr.Column,取代整頁分頁切換。三塊
|
| 3235 |
# 目前皆用同一組 visible=True/False 語意(見 _populate_tabs 的
|
|
@@ -3568,34 +3734,64 @@ def create_app():
|
|
| 3568 |
label=_accordion_label(log_history),
|
| 3569 |
)
|
| 3570 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3571 |
# ── 文字送出(streaming generator)──────────────────────────────────
|
| 3572 |
# ── 研究情境選擇(封閉式固定四選一,按鈕直接觸發,不再解析打字輸入)──
|
| 3573 |
def on_scenario_pick(sc_num, chat_history, log_history, state):
|
| 3574 |
if state is None:
|
| 3575 |
-
yield chat_history, log_history, state, gr.update(), gr.update(), gr.update(), gr.update(),
|
|
|
|
| 3576 |
return
|
| 3577 |
|
| 3578 |
sc_info = SCENARIOS[sc_num]
|
| 3579 |
chat_history = chat_history + [_user_msg(sc_info["title"])]
|
| 3580 |
log_history = _log_append(log_history, "使用者選擇研究情境中……")
|
| 3581 |
# 首頁一旦選定情境即隱藏,換成對話+操作區(workspace_row);
|
| 3582 |
-
#
|
|
|
|
|
|
|
| 3583 |
# 沿用 gr.update() 不動即可,不用每次都重複賦值。
|
| 3584 |
yield (chat_history, log_history, state, gr.update(), gr.update(), gr.update(), gr.update(),
|
| 3585 |
-
gr.update(visible=False), gr.update(visible=True))
|
| 3586 |
|
| 3587 |
reply, state = handle_scenario_select(sc_num, state)
|
| 3588 |
log_history = _log_append(log_history, "✅ STEP 1 情境選擇完成")
|
| 3589 |
chat_history = chat_history + [_assistant_msg(reply)]
|
| 3590 |
yield (chat_history, log_history, state, gr.update(), _todo_update(state), gr.update(), gr.update(),
|
| 3591 |
-
gr.update(), gr.update())
|
| 3592 |
|
| 3593 |
# STEP 2:確認訊息已經導向上傳卡片的「格式要求」區塊,不再另外用
|
| 3594 |
# LLM 生成一則重複格式細節的引導訊息,避免對話視窗出現冗餘內容
|
| 3595 |
state["current_step"] = 2
|
| 3596 |
log_history = _log_append(log_history, "⏳ STEP 2 上傳引導中……")
|
| 3597 |
yield (chat_history, log_history, state, gr.update(), _todo_update(state), gr.update(), gr.update(),
|
| 3598 |
-
gr.update(), gr.update())
|
| 3599 |
|
| 3600 |
state["done_steps"] = [1, 2]
|
| 3601 |
state["current_step"] = 3
|
|
@@ -3609,14 +3805,14 @@ def create_app():
|
|
| 3609 |
)
|
| 3610 |
yield (chat_history, log_history, state, gr.update(visible=True),
|
| 3611 |
_todo_update(state), gr.update(visible=False), gr.update(value=hint),
|
| 3612 |
-
gr.update(), gr.update())
|
| 3613 |
|
| 3614 |
for _sc_num, _sc_btn in (("1", sc_btn_1), ("2", sc_btn_2), ("3", sc_btn_3), ("4", sc_btn_4)):
|
| 3615 |
_sc_btn.click(
|
| 3616 |
fn=functools.partial(on_scenario_pick, _sc_num),
|
| 3617 |
inputs=[chatbot, exec_log, session_state],
|
| 3618 |
outputs=[chatbot, exec_log, session_state, upload_row, app_header_html, scenario_btn_col,
|
| 3619 |
-
upload_hint_md, homepage_col, workspace_row],
|
| 3620 |
).then(
|
| 3621 |
fn=_populate_tabs,
|
| 3622 |
inputs=[session_state],
|
|
@@ -3652,6 +3848,8 @@ def create_app():
|
|
| 3652 |
gr.update(visible=True), # homepage_col(Phase 8:重新開始=回到首頁選情境)
|
| 3653 |
gr.update(visible=False), # workspace_row
|
| 3654 |
gr.update(value=None), # file_input(Phase 8:upload_row 變正式入口後一併清空)
|
|
|
|
|
|
|
| 3655 |
)
|
| 3656 |
|
| 3657 |
reset_btn.click(fn=lambda: gr.update(visible=True), outputs=[reset_confirm_row])
|
|
@@ -3661,7 +3859,8 @@ def create_app():
|
|
| 3661 |
outputs=[chatbot, exec_log, session_state, app_header_html,
|
| 3662 |
scenario_btn_col, upload_row, chat_upload, metadata_row,
|
| 3663 |
canvas_idx_col, canvas_stat_col, canvas_report_col,
|
| 3664 |
-
reset_confirm_row, exec_log_accordion, homepage_col, workspace_row, file_input
|
|
|
|
| 3665 |
)
|
| 3666 |
|
| 3667 |
# ── 檔案上傳確認(streaming generator)──────────────────────────────
|
|
@@ -3754,7 +3953,8 @@ def create_app():
|
|
| 3754 |
|
| 3755 |
def _run_computation(chat_history, log_history, state):
|
| 3756 |
log_history = _log_append(log_history, "⏳ STEP 5 計算語言指標中……")
|
| 3757 |
-
yield chat_history, log_history, state, _todo_update(state),
|
|
|
|
| 3758 |
for prog_msg, is_final, state in run_computation_pipeline_streaming(state):
|
| 3759 |
if "指標計算完成" in prog_msg:
|
| 3760 |
state["done_steps"] = list(set(state.get("done_steps", []) + [5])); state["current_step"] = 6
|
|
@@ -3769,7 +3969,8 @@ def create_app():
|
|
| 3769 |
log_history = _log_append(log_history, prog_msg)
|
| 3770 |
if is_final:
|
| 3771 |
chat_history = chat_history + [_assistant_msg(prog_msg)]
|
| 3772 |
-
yield chat_history, log_history, state, _todo_update(state),
|
|
|
|
| 3773 |
|
| 3774 |
def _show_metadata_form(state):
|
| 3775 |
_NO = gr.update()
|
|
@@ -3826,7 +4027,7 @@ def create_app():
|
|
| 3826 |
ngroups, method, group_df, indiv_df,
|
| 3827 |
chat_history, log_history, state):
|
| 3828 |
if state is None:
|
| 3829 |
-
yield chat_history, log_history, state, gr.update(), _todo_update(state), gr.update()
|
| 3830 |
return
|
| 3831 |
|
| 3832 |
# 群組數量跟實際上傳分組是否一致:只有情境3/4才會顯示這個選項,
|
|
@@ -3844,7 +4045,8 @@ def create_app():
|
|
| 3844 |
)
|
| 3845 |
chat_history = chat_history + [_assistant_msg(warn_msg)]
|
| 3846 |
log_history = _log_append(log_history, "⚠️ 群組數量與上傳檔案不一致")
|
| 3847 |
-
yield chat_history, log_history, state, gr.update(visible=True),
|
|
|
|
| 3848 |
return
|
| 3849 |
|
| 3850 |
state["user_metadata"] = _compile_metadata(state, title, author, lang, pubyear,
|
|
@@ -3853,10 +4055,10 @@ def create_app():
|
|
| 3853 |
# 在主對話視窗立即顯示「開始分析」訊息,避免長時間運算期間畫面看起來像沒有反應
|
| 3854 |
chat_history = chat_history + [_assistant_msg(_ANALYSIS_START_MSG)]
|
| 3855 |
yield (chat_history, log_history, state, gr.update(visible=False),
|
| 3856 |
-
_todo_update(state), _accordion_update(state, log_history))
|
| 3857 |
-
for ch, lh, st, todo, acc in _run_computation(chat_history, log_history, state):
|
| 3858 |
chat_history, log_history, state = ch, lh, st
|
| 3859 |
-
yield chat_history, log_history, state, gr.update(visible=False), todo, acc
|
| 3860 |
|
| 3861 |
def _lock_meta():
|
| 3862 |
return gr.update(interactive=False), gr.update(interactive=False)
|
|
@@ -3871,30 +4073,32 @@ def create_app():
|
|
| 3871 |
inputs=[meta_title, meta_author, meta_lang, meta_pubyear, meta_version,
|
| 3872 |
meta_ngroups, meta_method, meta_group_df, meta_indiv_df,
|
| 3873 |
chatbot, exec_log, session_state],
|
| 3874 |
-
outputs=[chatbot, exec_log, session_state, metadata_row, app_header_html,
|
|
|
|
| 3875 |
).then(
|
| 3876 |
fn=_unlock_meta, inputs=None, outputs=[meta_confirm_btn, meta_cancel_btn],
|
| 3877 |
).then(fn=_populate_tabs, inputs=[session_state], outputs=_TAB_OUTPUTS)
|
| 3878 |
|
| 3879 |
def on_metadata_skip(chat_history, log_history, state):
|
| 3880 |
if state is None:
|
| 3881 |
-
yield chat_history, log_history, state, gr.update(), _todo_update(state), gr.update()
|
| 3882 |
return
|
| 3883 |
state["user_metadata"] = state.get("user_metadata", "") or "(使用者未提供語料 Metadata 說明)"
|
| 3884 |
log_history = _log_append(log_history, "⏭️ 已略過 Metadata,直接開始分析")
|
| 3885 |
chat_history = chat_history + [_assistant_msg(_ANALYSIS_START_MSG)]
|
| 3886 |
yield (chat_history, log_history, state, gr.update(visible=False),
|
| 3887 |
-
_todo_update(state), _accordion_update(state, log_history))
|
| 3888 |
-
for ch, lh, st, todo, acc in _run_computation(chat_history, log_history, state):
|
| 3889 |
chat_history, log_history, state = ch, lh, st
|
| 3890 |
-
yield chat_history, log_history, state, gr.update(visible=False), todo, acc
|
| 3891 |
|
| 3892 |
meta_cancel_btn.click(
|
| 3893 |
fn=_lock_meta, inputs=None, outputs=[meta_confirm_btn, meta_cancel_btn],
|
| 3894 |
).then(
|
| 3895 |
fn=on_metadata_skip,
|
| 3896 |
inputs=[chatbot, exec_log, session_state],
|
| 3897 |
-
outputs=[chatbot, exec_log, session_state, metadata_row, app_header_html,
|
|
|
|
| 3898 |
).then(
|
| 3899 |
fn=_unlock_meta, inputs=None, outputs=[meta_confirm_btn, meta_cancel_btn],
|
| 3900 |
).then(fn=_populate_tabs, inputs=[session_state], outputs=_TAB_OUTPUTS)
|
|
|
|
| 2037 |
/* 注意:這裡原本用 backdrop-filter 做毛玻璃效果,搭配 position: sticky
|
| 2038 |
會讓瀏覽器每個捲動影格都要重新計算模糊,頁面一長(大表格、多張圖)就會
|
| 2039 |
卡很久(見使用者回報「滑鼠往下滑畫面會卡住好久」)。改用不透明背景取代
|
| 2040 |
+
模糊,視覺上仍有「浮在內容上方」的區隔感,但渲染成本低很多
|
| 2041 |
+
⚠ 已知問題(2026-07-22 Phase 8-D 排查時發現,尚未修):這整組
|
| 2042 |
+
`.tabs > .tab-nav` 選擇器在目前這版 Gradio 的實際 DOM 完全不會命中——
|
| 2043 |
+
真正的分頁按鈕列 class 是 `.tabs > .tab-wrapper > .tab-container`(用
|
| 2044 |
+
devtools 逐層確認過),沒有任何節點叫 `.tab-nav`。下面這整組 sticky/
|
| 2045 |
+
背景/hover/selected 樣式從寫下來那天起可能就是死規則,畫面上看起來
|
| 2046 |
+
還算合理是因為套用 Gradio 自己的預設樣式,不是這裡的客製化在生效。
|
| 2047 |
+
影響範圍是「統計比較分析」巢狀子分頁的視覺,不是本次 Phase 8-D 導覽
|
| 2048 |
+
功能的範圍(導覽的捲動/切換邏輯已改用正確的 `.tab-container` 選擇器,
|
| 2049 |
+
見 _APP_HEAD_SCRIPT 的 bindResultNav())。下次要做這批巢狀分頁的視覺
|
| 2050 |
+
打磨(sticky 分頁列、選中底色等)時,先把這整組選擇器換成
|
| 2051 |
+
`.tab-container` 再動手,不要照抄這裡的 `.tab-nav`。 */
|
| 2052 |
.tabs > .tab-nav {
|
| 2053 |
background: var(--c-surface) !important;
|
| 2054 |
border-bottom: 1px solid var(--c-border) !important;
|
|
|
|
| 2082 |
/* 巢狀子分頁(統計比較分析內,敘述統計/差異性分析/監督式學習/非監督式學習)
|
| 2083 |
維持原字級。Phase 8-C 前這裡靠 .tabitem 祖先跟外層分頁列的 .tabs 區分;
|
| 2084 |
外層 gr.Tabs() 拿掉後,這是全站唯一剩下的 .tabs,改用 canvas_stat_col
|
| 2085 |
+
的 elem_id 精準定位,避免套用上面給「全頁分頁列」設計的 1.20rem 大字級。
|
| 2086 |
+
注意:選擇器用 .tab-container(不是 .tab-nav,見上方「已知問題」註解),
|
| 2087 |
+
且要排除 .visually-hidden 那份(窄螢幕溢出選單用的隱藏副本),否則兩份
|
| 2088 |
+
都會命中但視覺上只有一份看得到,容易誤以為規則沒生效 */
|
| 2089 |
+
#canvas_stat .tabs > .tab-wrapper > .tab-container:not(.visually-hidden) > button {
|
| 2090 |
+
font-size: 0.80rem !important;
|
| 2091 |
+
}
|
| 2092 |
|
| 2093 |
/* ── 4. CHATBOT ────────────────────────────────────────────────── */
|
| 2094 |
.chatbot {
|
|
|
|
| 2563 |
padding: 1rem 1.2rem !important;
|
| 2564 |
margin-top: .6rem !important;
|
| 2565 |
}
|
| 2566 |
+
/* Phase 8-D:結果導覽(情境選定後顯示在開始新分析按鈕下方),純文字
|
| 2567 |
+
標籤(暫不用圖示,等下一輪視覺打磨補 Heroicons SVG),維持跟
|
| 2568 |
+
scenario-buttons 一致的「貼齊左邊、無強調色底」低視覺重量風格,
|
| 2569 |
+
避免搶過主要操作按鈕的注意力 */
|
| 2570 |
+
.result-nav {
|
| 2571 |
+
margin-top: 1rem !important;
|
| 2572 |
+
padding-top: 1rem !important;
|
| 2573 |
+
border-top: 1px solid var(--c-border) !important;
|
| 2574 |
+
gap: .3rem !important;
|
| 2575 |
+
}
|
| 2576 |
+
.result-nav-btn, .result-nav-subbtn {
|
| 2577 |
+
width: 100% !important;
|
| 2578 |
+
justify-content: flex-start !important;
|
| 2579 |
+
text-align: left !important;
|
| 2580 |
+
border: none !important;
|
| 2581 |
+
background: transparent !important;
|
| 2582 |
+
box-shadow: none !important;
|
| 2583 |
+
}
|
| 2584 |
+
.result-nav-btn {
|
| 2585 |
+
padding: .6rem .7rem !important;
|
| 2586 |
+
font-size: .88rem !important;
|
| 2587 |
+
font-weight: 600 !important;
|
| 2588 |
+
border-radius: 8px !important;
|
| 2589 |
+
color: var(--c-text-soft) !important;
|
| 2590 |
+
}
|
| 2591 |
+
.result-nav-btn:hover { background: rgba(var(--c-accent-rgb),.08) !important; color: var(--c-text) !important; }
|
| 2592 |
+
.result-nav-subbtn {
|
| 2593 |
+
padding: .45rem .7rem .45rem 1.4rem !important;
|
| 2594 |
+
font-size: .8rem !important;
|
| 2595 |
+
font-weight: 500 !important;
|
| 2596 |
+
border-radius: 6px !important;
|
| 2597 |
+
color: var(--c-text-muted) !important;
|
| 2598 |
+
}
|
| 2599 |
+
.result-nav-subbtn:hover { background: rgba(var(--c-accent-rgb),.06) !important; color: var(--c-text-soft) !important; }
|
| 2600 |
+
.result-nav-accordion {
|
| 2601 |
+
margin: 0 !important;
|
| 2602 |
+
border: none !important;
|
| 2603 |
+
background: transparent !important;
|
| 2604 |
+
box-shadow: none !important;
|
| 2605 |
+
}
|
| 2606 |
+
.result-nav-accordion .label-wrap {
|
| 2607 |
+
padding: .6rem .7rem !important;
|
| 2608 |
+
font-size: .88rem !important;
|
| 2609 |
+
font-weight: 600 !important;
|
| 2610 |
+
color: var(--c-text-soft) !important;
|
| 2611 |
+
}
|
| 2612 |
/* 語料 Metadata 說明表單卡片 */
|
| 2613 |
.metadata-zone {
|
| 2614 |
border: 1px solid rgba(var(--c-accent-rgb),.40) !important;
|
|
|
|
| 2624 |
從原本的 gr.Tab()(自帶 .tabitem padding)改成 gr.Column,這裡補上
|
| 2625 |
跟上��� upload-zone/metadata-zone 一致的垂直間距,避免緊貼在一起 */
|
| 2626 |
.canvas-result { margin-top: 1.2rem !important; }
|
| 2627 |
+
/* Phase 8-D:運算中提示——跟 upload-zone/metadata-zone 一樣的圓角/間距
|
| 2628 |
+
慣例,但刻意用中性 surface2 底色(不是強調色漸層),因為這裡純粹是
|
| 2629 |
+
唯讀進度提示,不是需要操作的表單卡片,避免視覺上混淆成可互動元件 */
|
| 2630 |
+
.computing-zone {
|
| 2631 |
+
display: flex;
|
| 2632 |
+
align-items: center;
|
| 2633 |
+
gap: .7rem;
|
| 2634 |
+
border: 1px solid var(--c-border) !important;
|
| 2635 |
+
border-radius: 14px !important;
|
| 2636 |
+
background: var(--c-surface2) !important;
|
| 2637 |
+
padding: 1rem 1.3rem !important;
|
| 2638 |
+
margin-top: 1.2rem !important;
|
| 2639 |
+
font-size: var(--font-size-base) !important;
|
| 2640 |
+
font-weight: 600 !important;
|
| 2641 |
+
color: var(--c-text-soft) !important;
|
| 2642 |
+
}
|
| 2643 |
+
.computing-spinner {
|
| 2644 |
+
flex: none;
|
| 2645 |
+
width: 20px; height: 20px;
|
| 2646 |
+
border-radius: 50%;
|
| 2647 |
+
border: 2.5px solid rgba(var(--c-accent-rgb),.25);
|
| 2648 |
+
border-top-color: var(--c-accent);
|
| 2649 |
+
animation: computingSpin .8s linear infinite;
|
| 2650 |
+
}
|
| 2651 |
+
@keyframes computingSpin { to { transform: rotate(360deg); } }
|
| 2652 |
.upload-area, [data-testid="droparea"] {
|
| 2653 |
border: 2px dashed rgba(var(--c-accent-rgb),.28) !important;
|
| 2654 |
border-radius: 12px !important;
|
|
|
|
| 3047 |
}
|
| 3048 |
[300, 800, 1500, 3000].forEach(function(t) { setTimeout(bindScenarioCards, t); });
|
| 3049 |
|
| 3050 |
+
/* Phase 8-D:左側結果導覽(result_nav_col)——純粹是「捲動到
|
| 3051 |
+
Canvas 對應區塊+切換巢狀子分頁」的畫面操作,不牽動任何後端
|
| 3052 |
+
狀態,所以這幾顆按鈕在 Python 端完全沒有掛 .click(),改用這裡
|
| 3053 |
+
的事件代理直接處理,不用走 Gradio queue 來回。
|
| 3054 |
+
注意:result_nav_col 建構時是 visible=False(跟 sc_btn_1..4
|
| 3055 |
+
一度踩過的坑同一類),如果比照 bindScenarioCards() 用
|
| 3056 |
+
setTimeout 抓固定時間點的按鈕,情境選定前按鈕還沒掛載,之後
|
| 3057 |
+
也不會再重試。改用事件代理綁在 document 這個從頁面一開始就
|
| 3058 |
+
存在的祖先節點上,不管 result_nav_col 什麼時候才真正掛載進
|
| 3059 |
+
DOM,點擊都能正確代理處理,不用重試機制。 */
|
| 3060 |
+
function bindResultNav() {
|
| 3061 |
+
if (window._resultNavBound) return;
|
| 3062 |
+
window._resultNavBound = true;
|
| 3063 |
+
function scrollToId(id) {
|
| 3064 |
+
var el = document.getElementById(id);
|
| 3065 |
+
if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
| 3066 |
+
}
|
| 3067 |
+
document.addEventListener('click', function (e) {
|
| 3068 |
+
if (e.target.closest('#nav_top_btn')) {
|
| 3069 |
+
var scrollBox = document.querySelector('.canvas-scroll');
|
| 3070 |
+
if (scrollBox) scrollBox.scrollTo({ top: 0, behavior: 'smooth' });
|
| 3071 |
+
return;
|
| 3072 |
+
}
|
| 3073 |
+
if (e.target.closest('#nav_idx_btn')) { scrollToId('canvas_idx'); return; }
|
| 3074 |
+
if (e.target.closest('#nav_report_btn')) { scrollToId('canvas_report'); return; }
|
| 3075 |
+
if (e.target.closest('#nav_stat_accordion .label-wrap')) { scrollToId('canvas_stat'); return; }
|
| 3076 |
+
for (var i = 0; i < 4; i++) {
|
| 3077 |
+
if (e.target.closest('#nav_stat_sub_' + i)) {
|
| 3078 |
+
scrollToId('canvas_stat');
|
| 3079 |
+
/* 注意:這版 Gradio 的巢狀分頁 DOM 結構是
|
| 3080 |
+
.tabs > .tab-wrapper > .tab-container(兩個,
|
| 3081 |
+
一個 .visually-hidden 是窄螢幕/溢出選單用的隱藏
|
| 3082 |
+
版本,另一個才是實際看得到、要點的),不是常見
|
| 3083 |
+
印象中的 .tab-nav——原本沿用 .tab-nav 的選擇器
|
| 3084 |
+
(包含 CSS 那條,見上面 #canvas_stat 註解)在
|
| 3085 |
+
這版完全不會命中,只是沒人發現因為 Gradio 自己的
|
| 3086 |
+
預設樣式已經看起來夠好。這裡用 devtools 逐層
|
| 3087 |
+
確認過實際 class 後才改對。 */
|
| 3088 |
+
var tabButtons = document.querySelectorAll(
|
| 3089 |
+
'#canvas_stat .tabs > .tab-wrapper > .tab-container:not(.visually-hidden) > button'
|
| 3090 |
+
);
|
| 3091 |
+
if (tabButtons[i]) tabButtons[i].click();
|
| 3092 |
+
return;
|
| 3093 |
+
}
|
| 3094 |
+
}
|
| 3095 |
+
});
|
| 3096 |
+
}
|
| 3097 |
+
bindResultNav();
|
| 3098 |
+
|
| 3099 |
/* 持續監聽 DOM 變化(每次訊息更新後重設) */
|
| 3100 |
var mo = new MutationObserver(function(mutations) {
|
| 3101 |
var needsFix = mutations.some(function(m) {
|
|
|
|
| 3258 |
with gr.Row(elem_classes=["upload-actions"]):
|
| 3259 |
reset_cancel_btn = gr.Button("取消", scale=1, variant="secondary")
|
| 3260 |
reset_confirm_btn = gr.Button("確定重新開始", scale=2, variant="primary")
|
| 3261 |
+
|
| 3262 |
+
# Phase 8-D:結果導覽——情境選定後顯示,讓使用者不用手動
|
| 3263 |
+
# 往下捲一大段就能跳到 Canvas 對應區塊。這幾顆按鈕刻意不接
|
| 3264 |
+
# Python .click():純粹是「捲動+切換巢狀子分頁」的畫面
|
| 3265 |
+
# 操作,不牽動任何後端狀態,改用跟首頁情境卡片同一套手法
|
| 3266 |
+
# (_APP_HEAD_SCRIPT 的 JS 監聽),完全不用走 Gradio queue
|
| 3267 |
+
# 來回,反應更快。下載捷徑/「下載完整報告」假按鈕留到
|
| 3268 |
+
# 下一輪視覺打磨(Heroicons 圖示)一起補,這次先求導覽功能
|
| 3269 |
+
# 正確可用。
|
| 3270 |
+
with gr.Column(visible=False, elem_id="result_nav_col", elem_classes=["result-nav"]) as result_nav_col:
|
| 3271 |
+
nav_top_btn = gr.Button("回到上傳/表單", elem_id="nav_top_btn",
|
| 3272 |
+
elem_classes=["result-nav-btn"], variant="secondary")
|
| 3273 |
+
nav_idx_btn = gr.Button("語言指標分析", elem_id="nav_idx_btn",
|
| 3274 |
+
elem_classes=["result-nav-btn"], variant="secondary")
|
| 3275 |
+
with gr.Accordion("統計比較分析", open=False, elem_id="nav_stat_accordion",
|
| 3276 |
+
elem_classes=["result-nav-accordion"]):
|
| 3277 |
+
nav_stat_sub_0 = gr.Button("敘述統計", elem_id="nav_stat_sub_0",
|
| 3278 |
+
elem_classes=["result-nav-subbtn"], variant="secondary")
|
| 3279 |
+
nav_stat_sub_1 = gr.Button("差異性分析", elem_id="nav_stat_sub_1",
|
| 3280 |
+
elem_classes=["result-nav-subbtn"], variant="secondary")
|
| 3281 |
+
nav_stat_sub_2 = gr.Button("監督式學習", elem_id="nav_stat_sub_2",
|
| 3282 |
+
elem_classes=["result-nav-subbtn"], variant="secondary")
|
| 3283 |
+
nav_stat_sub_3 = gr.Button("非監督式學習", elem_id="nav_stat_sub_3",
|
| 3284 |
+
elem_classes=["result-nav-subbtn"], variant="secondary")
|
| 3285 |
+
nav_report_btn = gr.Button("LLM輔助分析", elem_id="nav_report_btn",
|
| 3286 |
+
elem_classes=["result-nav-btn"], variant="secondary")
|
| 3287 |
|
| 3288 |
with gr.Column(scale=4, min_width=300, elem_classes=["chat-col"]):
|
| 3289 |
chatbot = gr.Chatbot(
|
|
|
|
| 3390 |
meta_cancel_btn = gr.Button("略過", scale=1, variant="secondary")
|
| 3391 |
meta_confirm_btn = gr.Button("確認並開始分析", scale=2, variant="primary")
|
| 3392 |
|
| 3393 |
+
# Phase 8-D:運算中提示(指標計算/統計分析/報告撰寫這三步
|
| 3394 |
+
# 沒有真百分比,只有粗粒度階段字樣+轉圈動畫,讓使用者不用
|
| 3395 |
+
# 展開下方技術執行紀錄也能一眼看到系統還在跑)。空字串=
|
| 3396 |
+
# 不顯示,見 _build_computing_html/_computing_update。
|
| 3397 |
+
computing_html = gr.HTML(value="", elem_id="computing_zone")
|
| 3398 |
+
|
| 3399 |
# Phase 8-C:結果內容從 tab2/tab3/tab6(原本 gr.Tabs() 分頁頁面)搬進
|
| 3400 |
# Canvas,改成三個互斥可見性的 gr.Column,取代整頁分頁切換。三塊
|
| 3401 |
# 目前皆用同一組 visible=True/False 語意(見 _populate_tabs 的
|
|
|
|
| 3734 |
label=_accordion_label(log_history),
|
| 3735 |
)
|
| 3736 |
|
| 3737 |
+
# ── Phase 8-D:Canvas 運算中提示(粗粒度階段文字+轉圈動畫)─────
|
| 3738 |
+
# 沿用跟 _accordion_update 完全一樣的判斷(current_step 在 5/6/7 之間
|
| 3739 |
+
# 才顯示),不新增運算邏輯;用 gr.HTML() 單一元件承載,空字串=不
|
| 3740 |
+
# 顯示、不用另外接一個 visibility 輸出,wiring 只多一個輸出點。
|
| 3741 |
+
_COMPUTING_STEP_LABELS = {
|
| 3742 |
+
5: ("1", "指標計算"),
|
| 3743 |
+
6: ("2", "統計分析"),
|
| 3744 |
+
7: ("3", "報告撰寫"),
|
| 3745 |
+
}
|
| 3746 |
+
|
| 3747 |
+
def _build_computing_html(state):
|
| 3748 |
+
if not state:
|
| 3749 |
+
return ""
|
| 3750 |
+
info = _COMPUTING_STEP_LABELS.get(state.get("current_step"))
|
| 3751 |
+
if not info:
|
| 3752 |
+
return ""
|
| 3753 |
+
n, label = info
|
| 3754 |
+
return (
|
| 3755 |
+
'<div class="computing-zone">'
|
| 3756 |
+
'<span class="computing-spinner" aria-hidden="true"></span>'
|
| 3757 |
+
f'<span>運算中…(步驟 {n}/3 {label})</span>'
|
| 3758 |
+
'</div>'
|
| 3759 |
+
)
|
| 3760 |
+
|
| 3761 |
+
def _computing_update(state):
|
| 3762 |
+
return gr.update(value=_build_computing_html(state))
|
| 3763 |
+
|
| 3764 |
# ── 文字送出(streaming generator)──────────────────────────────────
|
| 3765 |
# ── 研究情境選擇(封閉式固定四選一,按鈕直接觸發,不再解析打字輸入)──
|
| 3766 |
def on_scenario_pick(sc_num, chat_history, log_history, state):
|
| 3767 |
if state is None:
|
| 3768 |
+
yield (chat_history, log_history, state, gr.update(), gr.update(), gr.update(), gr.update(),
|
| 3769 |
+
gr.update(), gr.update(), gr.update())
|
| 3770 |
return
|
| 3771 |
|
| 3772 |
sc_info = SCENARIOS[sc_num]
|
| 3773 |
chat_history = chat_history + [_user_msg(sc_info["title"])]
|
| 3774 |
log_history = _log_append(log_history, "使用者選擇研究情境中……")
|
| 3775 |
# 首頁一旦選定情境即隱藏,換成對話+操作區(workspace_row);
|
| 3776 |
+
# 結果導覽(result_nav_col)也在這時候一併顯示(雖然還沒有結果
|
| 3777 |
+
# 可跳轉,但導覽列本身跟開始新分析按鈕一樣是常駐的操作區塊)。
|
| 3778 |
+
# 這幾個 visibility 只需要在第一個 yield 就切換一次,後續 yield
|
| 3779 |
# 沿用 gr.update() 不動即可,不用每次都重複賦值。
|
| 3780 |
yield (chat_history, log_history, state, gr.update(), gr.update(), gr.update(), gr.update(),
|
| 3781 |
+
gr.update(visible=False), gr.update(visible=True), gr.update(visible=True))
|
| 3782 |
|
| 3783 |
reply, state = handle_scenario_select(sc_num, state)
|
| 3784 |
log_history = _log_append(log_history, "✅ STEP 1 情境選擇完成")
|
| 3785 |
chat_history = chat_history + [_assistant_msg(reply)]
|
| 3786 |
yield (chat_history, log_history, state, gr.update(), _todo_update(state), gr.update(), gr.update(),
|
| 3787 |
+
gr.update(), gr.update(), gr.update())
|
| 3788 |
|
| 3789 |
# STEP 2:確認訊息已經導向上傳卡片的「格式要求」區塊,不再另外用
|
| 3790 |
# LLM 生成一則重複格式細節的引導訊息,避免對話視窗出現冗餘內容
|
| 3791 |
state["current_step"] = 2
|
| 3792 |
log_history = _log_append(log_history, "⏳ STEP 2 上傳引導中……")
|
| 3793 |
yield (chat_history, log_history, state, gr.update(), _todo_update(state), gr.update(), gr.update(),
|
| 3794 |
+
gr.update(), gr.update(), gr.update())
|
| 3795 |
|
| 3796 |
state["done_steps"] = [1, 2]
|
| 3797 |
state["current_step"] = 3
|
|
|
|
| 3805 |
)
|
| 3806 |
yield (chat_history, log_history, state, gr.update(visible=True),
|
| 3807 |
_todo_update(state), gr.update(visible=False), gr.update(value=hint),
|
| 3808 |
+
gr.update(), gr.update(), gr.update())
|
| 3809 |
|
| 3810 |
for _sc_num, _sc_btn in (("1", sc_btn_1), ("2", sc_btn_2), ("3", sc_btn_3), ("4", sc_btn_4)):
|
| 3811 |
_sc_btn.click(
|
| 3812 |
fn=functools.partial(on_scenario_pick, _sc_num),
|
| 3813 |
inputs=[chatbot, exec_log, session_state],
|
| 3814 |
outputs=[chatbot, exec_log, session_state, upload_row, app_header_html, scenario_btn_col,
|
| 3815 |
+
upload_hint_md, homepage_col, workspace_row, result_nav_col],
|
| 3816 |
).then(
|
| 3817 |
fn=_populate_tabs,
|
| 3818 |
inputs=[session_state],
|
|
|
|
| 3848 |
gr.update(visible=True), # homepage_col(Phase 8:重新開始=回到首頁選情境)
|
| 3849 |
gr.update(visible=False), # workspace_row
|
| 3850 |
gr.update(value=None), # file_input(Phase 8:upload_row 變正式入口後一併清空)
|
| 3851 |
+
gr.update(value=""), # computing_html(Phase 8-D:中途重置要清掉運算中提示)
|
| 3852 |
+
gr.update(visible=False), # result_nav_col(Phase 8-D:重新開始=回到首頁,導覽收起)
|
| 3853 |
)
|
| 3854 |
|
| 3855 |
reset_btn.click(fn=lambda: gr.update(visible=True), outputs=[reset_confirm_row])
|
|
|
|
| 3859 |
outputs=[chatbot, exec_log, session_state, app_header_html,
|
| 3860 |
scenario_btn_col, upload_row, chat_upload, metadata_row,
|
| 3861 |
canvas_idx_col, canvas_stat_col, canvas_report_col,
|
| 3862 |
+
reset_confirm_row, exec_log_accordion, homepage_col, workspace_row, file_input,
|
| 3863 |
+
computing_html, result_nav_col],
|
| 3864 |
)
|
| 3865 |
|
| 3866 |
# ── 檔案上傳確認(streaming generator)──────────────────────────────
|
|
|
|
| 3953 |
|
| 3954 |
def _run_computation(chat_history, log_history, state):
|
| 3955 |
log_history = _log_append(log_history, "⏳ STEP 5 計算語言指標中……")
|
| 3956 |
+
yield (chat_history, log_history, state, _todo_update(state),
|
| 3957 |
+
_accordion_update(state, log_history), _computing_update(state))
|
| 3958 |
for prog_msg, is_final, state in run_computation_pipeline_streaming(state):
|
| 3959 |
if "指標計算完成" in prog_msg:
|
| 3960 |
state["done_steps"] = list(set(state.get("done_steps", []) + [5])); state["current_step"] = 6
|
|
|
|
| 3969 |
log_history = _log_append(log_history, prog_msg)
|
| 3970 |
if is_final:
|
| 3971 |
chat_history = chat_history + [_assistant_msg(prog_msg)]
|
| 3972 |
+
yield (chat_history, log_history, state, _todo_update(state),
|
| 3973 |
+
_accordion_update(state, log_history), _computing_update(state))
|
| 3974 |
|
| 3975 |
def _show_metadata_form(state):
|
| 3976 |
_NO = gr.update()
|
|
|
|
| 4027 |
ngroups, method, group_df, indiv_df,
|
| 4028 |
chat_history, log_history, state):
|
| 4029 |
if state is None:
|
| 4030 |
+
yield chat_history, log_history, state, gr.update(), _todo_update(state), gr.update(), gr.update()
|
| 4031 |
return
|
| 4032 |
|
| 4033 |
# 群組數量跟實際上傳分組是否一致:只有情境3/4才會顯示這個選項,
|
|
|
|
| 4045 |
)
|
| 4046 |
chat_history = chat_history + [_assistant_msg(warn_msg)]
|
| 4047 |
log_history = _log_append(log_history, "⚠️ 群組數量與上傳檔案不一致")
|
| 4048 |
+
yield (chat_history, log_history, state, gr.update(visible=True),
|
| 4049 |
+
_todo_update(state), gr.update(), gr.update())
|
| 4050 |
return
|
| 4051 |
|
| 4052 |
state["user_metadata"] = _compile_metadata(state, title, author, lang, pubyear,
|
|
|
|
| 4055 |
# 在主對話視窗立即顯示「開始分析」訊息,避免長時間運算期間畫面看起來像沒有反應
|
| 4056 |
chat_history = chat_history + [_assistant_msg(_ANALYSIS_START_MSG)]
|
| 4057 |
yield (chat_history, log_history, state, gr.update(visible=False),
|
| 4058 |
+
_todo_update(state), _accordion_update(state, log_history), _computing_update(state))
|
| 4059 |
+
for ch, lh, st, todo, acc, comp in _run_computation(chat_history, log_history, state):
|
| 4060 |
chat_history, log_history, state = ch, lh, st
|
| 4061 |
+
yield chat_history, log_history, state, gr.update(visible=False), todo, acc, comp
|
| 4062 |
|
| 4063 |
def _lock_meta():
|
| 4064 |
return gr.update(interactive=False), gr.update(interactive=False)
|
|
|
|
| 4073 |
inputs=[meta_title, meta_author, meta_lang, meta_pubyear, meta_version,
|
| 4074 |
meta_ngroups, meta_method, meta_group_df, meta_indiv_df,
|
| 4075 |
chatbot, exec_log, session_state],
|
| 4076 |
+
outputs=[chatbot, exec_log, session_state, metadata_row, app_header_html,
|
| 4077 |
+
exec_log_accordion, computing_html],
|
| 4078 |
).then(
|
| 4079 |
fn=_unlock_meta, inputs=None, outputs=[meta_confirm_btn, meta_cancel_btn],
|
| 4080 |
).then(fn=_populate_tabs, inputs=[session_state], outputs=_TAB_OUTPUTS)
|
| 4081 |
|
| 4082 |
def on_metadata_skip(chat_history, log_history, state):
|
| 4083 |
if state is None:
|
| 4084 |
+
yield chat_history, log_history, state, gr.update(), _todo_update(state), gr.update(), gr.update()
|
| 4085 |
return
|
| 4086 |
state["user_metadata"] = state.get("user_metadata", "") or "(使用者未提供語料 Metadata 說明)"
|
| 4087 |
log_history = _log_append(log_history, "⏭️ 已略過 Metadata,直接開始分析")
|
| 4088 |
chat_history = chat_history + [_assistant_msg(_ANALYSIS_START_MSG)]
|
| 4089 |
yield (chat_history, log_history, state, gr.update(visible=False),
|
| 4090 |
+
_todo_update(state), _accordion_update(state, log_history), _computing_update(state))
|
| 4091 |
+
for ch, lh, st, todo, acc, comp in _run_computation(chat_history, log_history, state):
|
| 4092 |
chat_history, log_history, state = ch, lh, st
|
| 4093 |
+
yield chat_history, log_history, state, gr.update(visible=False), todo, acc, comp
|
| 4094 |
|
| 4095 |
meta_cancel_btn.click(
|
| 4096 |
fn=_lock_meta, inputs=None, outputs=[meta_confirm_btn, meta_cancel_btn],
|
| 4097 |
).then(
|
| 4098 |
fn=on_metadata_skip,
|
| 4099 |
inputs=[chatbot, exec_log, session_state],
|
| 4100 |
+
outputs=[chatbot, exec_log, session_state, metadata_row, app_header_html,
|
| 4101 |
+
exec_log_accordion, computing_html],
|
| 4102 |
).then(
|
| 4103 |
fn=_unlock_meta, inputs=None, outputs=[meta_confirm_btn, meta_cancel_btn],
|
| 4104 |
).then(fn=_populate_tabs, inputs=[session_state], outputs=_TAB_OUTPUTS)
|