Spaces:
Sleeping
Sleeping
Upload 9 files
Browse files- app.py +11 -5
- ui/layouts.py +23 -16
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
from core.visits import get_and_update_visits
|
| 4 |
from ui.layouts import create_ui
|
| 5 |
|
| 6 |
-
# ---
|
| 7 |
custom_theme = gr.themes.Soft(
|
| 8 |
primary_hue="blue",
|
| 9 |
secondary_hue="cyan",
|
|
@@ -12,15 +12,21 @@ custom_theme = gr.themes.Soft(
|
|
| 12 |
radius_size=gr.themes.sizes.radius_md,
|
| 13 |
).set(
|
| 14 |
# Custom colors
|
| 15 |
-
body_background_fill="#F0F4F8",
|
| 16 |
-
block_background_fill="white",
|
| 17 |
-
block_border_width="1px",
|
| 18 |
-
block_shadow="*shadow_drop_lg",
|
| 19 |
|
| 20 |
# Custom button style
|
| 21 |
button_primary_background_fill="*primary_500",
|
| 22 |
button_primary_background_fill_hover="*primary_400",
|
| 23 |
button_primary_text_color="white",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
|
| 26 |
# --- 2. Update site visit count on startup ---
|
|
|
|
| 3 |
from core.visits import get_and_update_visits
|
| 4 |
from ui.layouts import create_ui
|
| 5 |
|
| 6 |
+
# --- 1. Define a new custom theme for better aesthetics ---
|
| 7 |
custom_theme = gr.themes.Soft(
|
| 8 |
primary_hue="blue",
|
| 9 |
secondary_hue="cyan",
|
|
|
|
| 12 |
radius_size=gr.themes.sizes.radius_md,
|
| 13 |
).set(
|
| 14 |
# Custom colors
|
| 15 |
+
body_background_fill="#F0F4F8",
|
| 16 |
+
block_background_fill="white",
|
| 17 |
+
block_border_width="1px",
|
| 18 |
+
block_shadow="*shadow_drop_lg",
|
| 19 |
|
| 20 |
# Custom button style
|
| 21 |
button_primary_background_fill="*primary_500",
|
| 22 |
button_primary_background_fill_hover="*primary_400",
|
| 23 |
button_primary_text_color="white",
|
| 24 |
+
|
| 25 |
+
# --- ✨ ADDED: Style for input textbox to make it more visible ---
|
| 26 |
+
input_background_fill="white",
|
| 27 |
+
input_border_color="*neutral_200",
|
| 28 |
+
input_shadow="*shadow_drop",
|
| 29 |
+
input_border_width="1.5px", # Slightly thicker border
|
| 30 |
)
|
| 31 |
|
| 32 |
# --- 2. Update site visit count on startup ---
|
ui/layouts.py
CHANGED
|
@@ -14,31 +14,22 @@ def create_ui(visit_count_html: str, theme: gr.Theme):
|
|
| 14 |
|
| 15 |
# --- Main UI Layout ---
|
| 16 |
with gr.Blocks(theme=theme, title="地球物理學與AI應用") as demo:
|
| 17 |
-
#
|
| 18 |
gr.Markdown(visit_count_html)
|
| 19 |
-
|
| 20 |
-
# --- Introduction Section ---
|
| 21 |
gr.Markdown(content.course_introduction_md)
|
| 22 |
|
| 23 |
-
# --- Main Tabs ---
|
| 24 |
with gr.Tabs():
|
| 25 |
-
|
| 26 |
-
# (其他 TabItem 維持不變)
|
| 27 |
with gr.TabItem("🎯 課程目標"):
|
| 28 |
gr.Markdown(content.course_goals_md)
|
| 29 |
-
|
| 30 |
with gr.TabItem("🗓️ 課程進度"):
|
| 31 |
gr.Markdown("### 每週課程安排")
|
| 32 |
gr.DataFrame(data.schedule_df, wrap=True)
|
| 33 |
-
|
| 34 |
with gr.TabItem("💯 成績計算"):
|
| 35 |
gr.Markdown(content.grading_policy_md)
|
| 36 |
-
|
| 37 |
with gr.TabItem("🚀 互動體驗區 (程式碼實驗室)"):
|
| 38 |
gr.Markdown("## 🚀 互動程式碼實驗室")
|
| 39 |
gr.Markdown("歡迎來到這裡!直接修改下方的 Python 程式碼,點擊「執行」,即可在右側看到成果。這是學習程式與地球物理最直接的方式!")
|
| 40 |
gr.Info("注意:執行環境已受限,僅支援資料視覺化相關操作。請勿嘗試檔案讀寫或網路請求。")
|
| 41 |
-
|
| 42 |
with gr.Accordion("🌍 地圖繪製實驗室 (PyGMT/Cartopy 概念)", open=True):
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column(scale=2):
|
|
@@ -48,7 +39,6 @@ def create_ui(visit_count_html: str, theme: gr.Theme):
|
|
| 48 |
with gr.Column(scale=3):
|
| 49 |
map_plot_output = gr.Plot(label="地圖輸出")
|
| 50 |
map_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
|
| 51 |
-
|
| 52 |
with gr.Accordion("📈 震波圖繪製實驗室 (ObsPy 概念)", open=False):
|
| 53 |
with gr.Row():
|
| 54 |
with gr.Column(scale=2):
|
|
@@ -59,18 +49,35 @@ def create_ui(visit_count_html: str, theme: gr.Theme):
|
|
| 59 |
seismo_plot_output = gr.Plot(label="震波圖輸出")
|
| 60 |
seismo_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
# --- ✨ Tab 5: AI Chatbot (with corrected layout component) --- ✨
|
| 64 |
with gr.TabItem("🤖 AI 課程助教"):
|
| 65 |
-
# Use gr.Group for backward compatibility with older Gradio versions
|
| 66 |
with gr.Group():
|
| 67 |
gr.Markdown("### 🤖 AI 課程助教 (知識庫強化版)")
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
gr.ChatInterface(
|
| 70 |
callbacks.ai_chatbot_with_kb,
|
| 71 |
chatbot=gr.Chatbot(height=450, type="messages", avatar_images=(None, "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")),
|
| 72 |
title="課程AI助教",
|
| 73 |
-
description="
|
|
|
|
| 74 |
)
|
| 75 |
|
| 76 |
# --- Connect Buttons to Backend Functions ---
|
|
|
|
| 14 |
|
| 15 |
# --- Main UI Layout ---
|
| 16 |
with gr.Blocks(theme=theme, title="地球物理學與AI應用") as demo:
|
| 17 |
+
# (此處程式碼不變,省略以節省篇幅)
|
| 18 |
gr.Markdown(visit_count_html)
|
|
|
|
|
|
|
| 19 |
gr.Markdown(content.course_introduction_md)
|
| 20 |
|
|
|
|
| 21 |
with gr.Tabs():
|
|
|
|
|
|
|
| 22 |
with gr.TabItem("🎯 課程目標"):
|
| 23 |
gr.Markdown(content.course_goals_md)
|
|
|
|
| 24 |
with gr.TabItem("🗓️ 課程進度"):
|
| 25 |
gr.Markdown("### 每週課程安排")
|
| 26 |
gr.DataFrame(data.schedule_df, wrap=True)
|
|
|
|
| 27 |
with gr.TabItem("💯 成績計算"):
|
| 28 |
gr.Markdown(content.grading_policy_md)
|
|
|
|
| 29 |
with gr.TabItem("🚀 互動體驗區 (程式碼實驗室)"):
|
| 30 |
gr.Markdown("## 🚀 互動程式碼實驗室")
|
| 31 |
gr.Markdown("歡迎來到這裡!直接修改下方的 Python 程式碼,點擊「執行」,即可在右側看到成果。這是學習程式與地球物理最直接的方式!")
|
| 32 |
gr.Info("注意:執行環境已受限,僅支援資料視覺化相關操作。請勿嘗試檔案讀寫或網路請求。")
|
|
|
|
| 33 |
with gr.Accordion("🌍 地圖繪製實驗室 (PyGMT/Cartopy 概念)", open=True):
|
| 34 |
with gr.Row():
|
| 35 |
with gr.Column(scale=2):
|
|
|
|
| 39 |
with gr.Column(scale=3):
|
| 40 |
map_plot_output = gr.Plot(label="地圖輸出")
|
| 41 |
map_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
|
|
|
|
| 42 |
with gr.Accordion("📈 震波圖繪製實驗室 (ObsPy 概念)", open=False):
|
| 43 |
with gr.Row():
|
| 44 |
with gr.Column(scale=2):
|
|
|
|
| 49 |
seismo_plot_output = gr.Plot(label="震波圖輸出")
|
| 50 |
seismo_console_output = gr.Textbox(label="執行結果 / 錯誤訊息", lines=8, interactive=False)
|
| 51 |
|
| 52 |
+
# --- ✨ Tab 5: AI Chatbot (with improved description and textbox) --- ✨
|
|
|
|
| 53 |
with gr.TabItem("🤖 AI 課程助教"):
|
|
|
|
| 54 |
with gr.Group():
|
| 55 |
gr.Markdown("### 🤖 AI 課程助教 (知識庫強化版)")
|
| 56 |
+
# --- ✨ 1. Strengthened description ---
|
| 57 |
+
gr.Markdown("""
|
| 58 |
+
歡迎使用課程 AI 助教!這裡整合了課程的關鍵資訊,您可以隨時向我提問。
|
| 59 |
+
|
| 60 |
+
**不知道從何問起嗎?試試看下面幾個方向:**
|
| 61 |
+
- **課程資訊**:`「這門課的評分標準是什麼?」`、`「期末專題有什麼建議主題?」`
|
| 62 |
+
- **技術工具**:`「什麼是版本控制?」`、`「Colab 和 Codespaces 有什麼差別?」`
|
| 63 |
+
- **地球物理**:`「解釋一下什麼是折射震測」`、`「地熱發電有什麼優點?」`
|
| 64 |
+
|
| 65 |
+
我能理解錯別字或不完全精確的提問,請隨意發問!
|
| 66 |
+
""")
|
| 67 |
+
|
| 68 |
+
# --- ✨ 2. Customized textbox for the chat interface ---
|
| 69 |
+
custom_textbox = gr.Textbox(
|
| 70 |
+
placeholder="對課程有什麼問題嗎?在這裡試著問我!",
|
| 71 |
+
show_label=False,
|
| 72 |
+
container=False, # Important to make it blend into the ChatInterface UI
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
gr.ChatInterface(
|
| 76 |
callbacks.ai_chatbot_with_kb,
|
| 77 |
chatbot=gr.Chatbot(height=450, type="messages", avatar_images=(None, "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")),
|
| 78 |
title="課程AI助教",
|
| 79 |
+
description="由結構化知識庫與模糊比對驅動的問答機器人",
|
| 80 |
+
textbox=custom_textbox, # Apply the custom textbox
|
| 81 |
)
|
| 82 |
|
| 83 |
# --- Connect Buttons to Backend Functions ---
|