cwadayi commited on
Commit
0e520f2
·
verified ·
1 Parent(s): 9f453e4

Update ui/layouts.py

Browse files
Files changed (1) hide show
  1. ui/layouts.py +15 -143
ui/layouts.py CHANGED
@@ -1,155 +1,27 @@
1
- # ui/layouts.py
2
  import gradio as gr
3
- from config import content, data, defaults
4
- from core import callbacks
5
 
6
  def create_ui(visit_count_html: str, theme: gr.Theme):
7
  """
8
- Creates and returns the Gradio UI Blocks.
9
-
10
- Args:
11
- visit_count_html: The Markdown string to display the visit count.
12
- theme: The Gradio theme object to apply to the UI.
13
  """
14
-
15
- # --- Main UI Layout ---
16
- with gr.Blocks(theme=theme, title="地球物理學") as demo:
17
- # --- 自訂頂部 Header ---
18
- gr.Markdown(
19
- """
20
- <style>
21
- .custom-header {
22
- background: linear-gradient(135deg, #005f73, #0a9396);
23
- color: #fff;
24
- padding: 4rem 2rem;
25
- text-align: center;
26
- border-radius: 0 0 20px 20px;
27
- margin-bottom: 2rem;
28
- box-shadow: 0 8px 15px rgba(0,0,0,0.1);
29
- }
30
- .custom-header h1 {
31
- font-size: 3.5rem;
32
- font-weight: 700;
33
- margin-bottom: 0.8rem;
34
- line-height: 1.2;
35
- }
36
- .custom-header p {
37
- font-size: 1.6rem;
38
- font-weight: 400;
39
- opacity: 0.9;
40
- margin-top: 0;
41
- }
42
- @media (max-width: 768px) {
43
- .custom-header {
44
- padding: 3rem 1rem;
45
- border-radius: 0;
46
- }
47
- .custom-header h1 {
48
- font-size: 2.5rem;
49
- }
50
- .custom-header p {
51
- font-size: 1.2rem;
52
- }
53
- }
54
- </style>
55
- <div class="custom-header">
56
- <h1>地球物理概論</h1>
57
- <p>一個探索我們星球內在奧秘的互動式指南</p>
58
- </div>
59
- """
60
- )
61
 
62
- # --- 主導覽列 Tab 容器 ---
63
- with gr.Row(variant="panel", elem_id="main-nav-tabs"):
64
- with gr.Tabs(selected=0):
65
-
66
- with gr.TabItem("🎯 課程目標"):
67
- gr.Markdown(content.course_goals_md)
68
 
69
- with gr.TabItem("🗓️ 課程進度"):
70
- gr.Markdown("### 每週課程安排")
71
- gr.DataFrame(data.schedule_df, wrap=True)
72
 
73
- with gr.TabItem("💯 成績計算"):
74
- gr.Markdown(content.grading_policy_md)
75
 
76
- # --- ✨ 還原「互動體驗區」分頁 ---
77
- with gr.TabItem("🚀 互動體驗區 (程式碼實驗室)"):
78
- gr.Markdown("## 🚀 互動程式碼實驗室")
79
- gr.Markdown("歡迎來到這裡!直接修改下方的 Python 程式碼,點擊「執行」,即可在右側看到成果。這是學習程式與地球物理最直接的方式!")
80
- gr.Info("注意:執行環境已受限,僅支援資料視覺化相關操作。請勿嘗試檔案讀寫或網路請求。")
81
 
82
- with gr.Accordion("🌍 地圖繪製實驗室 (PyGMT/Cartopy 概念)", open=True):
83
- with gr.Row():
84
- with gr.Column(scale=2):
85
- gr.Markdown("### 說明\n這段程式碼使用 `cartopy` 和 `matplotlib` 函式庫來繪製地理地圖。\n\n**您可以試著:**\n1. 修改 `center_lon`, `center_lat` 來改變地圖中心。\n2. 調整 `extent_lon`, `extent_lat` 來縮放地圖。\n3. 將 `coastline_color` 改成 'red' 或其他顏色。\n4. **在 `symbols` 列表中新增或修改字典,來繪製自訂的符號(例如:標示您所在的城市)。**")
86
- map_code = gr.Code(label="可編輯的 Python 程式碼", value=defaults.DEFAULT_MAP_CODE, language="python", lines=25)
87
- map_run_button = gr.Button("執行程式碼", variant="primary")
88
- with gr.Column(scale=3):
89
- map_plot_output = gr.Plot(label="地圖輸出")
90
- map_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
91
-
92
- with gr.Accordion("📈 震波圖繪製實驗室 (ObsPy 概念)", open=False):
93
- with gr.Row():
94
- with gr.Column(scale=2):
95
- gr.Markdown("### 說明\n這段程式碼使用 `numpy` 產生模擬的地震波數據,並用 `matplotlib` 將其視覺化。\n\n**您可以試著:**\n1. 修改 `p_wave_arrival` 和 `s_wave_arrival` 來改變 P/S 波的抵達時間。\n2. 調整 `main_freq` 來改變地震波的頻率(數值越大,波形越密集)。\n3. 將 `decay_rate` 調小,觀察振幅衰減變慢的效果。")
96
- seismo_code = gr.Code(label="可編輯的 Python 程式碼", value=defaults.DEFAULT_SEISMO_CODE, language="python", lines=25)
97
- seismo_run_button = gr.Button("執行程式碼", variant="primary")
98
- with gr.Column(scale=3):
99
- seismo_plot_output = gr.Plot(label="震波圖輸出")
100
- seismo_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
101
 
