Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import re
|
| 3 |
import tempfile
|
| 4 |
from datetime import datetime, timedelta, timezone
|
|
|
|
| 5 |
|
| 6 |
import requests
|
| 7 |
import pandas as pd
|
|
@@ -175,7 +176,7 @@ def df_to_markdown(df, top_n=100):
|
|
| 175 |
return header + table
|
| 176 |
|
| 177 |
# -----------------------------
|
| 178 |
-
# OSM 地圖(Folium
|
| 179 |
# -----------------------------
|
| 180 |
def map_osm_html(df: pd.DataFrame):
|
| 181 |
if df.empty:
|
|
@@ -234,9 +235,10 @@ def map_osm_html(df: pd.DataFrame):
|
|
| 234 |
# fit bounds
|
| 235 |
m.fit_bounds([[d["Lat"].min(), d["Lon"].min()], [d["Lat"].max(), d["Lon"].max()]], padding=(20, 20))
|
| 236 |
|
| 237 |
-
#
|
| 238 |
html = m.get_root().render()
|
| 239 |
-
|
|
|
|
| 240 |
|
| 241 |
# -----------------------------
|
| 242 |
# 主流程
|
|
@@ -289,8 +291,7 @@ with gr.Blocks(fill_height=True) as demo:
|
|
| 289 |
run_btn = gr.Button("查詢", variant="primary")
|
| 290 |
|
| 291 |
table_out = gr.Markdown("(尚未查詢)")
|
| 292 |
-
#
|
| 293 |
-
map_out = gr.HTML(sanitize_html=False)
|
| 294 |
dl_btn = gr.DownloadButton(label="下載 CSV")
|
| 295 |
|
| 296 |
# 快速鍵
|
|
|
|
| 2 |
import re
|
| 3 |
import tempfile
|
| 4 |
from datetime import datetime, timedelta, timezone
|
| 5 |
+
import base64
|
| 6 |
|
| 7 |
import requests
|
| 8 |
import pandas as pd
|
|
|
|
| 176 |
return header + table
|
| 177 |
|
| 178 |
# -----------------------------
|
| 179 |
+
# OSM 地圖(Folium)輸出(以 data URL iframe 嵌入)
|
| 180 |
# -----------------------------
|
| 181 |
def map_osm_html(df: pd.DataFrame):
|
| 182 |
if df.empty:
|
|
|
|
| 235 |
# fit bounds
|
| 236 |
m.fit_bounds([[d["Lat"].min(), d["Lon"].min()], [d["Lat"].max(), d["Lon"].max()]], padding=(20, 20))
|
| 237 |
|
| 238 |
+
# 以 data URL 方式嵌入,避免被 HTML 清洗移除 <script>
|
| 239 |
html = m.get_root().render()
|
| 240 |
+
b64 = base64.b64encode(html.encode("utf-8")).decode("ascii")
|
| 241 |
+
return f'<iframe src="data:text/html;base64,{b64}" style="width:100%;height:520px;border:none;"></iframe>'
|
| 242 |
|
| 243 |
# -----------------------------
|
| 244 |
# 主流程
|
|
|
|
| 291 |
run_btn = gr.Button("查詢", variant="primary")
|
| 292 |
|
| 293 |
table_out = gr.Markdown("(尚未查詢)")
|
| 294 |
+
map_out = gr.HTML() # 不帶 sanitize_html 參數(舊版 Gradio 相容)
|
|
|
|
| 295 |
dl_btn = gr.DownloadButton(label="下載 CSV")
|
| 296 |
|
| 297 |
# 快速鍵
|