sush0401 commited on
Commit
576c6b1
Β·
verified Β·
1 Parent(s): 485b68d

Register ZeroGPU @spaces.GPU tasks at startup

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -15,6 +15,17 @@ from worlds import get_world, WORLDS, list_worlds
15
 
16
  MOCK = os.environ.get("TINYWORLD_MOCK", "0") == "1"
17
 
 
 
 
 
 
 
 
 
 
 
 
18
  MOOD_EMOJI = {
19
  "happy": "😊", "stressed": "😰", "bored": "😐", "excited": "🀩",
20
  "hungry": "πŸ•", "tired": "😴", "nostalgic": "πŸ₯Ή", "curious": "🧐",
 
15
 
16
  MOCK = os.environ.get("TINYWORLD_MOCK", "0") == "1"
17
 
18
+ # On a ZeroGPU Space (TINYWORLD_INFER=local) the @spaces.GPU functions must be
19
+ # registered at startup or ZeroGPU shuts the Space down. Import inference eagerly
20
+ # in that mode only (loads torch but NOT the models β€” those stay lazy). Skipped on
21
+ # mock/modal so dev and tests never need torch/spaces.
22
+ if not MOCK and os.environ.get("TINYWORLD_INFER", "modal").lower() == "local":
23
+ try:
24
+ import inference # noqa: F401 (registers ZeroGPU GPU tasks)
25
+ print("[app] ZeroGPU inference module loaded")
26
+ except Exception as e:
27
+ print(f"[app] inference preimport failed: {e}")
28
+
29
  MOOD_EMOJI = {
30
  "happy": "😊", "stressed": "😰", "bored": "😐", "excited": "🀩",
31
  "hungry": "πŸ•", "tired": "😴", "nostalgic": "πŸ₯Ή", "curious": "🧐",