102
- # --- ✨ 還原「AI 課程助教」分頁 ---
103
- with gr.TabItem("🤖 AI 課程助教"):
104
- with gr.Group():
105
- gr.Markdown("### 🤖 AI 課程助教 (知識庫 & 即時資訊強化版)")
106
- gr.Markdown("""
107
- 歡迎使用課程 AI 助教!我整合了靜態的課程知識與多種即時資訊來源,您可以隨時向我提問。
108
-
109
- ---
110
-
111
- #### 📚 **課程知識庫**
112
- 我可以回答關於本課程的各種問題,例如:`「這門課的評分標準是什麼?」`
113
-
114
- ---
115
-
116
- #### ⚡ **即時資訊查詢**
117
- 我還能幫您查詢最新的動態資訊,試著問我:
118
- - **📰 今日新聞**:`「今天有什麼重要新聞?」`
119
- - **🚨 地震報告**:`「最新的 CWA 顯著地震報告」` 或 `「最近全球有哪些大地震?」`
120
- - **📢 災害預警**:`「現在有地震預警嗎?」`
121
-
122
- ---
123
-
124
- #### 🔎 **進階地震查詢**
125
- 您也可以指定日期與規模來查詢全球地震紀錄,請**完全依照以下格式**提問:
126
- - `查詢 2024-04-01 到 2024-04-07 規模 6.0 以上地震`
127
- """)
128
-
129
- custom_textbox = gr.Textbox(
130
- placeholder="對課程有什麼問題嗎?或查詢即時資訊...",
131
- show_label=False,
132
- container=False,
133
- )
134
-
135
- gr.ChatInterface(
136
- callbacks.ai_chatbot_with_kb,
137
- chatbot=gr.Chatbot(height=450, type="messages", avatar_images=(None, "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")),
138
- title="課程AI助教",
139
- description="由結構化知識庫與即時工具驅動的問答機器人",
140
- textbox=custom_textbox,
141
- )
142
-
143
- # --- Connect Buttons to Backend Functions ---
144
- map_run_button.click(
145
- fn=lambda code: callbacks.execute_user_code(code, "地圖繪製"),
146
- inputs=[map_code],
147
- outputs=[map_plot_output, map_console_output]
148
- )
149
- seismo_run_button.click(
150
- fn=lambda code: callbacks.execute_user_code(code, "震波圖"),
151
- inputs=[seismo_code],
152
- outputs=[seismo_plot_output, seismo_console_output]
153
- )
154
-
155
  return demo
 
1
+ # ui/layouts.py (測試用的簡化版本)
2
  import gradio as gr
 
 
3
 
4
  def create_ui(visit_count_html: str, theme: gr.Theme):
5
  """
6
+ 這是一個極度簡化的 UI 版本,只用來測試 Tab 是否能正常顯示。
 
 
 
 
7
  """
8
+ with gr.Blocks(theme=theme, title="版面顯示測試") as demo:
9
+ gr.Markdown("# 除錯測試頁面")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
+ with gr.Tabs():
12
+ with gr.TabItem(" 分頁一:課程目標"):
13
+ gr.Markdown("如果能看到這個,代表分頁1正常。")
 
 
 
14
 
15
+ with gr.TabItem(" 分頁二:課程進度"):
16
+ gr.Markdown("如果能看到這個,代表分頁2正常。")
 
17
 
18
+ with gr.TabItem(" 分頁三:成績計算"):
19
+ gr.Markdown("如果能看到這個,代表分頁3正常。")
20
 
21
+ with gr.TabItem("✅ 分頁四:互動體驗區"):
22
+ gr.Markdown("如果能看到這個,代表分頁4正常。")
 
 
 
23
 
24
+ with gr.TabItem(" 分頁五:AI 課程助教"):
25
+ gr.Markdown("如果能看到這個,代表分頁5正常。")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  return demo