Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,54 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
# 1.
|
| 4 |
-
# 我們使用 Python 字典來組織所有分類和連結
|
| 5 |
projects_data = {
|
| 6 |
"🌊 地震與波形展示": [
|
| 7 |
-
{"title": "地震目錄搜尋 API", "url": "https://cwadayi-python-app.hf.space/"},
|
| 8 |
-
{"title": "地震預警訊息顯示", "url": "https://huggingface.co/spaces/cwadayi/streamlit_alarm_Taiwan"},
|
| 9 |
-
{"title": "PyGMT 震央繪圖展示", "url": "https://huggingface.co/spaces/cwadayi/streamlit_gmt_demo_new"},
|
| 10 |
-
{"title": "ObsPy 地震資料處理", "url": "https://huggingface.co/spaces/cwadayi/streamlit_obspy"}
|
| 11 |
],
|
| 12 |
"🛰️ 地震監測與資料應用": [
|
| 13 |
-
{"title": "Geiger 法地震定位展示", "url": "https://huggingface.co/spaces/cwadayi/streamlit_earthquake_location"},
|
| 14 |
-
{"title": "地震監測流程", "url": "https://huggingface.co/spaces/cwadayi/earthquake_monitoring"},
|
| 15 |
-
{"title": "Google Sheet 資料顯示", "url": "https://huggingface.co/spaces/cwadayi/Grafana_like_2"},
|
| 16 |
-
{"title": "PWS 地震預警顯示", "url": "https://cwadayi-app-show-pws.hf.space/cwa-earthquakes"},
|
| 17 |
-
{"title": "全球地震顯示", "url": "https://huggingface.co/spaces/cwadayi/streamlit"}
|
| 18 |
],
|
| 19 |
"💻 資料擷取與 API 應用": [
|
| 20 |
-
{"title": "LINE ROBOT 伺服器", "url": "https://huggingface.co/spaces/cwadayi/LINE-ROBOT"},
|
| 21 |
-
{"title": "震央分佈圖 (MCP-2)", "url": "https://huggingface.co/spaces/cwadayi/MCP-2"},
|
| 22 |
-
{"title": "PWS 資訊擷取", "url": "https://huggingface.co/spaces/cwadayi/MCP-pws"},
|
| 23 |
-
{"title": "USGS 地震資料 API", "url": "https://huggingface.co/spaces/cwadayi/Usgs_api_gemini"},
|
| 24 |
-
{"title": "CWA 地震資料 API", "url": "https://huggingface.co/spaces/cwadayi/CWA_API_chatgpt5_1"}
|
| 25 |
],
|
| 26 |
"🏫 地球物理課程與教材": [
|
| 27 |
-
{"title": "地球物理課程 (總覽)", "url": "https://huggingface.co/spaces/cwadayi/Geophysics_class"},
|
| 28 |
-
{"title": "地物課程網站 (Day1)", "url": "https://huggingface.co/spaces/cwadayi/Geophysics_day1"},
|
| 29 |
-
{"title": "地物課程網站 (Day2)", "url": "https://huggingface.co/spaces/cwadayi/Geophysics_day2"},
|
| 30 |
-
{"title": "折射震測展示", "url": "https://huggingface.co/spaces/cwadayi/Refraction_sdd"},
|
| 31 |
-
{"title": "折射震測展示 (
|
| 32 |
-
{"title": "重力異常展示", "url": "https://huggingface.co/spaces/cwadayi/Gravity"}
|
| 33 |
]
|
| 34 |
}
|
| 35 |
|
| 36 |
-
# 2.
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
css = """
|
| 39 |
-
/*
|
| 40 |
#main-header {
|
| 41 |
background: linear-gradient(135deg, #2c3e50, #34495e);
|
| 42 |
padding: 2rem 1.5rem;
|
|
@@ -57,16 +69,67 @@ css = """
|
|
| 57 |
margin: 0 auto;
|
| 58 |
text-align: center;
|
| 59 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
/*
|
| 62 |
.project-title h3 {
|
| 63 |
margin: 0;
|
| 64 |
-
padding: 0.5rem 0;
|
| 65 |
font-size: 1.2rem;
|
| 66 |
color: #2c3e50;
|
| 67 |
}
|
| 68 |
|
| 69 |
-
/*
|
| 70 |
.project-button a {
|
| 71 |
background-color: #3498db !important;
|
| 72 |
color: #ffffff !important;
|
|
@@ -78,7 +141,7 @@ css = """
|
|
| 78 |
transform: scale(1.03);
|
| 79 |
}
|
| 80 |
|
| 81 |
-
/*
|
| 82 |
#footer {
|
| 83 |
text-align: center;
|
| 84 |
color: #777;
|
|
@@ -87,20 +150,21 @@ css = """
|
|
| 87 |
}
|
| 88 |
"""
|
| 89 |
|
| 90 |
-
#
|
| 91 |
with gr.Blocks(css=css, title="地球物理 x Hugging Face 專案展示") as demo:
|
| 92 |
|
| 93 |
-
# 標頭區
|
| 94 |
-
# 我們使用 gr.Markdown 來渲染 HTML 標籤,並用 elem_id 套用 CSS
|
| 95 |
with gr.Row(elem_id="main-header"):
|
| 96 |
gr.Markdown(
|
| 97 |
"""
|
|
|
|
|
|
|
| 98 |
<h1>地球物理 x Hugging Face 專案展示</h1>
|
| 99 |
-
<p
|
| 100 |
"""
|
| 101 |
)
|
| 102 |
|
| 103 |
-
# 介紹區
|
| 104 |
with gr.Accordion("🚀 關於 Hugging Face Spaces (點我展開)", open=False):
|
| 105 |
with gr.Row():
|
| 106 |
with gr.Column():
|
|
@@ -126,21 +190,26 @@ with gr.Blocks(css=css, title="地球物理 x Hugging Face 專案展示") as dem
|
|
| 126 |
"""
|
| 127 |
)
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
# 專案列表區
|
| 130 |
-
gr.Markdown("##
|
| 131 |
|
| 132 |
-
# 動態生成所有專案
|
| 133 |
for category, items in projects_data.items():
|
| 134 |
-
# 每個分類都是一個可折疊的 Accordion
|
| 135 |
with gr.Accordion(category, open=True):
|
| 136 |
for item in items:
|
| 137 |
-
|
| 138 |
-
with gr.Row():
|
| 139 |
-
# 左側:專案標題
|
| 140 |
with gr.Column(scale=4):
|
| 141 |
gr.Markdown(f"### {item['title']}", elem_classes="project-title")
|
| 142 |
-
|
| 143 |
-
with gr.Column(scale=1):
|
| 144 |
gr.Button(
|
| 145 |
"前往應用 ↗",
|
| 146 |
link=item['url'],
|
|
@@ -150,11 +219,17 @@ with gr.Blocks(css=css, title="地球物理 x Hugging Face 專案展示") as dem
|
|
| 150 |
# 頁腳
|
| 151 |
gr.Markdown(
|
| 152 |
"""
|
| 153 |
-
---
|
| 154 |
<p id="footer">此頁面由 Gemini 協助生成,展示 "1022 中央地科演講" 中的 Hugging Face 專案。</p>
|
| 155 |
"""
|
| 156 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
-
#
|
| 159 |
if __name__ == "__main__":
|
| 160 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
|
| 4 |
+
# 1. [創意升級] 專案資料:為每個專案標題加入 Emoji
|
|
|
|
| 5 |
projects_data = {
|
| 6 |
"🌊 地震與波形展示": [
|
| 7 |
+
{"title": "📡 地震目錄搜尋 API", "url": "https://cwadayi-python-app.hf.space/"},
|
| 8 |
+
{"title": "⚠️ 地震預警訊息顯示", "url": "https://huggingface.co/spaces/cwadayi/streamlit_alarm_Taiwan"},
|
| 9 |
+
{"title": "🗺️ PyGMT 震央繪圖展示", "url": "https://huggingface.co/spaces/cwadayi/streamlit_gmt_demo_new"},
|
| 10 |
+
{"title": "📈 ObsPy 地震資料處理", "url": "https://huggingface.co/spaces/cwadayi/streamlit_obspy"}
|
| 11 |
],
|
| 12 |
"🛰️ 地震監測與資料應用": [
|
| 13 |
+
{"title": "📍 Geiger 法地震定位展示", "url": "https://huggingface.co/spaces/cwadayi/streamlit_earthquake_location"},
|
| 14 |
+
{"title": "🔍 地震監測流程 (擷取-撿拾-定位)", "url": "https://huggingface.co/spaces/cwadayi/earthquake_monitoring"},
|
| 15 |
+
{"title": "📊 Google Sheet 資料顯示 (類Grafana)", "url": "https://huggingface.co/spaces/cwadayi/Grafana_like_2"},
|
| 16 |
+
{"title": "🏠 PWS 地震預警顯示", "url": "https://cwadayi-app-show-pws.hf.space/cwa-earthquakes"},
|
| 17 |
+
{"title": "🌍 全球地震顯示 (Streamlit)", "url": "https://huggingface.co/spaces/cwadayi/streamlit"}
|
| 18 |
],
|
| 19 |
"💻 資料擷取與 API 應用": [
|
| 20 |
+
{"title": "💬 LINE ROBOT 伺服器", "url": "https://huggingface.co/spaces/cwadayi/LINE-ROBOT"},
|
| 21 |
+
{"title": "🗺️ 震央分佈圖 (MCP-2)", "url": "https://huggingface.co/spaces/cwadayi/MCP-2"},
|
| 22 |
+
{"title": "📥 PWS 資訊擷取", "url": "https://huggingface.co/spaces/cwadayi/MCP-pws"},
|
| 23 |
+
{"title": "🏛️ USGS 地震資料 API", "url": "https://huggingface.co/spaces/cwadayi/Usgs_api_gemini"},
|
| 24 |
+
{"title": "🇹🇼 CWA 地震資料 API", "url": "https://huggingface.co/spaces/cwadayi/CWA_API_chatgpt5_1"}
|
| 25 |
],
|
| 26 |
"🏫 地球物理課程與教材": [
|
| 27 |
+
{"title": "🎓 地球物理課程 (總覽)", "url": "https://huggingface.co/spaces/cwadayi/Geophysics_class"},
|
| 28 |
+
{"title": "📗 地物課程網站 (Day1)", "url": "https://huggingface.co/spaces/cwadayi/Geophysics_day1"},
|
| 29 |
+
{"title": "📘 地物課程網站 (Day2)", "url": "https://huggingface.co/spaces/cwadayi/Geophysics_day2"},
|
| 30 |
+
{"title": "📏 折射震測展示 (SDD)", "url": "https://huggingface.co/spaces/cwadayi/Refraction_sdd"},
|
| 31 |
+
{"title": "📐 折射震測展示 (Refraction 3)", "url": "https://huggingface.co/spaces/cwadayi/Refraction_3"},
|
| 32 |
+
{"title": "⚖️ 重力異常展示 (Bouguer & Free-air)", "url": "https://huggingface.co/spaces/cwadayi/Gravity"}
|
| 33 |
]
|
| 34 |
}
|
| 35 |
|
| 36 |
+
# 2. [創意升級] 隨機推���函式
|
| 37 |
+
def recommend_project():
|
| 38 |
+
"""從所有專案中隨機挑選一個並回傳 Markdown 格式的推薦"""
|
| 39 |
+
all_projects = [item for sublist in projects_data.values() for item in sublist]
|
| 40 |
+
recommendation = random.choice(all_projects)
|
| 41 |
+
|
| 42 |
+
# 回傳精美的 Markdown 格式
|
| 43 |
+
return f"""
|
| 44 |
+
### {recommendation['title']}
|
| 45 |
+
|
| 46 |
+
[**點此立即前往 🚀**]({recommendation['url']})
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
# 3. [創意升級] 自訂 CSS 樣式
|
| 50 |
css = """
|
| 51 |
+
/* 標頭樣式 */
|
| 52 |
#main-header {
|
| 53 |
background: linear-gradient(135deg, #2c3e50, #34495e);
|
| 54 |
padding: 2rem 1.5rem;
|
|
|
|
| 69 |
margin: 0 auto;
|
| 70 |
text-align: center;
|
| 71 |
}
|
| 72 |
+
/* 標頭圖片 */
|
| 73 |
+
#header-image {
|
| 74 |
+
width: 100%;
|
| 75 |
+
max-height: 250px; /* 限制最大高度 */
|
| 76 |
+
object-fit: cover; /* 圖片會被裁剪以填滿容器 */
|
| 77 |
+
border-radius: 12px;
|
| 78 |
+
margin-bottom: 1rem;
|
| 79 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.2);
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
/* 推薦按鈕 */
|
| 83 |
+
#recommend-button {
|
| 84 |
+
background: linear-gradient(135deg, #1abc9c, #16a085); /* 亮眼的青色漸層 */
|
| 85 |
+
color: white !important;
|
| 86 |
+
font-size: 1.1rem !important;
|
| 87 |
+
font-weight: bold !important;
|
| 88 |
+
border: none !important;
|
| 89 |
+
border-radius: 10px !important;
|
| 90 |
+
transition: all 0.3s ease !important;
|
| 91 |
+
}
|
| 92 |
+
#recommend-button:hover {
|
| 93 |
+
background: linear-gradient(135deg, #16a085, #1abc9c);
|
| 94 |
+
transform: scale(1.02);
|
| 95 |
+
box-shadow: 0 5px 15px rgba(22, 160, 133, 0.4);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
/* 推薦輸出框 */
|
| 99 |
+
#recommend-output {
|
| 100 |
+
border: 2px dashed #1abc9c;
|
| 101 |
+
border-radius: 10px;
|
| 102 |
+
padding: 1.5rem;
|
| 103 |
+
text-align: center;
|
| 104 |
+
background-color: #f8fdfc; /* 非常淺的青色背景 */
|
| 105 |
+
}
|
| 106 |
+
#recommend-output h3 {
|
| 107 |
+
margin-top: 0.5rem;
|
| 108 |
+
margin-bottom: 1.2rem;
|
| 109 |
+
color: #2c3e50;
|
| 110 |
+
font-size: 1.4rem;
|
| 111 |
+
}
|
| 112 |
+
#recommend-output a {
|
| 113 |
+
font-size: 1.1rem;
|
| 114 |
+
font-weight: bold;
|
| 115 |
+
color: #2980b9;
|
| 116 |
+
text-decoration: none;
|
| 117 |
+
transition: color 0.3s ease;
|
| 118 |
+
}
|
| 119 |
+
#recommend-output a:hover {
|
| 120 |
+
color: #3498db;
|
| 121 |
+
text-decoration: underline;
|
| 122 |
+
}
|
| 123 |
|
| 124 |
+
/* 專案標題 */
|
| 125 |
.project-title h3 {
|
| 126 |
margin: 0;
|
| 127 |
+
padding: 0.5rem 0;
|
| 128 |
font-size: 1.2rem;
|
| 129 |
color: #2c3e50;
|
| 130 |
}
|
| 131 |
|
| 132 |
+
/* 專案按鈕 */
|
| 133 |
.project-button a {
|
| 134 |
background-color: #3498db !important;
|
| 135 |
color: #ffffff !important;
|
|
|
|
| 141 |
transform: scale(1.03);
|
| 142 |
}
|
| 143 |
|
| 144 |
+
/* 頁腳 */
|
| 145 |
#footer {
|
| 146 |
text-align: center;
|
| 147 |
color: #777;
|
|
|
|
| 150 |
}
|
| 151 |
"""
|
| 152 |
|
| 153 |
+
# 4. [創意升級] 使用 gr.Blocks() 建構介面
|
| 154 |
with gr.Blocks(css=css, title="地球物理 x Hugging Face 專案展示") as demo:
|
| 155 |
|
| 156 |
+
# 標頭區 (加入圖片)
|
|
|
|
| 157 |
with gr.Row(elem_id="main-header"):
|
| 158 |
gr.Markdown(
|
| 159 |
"""
|
| 160 |
+
<img id="header-image" src="https://images.pexels.com/photos/220201/pexels-photo-220201.jpeg" alt="Abstract seismic waves banner">
|
| 161 |
+
|
| 162 |
<h1>地球物理 x Hugging Face 專案展示</h1>
|
| 163 |
+
<p>一個地球物理學家的數位百寶箱:探索一系列由 cwadayi 打造的地震與地科應用!</p>
|
| 164 |
"""
|
| 165 |
)
|
| 166 |
|
| 167 |
+
# 介紹區 (保持不變)
|
| 168 |
with gr.Accordion("🚀 關於 Hugging Face Spaces (點我展開)", open=False):
|
| 169 |
with gr.Row():
|
| 170 |
with gr.Column():
|
|
|
|
| 190 |
"""
|
| 191 |
)
|
| 192 |
|
| 193 |
+
# [創意升級] 隨機推薦區
|
| 194 |
+
gr.Markdown("---")
|
| 195 |
+
with gr.Blocks():
|
| 196 |
+
gr.Markdown("## ✨ 幸運推薦 ✨")
|
| 197 |
+
recommend_btn = gr.Button("不知道從何逛起? 點我隨機推薦一個專案!", elem_id="recommend-button")
|
| 198 |
+
recommend_out = gr.Markdown("點擊上方按鈕,讓我為您挑選一個有趣的專案!", elem_id="recommend-output")
|
| 199 |
+
gr.Markdown("---")
|
| 200 |
+
|
| 201 |
+
|
| 202 |
# 專案列表區
|
| 203 |
+
gr.Markdown("## 📚 專案總覽")
|
| 204 |
|
| 205 |
+
# 動態生成所有專案 (現在會顯示帶有 Emoji 的標題)
|
| 206 |
for category, items in projects_data.items():
|
|
|
|
| 207 |
with gr.Accordion(category, open=True):
|
| 208 |
for item in items:
|
| 209 |
+
with gr.Row(variant="panel", equal_height=True):
|
|
|
|
|
|
|
| 210 |
with gr.Column(scale=4):
|
| 211 |
gr.Markdown(f"### {item['title']}", elem_classes="project-title")
|
| 212 |
+
with gr.Column(scale=1, min_width=150):
|
|
|
|
| 213 |
gr.Button(
|
| 214 |
"前往應用 ↗",
|
| 215 |
link=item['url'],
|
|
|
|
| 219 |
# 頁腳
|
| 220 |
gr.Markdown(
|
| 221 |
"""
|
|
|
|
| 222 |
<p id="footer">此頁面由 Gemini 協助生成,展示 "1022 中央地科演講" 中的 Hugging Face 專案。</p>
|
| 223 |
"""
|
| 224 |
)
|
| 225 |
+
|
| 226 |
+
# 5. [創意升級] 綁定按鈕點擊事件
|
| 227 |
+
recommend_btn.click(
|
| 228 |
+
fn=recommend_project, # 點擊後呼叫的函式
|
| 229 |
+
inputs=None, # 沒有輸入
|
| 230 |
+
outputs=recommend_out # 輸出到 recommend_out (Markdown 元件)
|
| 231 |
+
)
|
| 232 |
|
| 233 |
+
# 6. 啟動應用程式
|
| 234 |
if __name__ == "__main__":
|
| 235 |
demo.launch()
|