Spaces:
Sleeping
Sleeping
Fix ZeroGPU import order: import spaces before torch
Browse filesZeroGPU refuses to load if CUDA has been initialized before its
package is imported. Moving `import spaces` to the top of app.py.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -7,6 +7,16 @@ Google Solar API DSM data.
|
|
| 7 |
Deployed on HuggingFace Spaces with ZeroGPU.
|
| 8 |
"""
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
import json
|
| 11 |
import os
|
| 12 |
import tempfile
|
|
@@ -21,15 +31,6 @@ print("Initializing RoofSight...")
|
|
| 21 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 22 |
load_model(device="cpu")
|
| 23 |
|
| 24 |
-
# Try importing spaces for ZeroGPU decorator
|
| 25 |
-
try:
|
| 26 |
-
import spaces
|
| 27 |
-
GPU_DECORATOR = spaces.GPU
|
| 28 |
-
except ImportError:
|
| 29 |
-
# Local dev without ZeroGPU
|
| 30 |
-
def GPU_DECORATOR(fn):
|
| 31 |
-
return fn
|
| 32 |
-
|
| 33 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY", "")
|
| 34 |
|
| 35 |
|
|
|
|
| 7 |
Deployed on HuggingFace Spaces with ZeroGPU.
|
| 8 |
"""
|
| 9 |
|
| 10 |
+
# ZeroGPU requires `spaces` to be imported BEFORE any CUDA-touching package
|
| 11 |
+
# (torch, transformers, etc). Otherwise CUDA gets initialized and spaces refuses to load.
|
| 12 |
+
try:
|
| 13 |
+
import spaces
|
| 14 |
+
GPU_DECORATOR = spaces.GPU
|
| 15 |
+
except ImportError:
|
| 16 |
+
# Local dev without ZeroGPU
|
| 17 |
+
def GPU_DECORATOR(fn):
|
| 18 |
+
return fn
|
| 19 |
+
|
| 20 |
import json
|
| 21 |
import os
|
| 22 |
import tempfile
|
|
|
|
| 31 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 32 |
load_model(device="cpu")
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY", "")
|
| 35 |
|
| 36 |
|