mzidan000 commited on
Commit
033fbb4
·
verified ·
1 Parent(s): 002831b

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -14,6 +14,7 @@ The gr.Blocks streaming version is retained at ``matchday/app.py`` as a fallback
14
  """
15
  from __future__ import annotations
16
 
 
17
  import json
18
  import logging
19
  import os
@@ -45,7 +46,28 @@ USE_AGENT = True
45
  HERE = Path(__file__).parent
46
  INDEX_HTML = HERE / "index.html"
47
 
48
- app = Server()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
 
51
  def _ev(**payload) -> str:
 
14
  """
15
  from __future__ import annotations
16
 
17
+ import asyncio
18
  import json
19
  import logging
20
  import os
 
46
  HERE = Path(__file__).parent
47
  INDEX_HTML = HERE / "index.html"
48
 
49
+
50
+ async def _warm_nemotron() -> None:
51
+ """Best-effort warm generate on Space startup so the FIRST user query isn't
52
+ stuck behind a Modal cold start (~2 min warm from the weight cache). Runs as
53
+ a fire-and-forget background task; never blocks startup, never raises.
54
+ """
55
+ try:
56
+ agent = MatchDayAgent()
57
+ await asyncio.wait_for(
58
+ agent.run([{"role": "user", "content": "warmup ping"}]), timeout=240
59
+ )
60
+ logger.info("startup warmup ping completed — Nemotron container is hot")
61
+ except Exception as exc: # noqa: BLE001 — best-effort, must not break boot
62
+ logger.info("startup warmup ping ended early (%s)", repr(exc)[:80])
63
+
64
+
65
+ async def _startup_warmup() -> None:
66
+ """Server startup hook — schedule the warmup without blocking boot."""
67
+ asyncio.create_task(_warm_nemotron())
68
+
69
+
70
+ app = Server(on_startup=[_startup_warmup])
71
 
72
 
73
  def _ev(**payload) -> str: