jeffliulab commited on
Commit
d7ba128
Β·
1 Parent(s): 491a86d

Fix startup timeout: lazy-load basemaps on first forecast instead of startup

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -15,7 +15,6 @@ from model_utils import run_forecast, load_model, AVAILABLE_MODELS
15
  from visualization import (
16
  get_static_maps,
17
  plot_temperature,
18
- plot_temperature_placeholder,
19
  )
20
 
21
  logging.basicConfig(level=logging.INFO)
@@ -243,6 +242,10 @@ def _hero_html(r: dict, cycle_str: str, forecast_str: str, model_label: str) ->
243
  def do_forecast(model_display: str, progress=gr.Progress()):
244
  model_name = _resolve_model(model_display)
245
 
 
 
 
 
246
  progress(0.02, desc="Finding latest HRRR cycle...")
247
  try:
248
  input_array, cycle_time = fetch_hrrr_input(
@@ -266,16 +269,11 @@ def do_forecast(model_display: str, progress=gr.Progress()):
266
  temp_fig = plot_temperature(input_array, r, cycle_str, forecast_str)
267
  status = f"Forecast complete β€” HRRR cycle {cycle_str}"
268
 
269
- return hero, temp_fig, status
270
 
271
 
272
  # ── Build UI ──────────────────────────────────────────────────────────
273
 
274
- # Pre-render static maps at import time
275
- logger.info("Rendering static basemaps...")
276
- _sat_fig, _street_fig = get_static_maps()
277
- _temp_placeholder = plot_temperature_placeholder()
278
- logger.info("Basemaps ready.")
279
 
280
  with gr.Blocks(title="Tufts Jumbo Weather Forecast", css=CUSTOM_CSS) as demo:
281
 
@@ -314,15 +312,15 @@ with gr.Blocks(title="Tufts Jumbo Weather Forecast", css=CUSTOM_CSS) as demo:
314
 
315
  with gr.Row(equal_height=True):
316
  sat_plot = gr.Plot(
317
- value=_sat_fig, label="Satellite",
318
  elem_classes=["map-cell"],
319
  )
320
  street_plot = gr.Plot(
321
- value=_street_fig, label="Reference Map",
322
  elem_classes=["map-cell"],
323
  )
324
  temp_plot = gr.Plot(
325
- value=_temp_placeholder, label="Temperature",
326
  elem_classes=["map-cell"],
327
  )
328
 
@@ -341,7 +339,7 @@ with gr.Blocks(title="Tufts Jumbo Weather Forecast", css=CUSTOM_CSS) as demo:
341
  run_btn.click(
342
  fn=do_forecast,
343
  inputs=[model_dd],
344
- outputs=[hero_html, temp_plot, status_bar],
345
  )
346
 
347
 
 
15
  from visualization import (
16
  get_static_maps,
17
  plot_temperature,
 
18
  )
19
 
20
  logging.basicConfig(level=logging.INFO)
 
242
  def do_forecast(model_display: str, progress=gr.Progress()):
243
  model_name = _resolve_model(model_display)
244
 
245
+ # Render static basemaps on first call (lazy load to avoid startup timeout)
246
+ progress(0.01, desc="Rendering basemaps...")
247
+ sat_fig, street_fig = get_static_maps()
248
+
249
  progress(0.02, desc="Finding latest HRRR cycle...")
250
  try:
251
  input_array, cycle_time = fetch_hrrr_input(
 
269
  temp_fig = plot_temperature(input_array, r, cycle_str, forecast_str)
270
  status = f"Forecast complete β€” HRRR cycle {cycle_str}"
271
 
272
+ return hero, sat_fig, street_fig, temp_fig, status
273
 
274
 
275
  # ── Build UI ──────────────────────────────────────────────────────────
276
 
 
 
 
 
 
277
 
278
  with gr.Blocks(title="Tufts Jumbo Weather Forecast", css=CUSTOM_CSS) as demo:
279
 
 
312
 
313
  with gr.Row(equal_height=True):
314
  sat_plot = gr.Plot(
315
+ label="Satellite",
316
  elem_classes=["map-cell"],
317
  )
318
  street_plot = gr.Plot(
319
+ label="Reference Map",
320
  elem_classes=["map-cell"],
321
  )
322
  temp_plot = gr.Plot(
323
+ label="Temperature",
324
  elem_classes=["map-cell"],
325
  )
326
 
 
339
  run_btn.click(
340
  fn=do_forecast,
341
  inputs=[model_dd],
342
+ outputs=[hero_html, sat_plot, street_plot, temp_plot, status_bar],
343
  )
344
 
345