cwadayi commited on
Commit
e66d8b0
·
verified ·
1 Parent(s): e2b17d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
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
@@ -252,8 +252,8 @@ 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
- # Gradio DownloadButton 接受 bytes 或路徑;這裡直接給 bytes
256
- return md, map_html, csv_bytes
257
  except Exception as e:
258
  return f"錯誤:{e}", "<div style='padding:8px'>(無法繪圖)</div>", None
259
 
@@ -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", value=None, file_name="CWA_E-A0015-001.csv")
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
 
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
259
 
 
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])