Spaces:
Running on Zero
Running on Zero
Use GPU path only on ZeroGPU; CPU basic otherwise
Browse files
app.py
CHANGED
|
@@ -23,7 +23,9 @@ import uvicorn # noqa: E402
|
|
| 23 |
from app import sentiment # noqa: E402
|
| 24 |
from app.main import app # noqa: E402
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
analyzer = sentiment.get_analyzer()
|
| 28 |
analyzer.to("cuda") # ZeroGPU: real GPU only inside @spaces.GPU calls
|
| 29 |
_predict_on_gpu_device = analyzer.predict
|
|
|
|
| 23 |
from app import sentiment # noqa: E402
|
| 24 |
from app.main import app # noqa: E402
|
| 25 |
|
| 26 |
+
ON_ZERO_GPU = spaces is not None and os.getenv("SPACES_ZERO_GPU", "").lower() in ("1", "true")
|
| 27 |
+
|
| 28 |
+
if ON_ZERO_GPU and sentiment.get_analyzer().__class__.__name__ == "HFAnalyzer":
|
| 29 |
analyzer = sentiment.get_analyzer()
|
| 30 |
analyzer.to("cuda") # ZeroGPU: real GPU only inside @spaces.GPU calls
|
| 31 |
_predict_on_gpu_device = analyzer.predict
|