un2266 Claude Sonnet 5 commited on
Commit
e9047a4
·
1 Parent(s): 343eabe

Phase 5:結果分頁排版調整+缺口補件(凍結 _TAB_OUTPUTS 前最後一次結構變動)

Browse files

- 語言指標分析:下載按鈕移到頁面頂部(純排版順序調整,不動 _TAB_OUTPUTS)
- 差異性分析:圖表移到表格上方(同上,純排版順序調整)
- 差異性分析 sig_count=0 時,在標題文字附加空狀態說明,避免使用者誤以為
系統壞掉(Image 元件無法放文字,故不改 R[8] 本身,改在同段文字補充)
- 新增「監督式學習」「非監督式學習」兩個分頁的下載按鈕(tab_imp_file /
tab_cluster_file),後端本來就有產出對應檔案,只是沒接 UI;兩個新元件
append 到 _TAB_OUTPUTS 尾端(index 23-24),不插入既有 index 中間

已用 Playwright + 直接查 DOM 驗證:下載按鈕位置、空狀態文案、兩個新下載
按鈕的檔案連結皆正確;差異分析圖表/表格順序因測試資料 sig=0(圖表本來
就不會產生)無法用此資料視覺驗證,但屬純宣告順序調整、風險低。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app_agent.py +25 -6
app_agent.py CHANGED
@@ -2897,14 +2897,14 @@ def create_app():
2897
  # ══════════════════════════════════════════════════════════════
2898
  with gr.Tab("📊 語言指標分析", visible=False) as tab2:
2899
  tab_idx_md = gr.Markdown(_EMPTY_HINT)
2900
- tab_idx_df = gr.Dataframe(
2901
- label="指標計算結果",
2902
- interactive=False, visible=False,
2903
- )
2904
  tab_idx_file = gr.File(
2905
  label="下載檔案",
2906
  file_count="multiple", interactive=False, visible=False,
2907
  )
 
 
 
 
2908
 
2909
  with gr.Tab("📈 統計比較分析", visible=False) as tab3:
2910
  with gr.Tabs():
@@ -2922,11 +2922,11 @@ def create_app():
2922
  # 子分頁 2:差異性分析
2923
  with gr.Tab("2. 差異性分析"):
2924
  tab_diff_head = gr.Markdown(_EMPTY_HINT)
 
2925
  tab_diff_df = gr.Dataframe(
2926
  label="差異性分析",
2927
  interactive=False, visible=False,
2928
  )
2929
- tab_box_img = gr.Image(label="顯著指標箱形圖", visible=False)
2930
  tab_diff_file = gr.File(
2931
  label="下載差異性分析",
2932
  interactive=False, visible=False,
@@ -2942,6 +2942,10 @@ def create_app():
2942
  )
2943
  with gr.Column(scale=2):
2944
  tab_imp_img = gr.Image(label="特徵重要性圖", visible=False)
 
 
 
 
2945
  # 子分頁 4:非監督式學習
2946
  with gr.Tab("4. 非監督式學習"):
2947
  tab_clust_md = gr.Markdown(_EMPTY_HINT)
@@ -2955,6 +2959,10 @@ def create_app():
2955
  label="分群結果",
2956
  interactive=False, visible=False,
2957
  )
 
 
 
 
2958
  with gr.Tab("📝 LLM輔助分析", visible=False) as tab6:
2959
  tab_rpt_md = gr.Markdown(_EMPTY_HINT)
2960
  tab_rpt_file = gr.File(
@@ -2984,6 +2992,8 @@ def create_app():
2984
  tab_pca_img, tab_cluster_df, # 16-17
2985
  tab_rpt_md, tab_rpt_file, # 18-19 研究報告
2986
  tab2, tab3, tab6, # 20-22 (visibility)
 
 
2987
  ]
2988
  _N_TAB = len(_TAB_OUTPUTS)
2989
 
@@ -3037,8 +3047,11 @@ def create_app():
3037
  if diff_path.exists():
3038
  diff = pd.read_csv(str(diff_path))
3039
  sig = diff[diff.get('顯著', pd.Series()) != 'ns'] if '顯著' in diff.columns else pd.DataFrame()
 
 
 
3040
  R[6] = gr.update(
3041
- value=f"### 差異性分析\n共 **{len(diff)}** 個指標,其中 **{len(sig)}** 個達顯著差異(p < {ALPHA})。",
3042
  visible=True,
3043
  )
3044
  R[7] = gr.update(value=diff, visible=True)
@@ -3062,6 +3075,9 @@ def create_app():
3062
  R[11] = gr.update(value=imp, visible=True)
3063
  if imp_fig.exists():
3064
  R[12] = gr.update(value=str(imp_fig), visible=True)
 
 
 
3065
 
3066
  # ── 統計比較分析:非監督式學習(index 13-17)──────────────────
3067
  dendro_path = output_dir / "04a_dendrogram.png"
@@ -3085,6 +3101,9 @@ def create_app():
3085
  if cluster_path.exists():
3086
  cdf = pd.read_csv(str(cluster_path))
