cwadayi commited on
Commit
ebf8ad6
·
verified ·
1 Parent(s): 2dcae4b

Update ui/layouts.py

Browse files
Files changed (1) hide show
  1. ui/layouts.py +68 -69
ui/layouts.py CHANGED
@@ -58,84 +58,83 @@ def create_ui(visit_count_html: str, theme: gr.Theme):
58
  """
59
  )
60
 
61
- # --- 主導覽列 Tab 容器 ---
62
- with gr.Row(variant="panel", elem_id="main-nav-tabs"):
63
- with gr.Tabs(selected=0):
64
-
65
- with gr.TabItem("🎯 課程目標"):
66
- gr.Markdown(content.course_goals_md)
67
 
68
- with gr.TabItem("🗓️ 課程進度"):
69
- gr.Markdown("### 每週課程安排")
70
- gr.DataFrame(data.schedule_df, wrap=True)
71
 
72
- with gr.TabItem("💯 成績計算"):
73
- gr.Markdown(content.grading_policy_md)
74
 
75
- with gr.TabItem("🚀 互動體驗區 (程式碼實驗室)"):
76
- gr.Markdown("## 🚀 互動程式碼實驗室")
77
- gr.Markdown("歡迎來到這裡!直接修改下方的 Python 程式碼,點擊「執行」,即可在右側看到成果。這是學習程式與地球物理最直接的方式!")
78
- gr.Info("注意:執行環境已受限,僅支援資料視覺化相關操作。請勿嘗試檔案讀寫或網路請求。")
79
 
80
- with gr.Accordion("🌍 地圖繪製實驗室 (PyGMT/Cartopy 概念)", open=True):
81
- with gr.Row():
82
- with gr.Column(scale=2):
83
- gr.Markdown("### 說明\n這段程式碼使用 `cartopy` 和 `matplotlib` 函式庫來繪製地理地圖。\n\n**您可以試著:**\n1. 修改 `center_lon`, `center_lat` 來改變地圖中心。\n2. 調整 `extent_lon`, `extent_lat` 來縮放地圖。\n3. 將 `coastline_color` 改成 'red' 或其他顏色。\n4. **在 `symbols` 列表中新增或修改字典,來繪製自訂的符號(例如:標示您所在的城市)。**")
84
- map_code = gr.Code(label="可編輯的 Python 程式碼", value=defaults.DEFAULT_MAP_CODE, language="python", lines=25)
85
- map_run_button = gr.Button("執行程式碼", variant="primary")
86
- with gr.Column(scale=3):
87
- map_plot_output = gr.Plot(label="地圖輸出")
88
- map_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
89
-
90
- with gr.Accordion("📈 震波圖繪製實驗室 (ObsPy 概念)", open=False):
91
- with gr.Row():
92
- with gr.Column(scale=2):
93
- gr.Markdown("### 說明\n這段程式碼使用 `numpy` 產生模擬的地震波數據,並用 `matplotlib` 將其視覺化。\n\n**您可以試著:**\n1. 修改 `p_wave_arrival` 和 `s_wave_arrival` 來改變 P/S 波的抵達時間。\n2. 調整 `main_freq` 來改變地震波的頻率(數值越大,波形越密集)。\n3. 將 `decay_rate` 調小,觀察振幅衰減變慢的效果。")
94
- seismo_code = gr.Code(label="可編輯的 Python 程式碼", value=defaults.DEFAULT_SEISMO_CODE, language="python", lines=25)
95
- seismo_run_button = gr.Button("執行程式碼", variant="primary")
96
- with gr.Column(scale=3):
97
- seismo_plot_output = gr.Plot(label="震波圖輸出")
98
- seismo_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
99
 
100
- with gr.TabItem("🤖 AI 課程助教"):
101
- with gr.Group():
102
- gr.Markdown("### 🤖 AI 課程助教 (知識庫 & 即時資訊強化版)")
103
- gr.Markdown("""
104
- 歡迎使用課程 AI 助教!我整合了靜態的課程知識與多種即時資訊來源,您可以隨時向我提問。
105
 
106
- ---
107
-
108
- #### 📚 **課程知識庫**
109
- 我可以回答關於本課程的各種問題,例如:`「這門課的評分標準是什麼?」`
110
 
111
- ---
112
-
113
- #### ⚡ **即時資訊查詢**
114
- 我還能幫您查詢最新的動態資訊,試著問我:
115
- - **📰 今日新聞**:`「今天有什麼重要新聞?」`
116
- - **🚨 地震報告**:`「最新的 CWA 顯著地震報告」` 或 `「最近全球有哪些大地震?」`
117
- - **📢 災害預警**:`「現在有地震預警嗎?」`
118
-
119
- ---
120
 
121
- #### 🔎 **進階地震查詢**
122
- 您也可以指定日期與規模來查詢全球地震紀錄,請**完全依照以下格式**提問:
123
- - `查詢 2024-04-01 到 2024-04-07 規模 6.0 以上地震`
124
- """)
125
-
126
- custom_textbox = gr.Textbox(
127
- placeholder="對課程有什麼問題嗎?或查詢即時資訊...",
128
- show_label=False,
129
- container=False,
130
- )
131
 
132
- gr.ChatInterface(
133
- callbacks.ai_chatbot_with_kb,
134
- chatbot=gr.Chatbot(height=450, type="messages", avatar_images=(None, "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")),
135
- title="課程AI助教",
136
- description="由結構化知識庫與即時工具驅動的問答機器人",
137
- textbox=custom_textbox,
138
- )
139
 
140
  # --- 連接按鈕與後端執行函式 ---
141
  map_run_button.click(
 
58
  """
