Spaces:
Running on Zero
Running on Zero
Register ZeroGPU @spaces.GPU tasks at startup
Browse files
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": "π§",
|