3087
  R[17] = gr.update(value=cdf, visible=True)
 
 
 
3088
 
3089
  # ── 研究報告(index 18-19)────────────────────────────────────
3090
  txt_files = sorted(output_dir.glob("LLM_Analysis-*.txt"), reverse=True)
 
2897
  # ══════════════════════════════════════════════════════════════
2898
  with gr.Tab("📊 語言指標分析", visible=False) as tab2:
2899
  tab_idx_md = gr.Markdown(_EMPTY_HINT)
 
 
 
 
2900
  tab_idx_file = gr.File(
2901
  label="下載檔案",
2902
  file_count="multiple", interactive=False, visible=False,
2903
  )
2904
+ tab_idx_df = gr.Dataframe(
2905
+ label="指標計算結果",
2906
+ interactive=False, visible=False,
2907
+ )
2908
 
2909
  with gr.Tab("📈 統計比較分析", visible=False) as tab3:
2910
  with gr.Tabs():
 
2922
  # 子分頁 2:差異性分析
2923
  with gr.Tab("2. 差異性分析"):
2924
  tab_diff_head = gr.Markdown(_EMPTY_HINT)
2925
+ tab_box_img = gr.Image(label="顯著指標箱形圖", visible=False)
2926
  tab_diff_df = gr.Dataframe(
2927
  label="差異性分析",
2928
  interactive=False, visible=False,
2929
  )
 
2930
  tab_diff_file = gr.File(
2931
  label="下載差異性分析",
2932
  interactive=False, visible=False,
 
2942
  )
2943
  with gr.Column(scale=2):
2944
  tab_imp_img = gr.Image(label="特徵重要性圖", visible=False)
2945
+ tab_imp_file = gr.File(
2946
+ label="下載監督式學習",
2947
+ interactive=False, visible=False,
2948
+ )
2949
  # 子分頁 4:非監督式學習
2950
  with gr.Tab("4. 非監督式學習"):
2951
  tab_clust_md = gr.Markdown(_EMPTY_HINT)
 
2959
  label="分群結果",
2960
  interactive=False, visible=False,
2961
  )
2962
+ tab_cluster_file = gr.File(
2963
+ label="下載非監督式學習",
2964
+ interactive=False, visible=False,
2965
+ )
2966
  with gr.Tab("📝 LLM輔助分析", visible=False) as tab6:
2967
  tab_rpt_md = gr.Markdown(_EMPTY_HINT)
2968
  tab_rpt_file = gr.File(
 
2992
  tab_pca_img, tab_cluster_df, # 16-17
2993
  tab_rpt_md, tab_rpt_file, # 18-19 研究報告
2994
  tab2, tab3, tab6, # 20-22 (visibility)
2995
+ tab_imp_file, tab_cluster_file, # 23-24 新增下載按鈕(僅能往尾端加,
2996
+ # 不可插入既有 index 中間,見程式工作守則)
2997
  ]
2998
  _N_TAB = len(_TAB_OUTPUTS)
2999
 
 
3047
  if diff_path.exists():
3048
  diff = pd.read_csv(str(diff_path))
3049
  sig = diff[diff.get('顯著', pd.Series()) != 'ns'] if '顯著' in diff.columns else pd.DataFrame()
3050
+ # sig=0 時不會產生箱形圖(見下方 box_path 判斷),若只留白使用者
3051
+ # 容易誤以為系統壞掉,這裡改在標題文字附加空狀態說明
3052
+ empty_note = "" if len(sig) > 0 else "\n\n本次分析未發現統計顯著的指標差異,因此未產生箱形圖。"
3053
  R[6] = gr.update(
3054
+ value=f"### 差異性分析\n共 **{len(diff)}** 個指標,其中 **{len(sig)}** 個達顯著差異(p < {ALPHA})。{empty_note}",
3055
  visible=True,
3056
  )
3057
  R[7] = gr.update(value=diff, visible=True)
 
3075
  R[11] = gr.update(value=imp, visible=True)
3076
  if imp_fig.exists():
3077
  R[12] = gr.update(value=str(imp_fig), visible=True)
3078
+ imp_dl = [str(p) for p in [imp_path, imp_fig] if p.exists()]
3079
+ if imp_dl:
3080
+ R[23] = gr.update(value=imp_dl, visible=True)
3081
 
3082
  # ── 統計比較分析:非監督式學習(index 13-17)──────────────────
3083
  dendro_path = output_dir / "04a_dendrogram.png"
 
3101
  if cluster_path.exists():
3102
  cdf = pd.read_csv(str(cluster_path))
3103
  R[17] = gr.update(value=cdf, visible=True)
3104
+ cluster_dl = [str(p) for p in [dendro_path, elbow_path, pca_fig_path, cluster_path] if p.exists()]
3105
+ if cluster_dl:
3106
+ R[24] = gr.update(value=cluster_dl, visible=True)
3107
 
3108
  # ── 研究報告(index 18-19)────────────────────────────────────
3109
  txt_files = sorted(output_dir.glob("LLM_Analysis-*.txt"), reverse=True)