Upload 127 files
Browse files- app.py +19 -0
- game/__pycache__/gamemaster.cpython-313.pyc +0 -0
- game/gamemaster.py +12 -8
app.py
CHANGED
|
@@ -24,6 +24,10 @@ import uuid
|
|
| 24 |
# setdefault) because Spaces exports GRADIO_SSR_MODE=true.
|
| 25 |
os.environ["GRADIO_SSR_MODE"] = "false"
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
import gradio as gr
|
| 28 |
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
| 29 |
from fastapi.responses import FileResponse
|
|
@@ -356,6 +360,21 @@ with gr.Blocks(title="HuggingWizards — Game Master Dashboard") as demo:
|
|
| 356 |
|
| 357 |
app = gr.mount_gradio_app(app, demo, path="/dashboard", ssr_mode=False)
|
| 358 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
|
| 360 |
if __name__ == "__main__":
|
| 361 |
import uvicorn
|
|
|
|
| 24 |
# setdefault) because Spaces exports GRADIO_SSR_MODE=true.
|
| 25 |
os.environ["GRADIO_SSR_MODE"] = "false"
|
| 26 |
|
| 27 |
+
# On ZeroGPU, `spaces` must be imported before any CUDA-touching library.
|
| 28 |
+
with contextlib.suppress(Exception): # not installed in local dev
|
| 29 |
+
import spaces # noqa: F401
|
| 30 |
+
|
| 31 |
import gradio as gr
|
| 32 |
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
| 33 |
from fastapi.responses import FileResponse
|
|
|
|
| 360 |
|
| 361 |
app = gr.mount_gradio_app(app, demo, path="/dashboard", ssr_mode=False)
|
| 362 |
|
| 363 |
+
# ---- ZeroGPU startup report ------------------------------------------------
|
| 364 |
+
# The `spaces` package sends its "this app has @spaces.GPU functions" report
|
| 365 |
+
# to the ZeroGPU controller via a hook it installs on gr.Blocks.launch(). We
|
| 366 |
+
# serve everything through uvicorn instead of demo.launch(), so that hook
|
| 367 |
+
# never fires and ZeroGPU kills the Space with "No @spaces.GPU function
|
| 368 |
+
# detected during startup". Invoke the same startup task manually. It packs
|
| 369 |
+
# the (already loaded) model for fast GPU transfer and phones home; off
|
| 370 |
+
# Spaces, `spaces.zero` doesn't define `startup` and this is a no-op.
|
| 371 |
+
with contextlib.suppress(Exception):
|
| 372 |
+
from spaces import zero as _spaces_zero # type: ignore
|
| 373 |
+
|
| 374 |
+
if hasattr(_spaces_zero, "startup"):
|
| 375 |
+
_spaces_zero.startup()
|
| 376 |
+
print("[app] ZeroGPU startup report sent")
|
| 377 |
+
|
| 378 |
|
| 379 |
if __name__ == "__main__":
|
| 380 |
import uvicorn
|
game/__pycache__/gamemaster.cpython-313.pyc
CHANGED
|
Binary files a/game/__pycache__/gamemaster.cpython-313.pyc and b/game/__pycache__/gamemaster.cpython-313.pyc differ
|
|
|
game/gamemaster.py
CHANGED
|
@@ -161,14 +161,6 @@ def _ensure_model():
|
|
| 161 |
return False
|
| 162 |
|
| 163 |
|
| 164 |
-
# On Spaces, load the model at startup (ZeroGPU replays the .to("cuda") once a
|
| 165 |
-
# real GPU is attached) so the @spaces.GPU window is spent on inference only —
|
| 166 |
-
# lazy-loading inside the first GPU call would blow the 60 s duration on the
|
| 167 |
-
# weight download. Locally we stay lazy so dev/CI never downloads weights.
|
| 168 |
-
if _ON_SPACES and not os.environ.get("HUGGINGWIZARDS_NO_LLM"):
|
| 169 |
-
_ensure_model()
|
| 170 |
-
|
| 171 |
-
|
| 172 |
# ---- mercy guardrail -------------------------------------------------------
|
| 173 |
# The GM may slow the boss's attack speed to help wounded parties, but its
|
| 174 |
# willingness to help decays as waves progress: the allowed floor rises from
|
|
@@ -209,6 +201,18 @@ def _run_model(system: str, user: str) -> str:
|
|
| 209 |
return text
|
| 210 |
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
def _extract_json(text: str) -> dict | None:
|
| 213 |
m = re.search(r"\{.*\}", text, re.DOTALL)
|
| 214 |
if not m:
|
|
|
|
| 161 |
return False
|
| 162 |
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
# ---- mercy guardrail -------------------------------------------------------
|
| 165 |
# The GM may slow the boss's attack speed to help wounded parties, but its
|
| 166 |
# willingness to help decays as waves progress: the allowed floor rises from
|
|
|
|
| 201 |
return text
|
| 202 |
|
| 203 |
|
| 204 |
+
# On Spaces, load the model at startup (ZeroGPU replays the .to("cuda") once a
|
| 205 |
+
# real GPU is attached) so the @spaces.GPU window is spent on inference only —
|
| 206 |
+
# lazy-loading inside the first GPU call would blow the 60 s duration on the
|
| 207 |
+
# weight download. This MUST come after the @spaces.GPU function above is
|
| 208 |
+
# defined: ZeroGPU's startup probe needs to see a registered GPU function, and
|
| 209 |
+
# the multi-minute weight download would otherwise delay that registration
|
| 210 |
+
# ("No @spaces.GPU function detected during startup"). Locally we stay lazy so
|
| 211 |
+
# dev/CI never downloads weights.
|
| 212 |
+
if _ON_SPACES and not os.environ.get("HUGGINGWIZARDS_NO_LLM"):
|
| 213 |
+
_ensure_model()
|
| 214 |
+
|
| 215 |
+
|
| 216 |
def _extract_json(text: str) -> dict | None:
|
| 217 |
m = re.search(r"\{.*\}", text, re.DOTALL)
|
| 218 |
if not m:
|