Spaces:
Running
Running
Fix: remove eager live data load at startup to speed up Space init
Browse files
app.py
CHANGED
|
@@ -272,6 +272,8 @@ def constructor_standings(year_choice):
|
|
| 272 |
def load_live_predictions():
|
| 273 |
"""Load live race predictions from HF Hub."""
|
| 274 |
try:
|
|
|
|
|
|
|
| 275 |
live_path = hf_hub_download(
|
| 276 |
MODEL_REPO, "data/live_predictions.json",
|
| 277 |
cache_dir=CACHE_DIR, token=HF_TOKEN,
|
|
@@ -281,6 +283,7 @@ def load_live_predictions():
|
|
| 281 |
data = json.load(f)
|
| 282 |
return data
|
| 283 |
except Exception:
|
|
|
|
| 284 |
return None
|
| 285 |
|
| 286 |
|
|
@@ -402,7 +405,6 @@ with gr.Blocks(
|
|
| 402 |
year_dd.change(constructor_standings, inputs=[year_dd], outputs=[con_chart, con_table])
|
| 403 |
|
| 404 |
app.load(predict_race, inputs=[race_dd], outputs=[race_chart, race_table])
|
| 405 |
-
app.load(live_race_display, outputs=[live_chart, live_table, live_status])
|
| 406 |
|
| 407 |
if __name__ == "__main__":
|
| 408 |
app.launch()
|
|
|
|
| 272 |
def load_live_predictions():
|
| 273 |
"""Load live race predictions from HF Hub."""
|
| 274 |
try:
|
| 275 |
+
# Use a short-lived local cache to avoid hammering HF on every refresh
|
| 276 |
+
# force_download ensures we get the latest during a live race
|
| 277 |
live_path = hf_hub_download(
|
| 278 |
MODEL_REPO, "data/live_predictions.json",
|
| 279 |
cache_dir=CACHE_DIR, token=HF_TOKEN,
|
|
|
|
| 283 |
data = json.load(f)
|
| 284 |
return data
|
| 285 |
except Exception:
|
| 286 |
+
# File may not exist yet (no race has been tracked)
|
| 287 |
return None
|
| 288 |
|
| 289 |
|
|
|
|
| 405 |
year_dd.change(constructor_standings, inputs=[year_dd], outputs=[con_chart, con_table])
|
| 406 |
|
| 407 |
app.load(predict_race, inputs=[race_dd], outputs=[race_chart, race_table])
|
|
|
|
| 408 |
|
| 409 |
if __name__ == "__main__":
|
| 410 |
app.launch()
|