Spaces:
Running on Zero

vechey commited on
Commit
5c2b4d6
·
verified ·
1 Parent(s): b3db0f3

Use GPU path only on ZeroGPU; CPU basic otherwise

Browse files
Files changed (1) hide show
  1. app.py +3 -1
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
- if spaces is not None and sentiment.get_analyzer().__class__.__name__ == "HFAnalyzer":
 
 
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