Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import folium
|
|
| 9 |
from folium.plugins import MarkerCluster
|
| 10 |
from branca.colormap import linear
|
| 11 |
|
| 12 |
-
#
|
| 13 |
try:
|
| 14 |
import tabulate as _tabulate # noqa: F401
|
| 15 |
HAS_TABULATE = True
|
|
@@ -192,11 +192,11 @@ def map_osm_html(df: pd.DataFrame):
|
|
| 192 |
center = [d["Lat"].mean(), d["Lon"].mean()]
|
| 193 |
m = folium.Map(location=center, zoom_start=6, tiles="OpenStreetMap", control_scale=True)
|
| 194 |
|
| 195 |
-
#
|
| 196 |
depth_min, depth_max = float(d["Depth_km"].min()), float(d["Depth_km"].max())
|
| 197 |
if depth_min == depth_max:
|
| 198 |
depth_min, depth_max = max(0.0, depth_min - 1), depth_max + 1
|
| 199 |
-
cmap = linear.
|
| 200 |
cmap.caption = "Depth (km)"
|
| 201 |
cmap.add_to(m)
|
| 202 |
|
|
@@ -252,7 +252,7 @@ def query_and_render(time_from, time_to, sort_order):
|
|
| 252 |
map_html = map_osm_html(df)
|
| 253 |
|
| 254 |
csv_bytes = df.to_csv(index=False).encode("utf-8-sig")
|
| 255 |
-
# 回傳 (bytes, filename)
|
| 256 |
return md, map_html, (csv_bytes, "CWA_E-A0015-001.csv")
|
| 257 |
except Exception as e:
|
| 258 |
return f"錯誤:{e}", "<div style='padding:8px'>(無法繪圖)</div>", None
|
|
@@ -285,7 +285,7 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 285 |
|
| 286 |
table_out = gr.Markdown("(尚未查詢)")
|
| 287 |
map_out = gr.HTML() # 嵌入 OSM 互動地圖
|
| 288 |
-
dl_btn = gr.DownloadButton(label="下載 CSV") # 不使用 file_name
|
| 289 |
|
| 290 |
# 快速鍵
|
| 291 |
btn_12h.click(lambda: set_time_range(hours=12), outputs=[time_from, time_to])
|
|
|
|
| 9 |
from folium.plugins import MarkerCluster
|
| 10 |
from branca.colormap import linear
|
| 11 |
|
| 12 |
+
# ------- 可選依賴偵測(表格美化;沒裝也能跑) -------
|
| 13 |
try:
|
| 14 |
import tabulate as _tabulate # noqa: F401
|
| 15 |
HAS_TABULATE = True
|
|
|
|
| 192 |
center = [d["Lat"].mean(), d["Lon"].mean()]
|
| 193 |
m = folium.Map(location=center, zoom_start=6, tiles="OpenStreetMap", control_scale=True)
|
| 194 |
|
| 195 |
+
# 顏色條(深度)— 以 viridis(通用寫法)取代 Viridis_08
|
| 196 |
depth_min, depth_max = float(d["Depth_km"].min()), float(d["Depth_km"].max())
|
| 197 |
if depth_min == depth_max:
|
| 198 |
depth_min, depth_max = max(0.0, depth_min - 1), depth_max + 1
|
| 199 |
+
cmap = linear.viridis.scale(depth_min, depth_max)
|
| 200 |
cmap.caption = "Depth (km)"
|
| 201 |
cmap.add_to(m)
|
| 202 |
|
|
|
|
| 252 |
map_html = map_osm_html(df)
|
| 253 |
|
| 254 |
csv_bytes = df.to_csv(index=False).encode("utf-8-sig")
|
| 255 |
+
# 回傳 (bytes, filename) 讓(舊)Gradio 也能指定檔名
|
| 256 |
return md, map_html, (csv_bytes, "CWA_E-A0015-001.csv")
|
| 257 |
except Exception as e:
|
| 258 |
return f"錯誤:{e}", "<div style='padding:8px'>(無法繪圖)</div>", None
|
|
|
|
| 285 |
|
| 286 |
table_out = gr.Markdown("(尚未查詢)")
|
| 287 |
map_out = gr.HTML() # 嵌入 OSM 互動地圖
|
| 288 |
+
dl_btn = gr.DownloadButton(label="下載 CSV") # 不使用 file_name 參數
|
| 289 |
|
| 290 |
# 快速鍵
|
| 291 |
btn_12h.click(lambda: set_time_range(hours=12), outputs=[time_from, time_to])
|