59
  )
60
 
61
+ # --- 主導覽列 Tab 容器 (已移除多餘的 gr.Row) ---
62
+ with gr.Tabs(selected=0):
63
+
64
+ with gr.TabItem("🎯 課程目標"):
65
+ gr.Markdown(content.course_goals_md)
 
66
 
67
+ with gr.TabItem("🗓️ 課程進度"):
68
+ gr.Markdown("### 每週課程安排")
69
+ gr.DataFrame(data.schedule_df, wrap=True)
70
 
71
+ with gr.TabItem("💯 成績計算"):
72
+ gr.Markdown(content.grading_policy_md)
73
 
74
+ with gr.TabItem("🚀 互動體驗區 (程式碼實驗室)"):
75
+ gr.Markdown("## 🚀 互動程式碼實驗室")
76
+ gr.Markdown("歡迎來到這裡!直接修改下方的 Python 程式碼,點擊「執行」,即可在右側看到成果。這是學習程式與地球物理最直接的方式!")
77
+ gr.Info("注意:執行環境已受限,僅支援資料視覺化相關操作。請勿嘗試檔案讀寫或網路請求。")
78
 
79
+ with gr.Accordion("🌍 地圖繪製實驗室 (PyGMT/Cartopy 概念)", open=True):
80
+ with gr.Row():
81
+ with gr.Column(scale=2):
82
+ gr.Markdown("### 說明\n這段程式碼使用 `cartopy` 和 `matplotlib` 函式庫來繪製地理地圖。\n\n**您可以試著:**\n1. 修改 `center_lon`, `center_lat` 來改變地圖中心。\n2. 調整 `extent_lon`, `extent_lat` 來縮放地圖。\n3. 將 `coastline_color` 改成 'red' 或其他顏色。\n4. **在 `symbols` 列表中新增或修改字典,來繪製自訂的符號(例如:標示您所在的城市)。**")
83
+ map_code = gr.Code(label="可編輯的 Python 程式碼", value=defaults.DEFAULT_MAP_CODE, language="python", lines=25)
84
+ map_run_button = gr.Button("執行程式碼", variant="primary")
85
+ with gr.Column(scale=3):
86
+ map_plot_output = gr.Plot(label="地圖輸出")
87
+ map_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
88
+
89
+ with gr.Accordion("📈 震波圖繪製實驗室 (ObsPy 概念)", open=False):
90
+ with gr.Row():
91
+ with gr.Column(scale=2):
92
+ gr.Markdown("### 說明\n這段程式碼使用 `numpy` 產生模擬的地震波數據,並用 `matplotlib` 將其視覺化。\n\n**您可以試著:**\n1. 修改 `p_wave_arrival` 和 `s_wave_arrival` 來改變 P/S 波的抵達時間。\n2. 調整 `main_freq` 來改變地震波的頻率(數值越大,波形越密集)。\n3. 將 `decay_rate` 調小,觀察振幅衰減變慢的效果。")
93
+ seismo_code = gr.Code(label="可編輯的 Python 程式碼", value=defaults.DEFAULT_SEISMO_CODE, language="python", lines=25)
94
+ seismo_run_button = gr.Button("執行程式碼", variant="primary")
95
+ with gr.Column(scale=3):
96
+ seismo_plot_output = gr.Plot(label="震波圖輸出")
97
+ seismo_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
98
 
99
+ with gr.TabItem("🤖 AI 課程助教"):
100
+ with gr.Group():
101
+ gr.Markdown("### 🤖 AI 課程助教 (知識庫 & 即時資訊強化版)")
102
+ gr.Markdown("""
103
+ 歡迎使用課程 AI 助教!我整合了靜態的課程知識與多種即時資訊來源,您可以隨時向我提問。
104
 
105
+ ---
106
+
107
+ #### 📚 **課程知識庫**
108
+ 我可以回答關於本課程的各種問題,例如:`「這門課的評分標準是什麼?」`
109
 
110
+ ---
111
+
112
+ #### ⚡ **即時資訊查詢**
113
+ 我還能幫您查詢最新的動態資訊,試著問我:
114
+ - **📰 今日新聞**:`「今天有什麼重要新聞?」`
115
+ - **🚨 地震報告**:`「最新的 CWA 顯著地震報告」` 或 `「最近全球有哪些大地震?」`
116
+ - **📢 災害預警**:`「現在有地震預警嗎?」`
117
+
118
+ ---
119
 
120
+ #### 🔎 **進階地震查詢**
121
+ 您也可以指定日期與規模來查詢全球地震紀錄,請**完全依照以下格式**提問:
122
+ - `查詢 2024-04-01 到 2024-04-07 規模 6.0 以上地震`
123
+ """)
124
+
125
+ custom_textbox = gr.Textbox(
126
+ placeholder="對課程有什麼問題嗎?或查詢即時資訊...",
127
+ show_label=False,
128
+ container=False,
129
+ )
130
 
131
+ gr.ChatInterface(
132
+ callbacks.ai_chatbot_with_kb,
133
+ chatbot=gr.Chatbot(height=450, type="messages", avatar_images=(None, "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")),
134
+ title="課程AI助教",
135
+ description="由結構化知識庫與即時工具驅動的問答機器人",
136
+ textbox=custom_textbox,
137
+ )
138
 
139
  # --- 連接按鈕與後端執行函式 ---
140
  map_run_button.click(