cwadayi commited on
Commit
094197b
·
verified ·
1 Parent(s): 08d8bc9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +160 -0
app.py ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": "折射震測展示 (2)", "url": "https://huggingface.co/spaces/cwadayi/Refraction_3"},
32
+ {"title": "重力異常展示", "url": "https://huggingface.co/spaces/cwadayi/Gravity"}
33
+ ]
34
+ }
35
+
36
+ # 2. 自訂 CSS 樣式
37
+ # 這裡我們模仿 V1 靜態頁面的標頭樣式,並美化按鈕
38
+ css = """
39
+ /* 模仿 V1 靜態頁面的標頭 */
40
+ #main-header {
41
+ background: linear-gradient(135deg, #2c3e50, #34495e);
42
+ padding: 2rem 1.5rem;
43
+ border-bottom: 5px solid #1abc9c;
44
+ }
45
+ #main-header h1 {
46
+ font-size: 2.8rem;
47
+ font-weight: 700;
48
+ color: #ffffff;
49
+ text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
50
+ margin-bottom: 0.5rem;
51
+ text-align: center;
52
+ }
53
+ #main-header p {
54
+ font-size: 1.2rem;
55
+ color: #ecf0f1;
56
+ max-width: 600px;
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;
73
+ border-radius: 8px !important;
74
+ transition: background-color 0.3s ease, transform 0.2s ease !important;
75
+ }
76
+ .project-button a:hover {
77
+ background-color: #2980b9 !important;
78
+ transform: scale(1.03);
79
+ }
80
+
81
+ /* 頁腳樣式 */
82
+ #footer {
83
+ text-align: center;
84
+ color: #777;
85
+ font-size: 0.9rem;
86
+ margin-top: 2rem;
87
+ }
88
+ """
89
+
90
+ # 3. 使用 gr.Blocks() 建構介面
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>一系列運用 Hugging Face Space 部署的地球科學與地震應用程式,展現資料科學與網路技術的結合。</p>
100
+ """
101
+ )
102
+
103
+ # 介紹區
104
+ with gr.Accordion("🚀 關於 Hugging Face Spaces (點我展開)", open=False):
105
+ with gr.Row():
106
+ with gr.Column():
107
+ gr.Markdown(
108
+ """
109
+ ### 什麼是 Hugging Face Spaces?
110
+ Hugging Face Spaces 是一個由 Hugging Face 提供的免費平台,讓開發者和創作者可以輕鬆地建立、分享和展示他們的機器學習 Demo 或網頁應用程式。
111
+
112
+ 它就像是 AI 應用的「YouTube」!您可以使用 Gradio、Streamlit 等 Python 套件快速打造互動介面,或者部署靜態網頁 (HTML/CSS/JS),甚至運行 Docker 容器。
113
+ """
114
+ )
115
+ with gr.Column():
116
+ gr.Markdown(
117
+ """
118
+ ### 🚀 如何部署 Gradio 應用程式?
119
+ **這本身就是一個 Gradio 應用程式!** 部署它非常簡單:
120
+ 1. 在 Hugging Face 建立一個新 Space。
121
+ 2. 選擇 SDK:選擇 **"Gradio"** (這也是預設選項)。
122
+ 3. 建立 Space 後,點選 "Files and versions" 分頁。
123
+ 4. 建立一個名為 `app.py` 的檔案。
124
+ 5. **將這份 Python 程式碼**貼到 `app.py` 中並提交。
125
+ 6. **完成!** 您的Gradio應用程式將自動建置並上線。
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'],
147
+ elem_classes="project-button"
148
+ )
149
+
150
+ # 頁腳
151
+ gr.Markdown(
152
+ """
153
+ ---
154
+ <p id="footer">此頁面由 Gemini 協助生成,展示 "1022 中央地科演講" 中的 Hugging Face 專案。</p>
155
+ """
156
+ )
157
+
158
+ # 4. 啟動應用程式
159
+ if __name__ == "__main__":
160
+ demo.launch()