cwadayi commited on
Commit
d584c36
·
verified ·
1 Parent(s): a024ea5

Update ui/layouts.py

Browse files
Files changed (1) hide show
  1. ui/layouts.py +19 -81
ui/layouts.py CHANGED
@@ -1,54 +1,25 @@
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
  with gr.Blocks(theme=theme, title="地球物理學") as demo:
16
- # --- 自訂頂部 Header ---
17
  gr.Markdown(
18
  """
19
  <style>
20
  .custom-header {
21
  background: linear-gradient(135deg, #005f73, #0a9396);
22
- color: #fff;
23
- padding: 4rem 2rem;
24
- text-align: center;
25
- border-radius: 0 0 20px 20px;
26
- margin-bottom: 2rem;
27
  box-shadow: 0 8px 15px rgba(0,0,0,0.1);
28
  }
29
- .custom-header h1 {
30
- font-size: 3.5rem;
31
- font-weight: 700;
32
- margin-bottom: 0.8rem;
33
- line-height: 1.2;
34
- }
35
- .custom-header p {
36
- font-size: 1.6rem;
37
- font-weight: 400;
38
- opacity: 0.9;
39
- margin-top: 0;
40
- }
41
  @media (max-width: 768px) {
42
- .custom-header {
43
- padding: 3rem 1rem;
44
- border-radius: 0;
45
- }
46
- .custom-header h1 {
47
- font-size: 2.5rem;
48
- }
49
- .custom-header p {
50
- font-size: 1.2rem;
51
- }
52
  }
53
  </style>
54
  <div class="custom-header">
@@ -58,10 +29,8 @@ 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
 
@@ -86,7 +55,7 @@ def create_ui(visit_count_html: str, theme: gr.Theme):
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):
@@ -97,47 +66,16 @@ def create_ui(visit_count_html: str, theme: gr.Theme):
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
- # --- Connect Buttons to Backend Functions ---
141
  map_run_button.click(
142
  fn=lambda code: callbacks.execute_user_code(code, "地圖繪製"),
143
  inputs=[map_code],
@@ -148,5 +86,5 @@ def create_ui(visit_count_html: str, theme: gr.Theme):
148
  inputs=[seismo_code],
149
  outputs=[seismo_plot_output, seismo_console_output]
150
  )
151
-
152
  return demo
 
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
  with gr.Blocks(theme=theme, title="地球物理學") as demo:
 
8
  gr.Markdown(
9
  """
10
  <style>
11
  .custom-header {
12
  background: linear-gradient(135deg, #005f73, #0a9396);
13
+ color: #fff; padding: 4rem 2rem; text-align: center;
14
+ border-radius: 0 0 20px 20px; margin-bottom: 2rem;
 
 
 
15
  box-shadow: 0 8px 15px rgba(0,0,0,0.1);
16
  }
17
+ .custom-header h1 { font-size: 3.5rem; font-weight: 700; margin-bottom: 0.8rem; line-height: 1.2; }
18
+ .custom-header p { font-size: 1.6rem; font-weight: 400; opacity: 0.9; margin-top: 0; }
 
 
 
 
 
 
 
 
 
 
19
  @media (max-width: 768px) {
20
+ .custom-header { padding: 3rem 1rem; border-radius: 0; }
21
+ .custom-header h1 { font-size: 2.5rem; }
22
+ .custom-header p { font-size: 1.2rem; }
 
 
 
 
 
 
 
23
  }
24
  </style>
25
  <div class="custom-header">
 
29
  """
30
  )
31
 
 
32
  with gr.Row(variant="panel", elem_id="main-nav-tabs"):
33
  with gr.Tabs(selected=0):
 
34
  with gr.TabItem("🎯 課程目標"):
35
  gr.Markdown(content.course_goals_md)
36
 
 
55
  with gr.Column(scale=3):
56
  map_plot_output = gr.Plot(label="地圖輸出")
57
  map_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
58
+
59
  with gr.Accordion("📈 震波圖繪製實驗室 (ObsPy 概念)", open=False):
60
  with gr.Row():
61
  with gr.Column(scale=2):
 
66
  seismo_plot_output = gr.Plot(label="震波圖輸出")
67
  seismo_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
68
 
69
+ # --- ✨ 第五個分頁「AI 課程助教」已被暫時註解掉 ---
70
+ # with gr.TabItem("🤖 AI 課程助教"):
71
+ # with gr.Group():
72
+ # gr.Markdown("### 🤖 AI 課程助教 (知識庫 & 即時資訊強化版)")
73
+ # gr.Markdown(''' ... ''')
74
+ # custom_textbox = gr.Textbox(...)
75
+ # gr.ChatInterface(...)
 
 
 
76
 
77
+ # --- 按鈕的 click 事件定義也需要對應調整 ---
78
+ # 由於 map_run_button 和 seismo_run_button 仍在,所以這部分保留
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  map_run_button.click(
80
  fn=lambda code: callbacks.execute_user_code(code, "地圖繪製"),
81
  inputs=[map_code],
 
86
  inputs=[seismo_code],
87
  outputs=[seismo_plot_output, seismo_console_output]
88
  )
89
+
90
  return demo