prateeksharmacoder commited on
Commit
5db711c
·
1 Parent(s): 373050f

fix: inline Leaflet CSS/JS into gr.HTML value (Gradio 5 has no 'head'/'js_on_load' params)

Browse files
Files changed (1) hide show
  1. app.py +23 -19
app.py CHANGED
@@ -120,16 +120,8 @@ def save_tensor_as_geotiff(tensor, attrs, out_path, super_resolved=False, sr_fac
120
  DEFAULT_LAT = 39.39785676571274
121
  DEFAULT_LON = -0.3798517619438821
122
 
123
- LEAFLET_HEAD = """
124
- <link
125
- rel="stylesheet"
126
- href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"
127
- />
128
-
129
- <script
130
- src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js">
131
- </script>
132
- """
133
 
134
 
135
  # ============================================================
@@ -369,6 +361,24 @@ MAP_JS = MAP_JS.replace(
369
  str(DEFAULT_LON)
370
  )
371
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
 
373
  # ============================================================
374
  # CUSTOM CSS
@@ -924,15 +934,9 @@ with gr.Blocks(
924
  # ------------------------------------------------
925
 
926
  map_html = gr.HTML(
927
-
928
- # Value now contains the div that Leaflet will target
929
- value='<div id="terrativision-map"></div>',
930
-
931
- head=LEAFLET_HEAD,
932
-
933
- js_on_load=MAP_JS,
934
-
935
- # elem_id for the wrapping gr.HTML component itself
936
  elem_id="map-container-wrapper"
937
  )
938
 
 
120
  DEFAULT_LAT = 39.39785676571274
121
  DEFAULT_LON = -0.3798517619438821
122
 
123
+ # LEAFLET_HEAD removed — Gradio 5 gr.HTML does not support 'head'.
124
+ # Leaflet CSS/JS are inlined into MAP_HTML_VALUE below.
 
 
 
 
 
 
 
 
125
 
126
 
127
  # ============================================================
 
361
  str(DEFAULT_LON)
362
  )
363
 
364
+ # ============================================================
365
+ # COMPLETE MAP HTML
366
+ # Gradio 5 gr.HTML has no 'head' or 'js_on_load' parameters.
367
+ # Inline Leaflet CSS, Leaflet JS, the map div, and the init
368
+ # script all inside the value string.
369
+ # ============================================================
370
+ MAP_HTML_VALUE = f"""
371
+ <link rel="stylesheet"
372
+ href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
373
+ <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
374
+ <div id="terrativision-map"
375
+ style="width:100%;height:400px;border-radius:14px;
376
+ overflow:hidden;border:1px solid rgba(128,128,128,0.35);"></div>
377
+ <script>
378
+ {MAP_JS}
379
+ </script>
380
+ """
381
+
382
 
383
  # ============================================================
384
  # CUSTOM CSS
 
934
  # ------------------------------------------------
935
 
936
  map_html = gr.HTML(
937
+ # Leaflet CSS/JS + map div + init script all inlined.
938
+ # Gradio 5 gr.HTML does not support 'head' or 'js_on_load'.
939
+ value=MAP_HTML_VALUE,
 
 
 
 
 
 
940
  elem_id="map-container-wrapper"
941
  )
942