tirtho149 commited on
Commit
2743acd
·
verified ·
1 Parent(s): 89cb014

Add no-op @spaces.GPU probe so ZeroGPU runtime starts (app is CPU-only)

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -21,6 +21,26 @@ from src.tools.tool_matcher import ToolMatcher
21
 
22
  logger = logging.getLogger(__name__)
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  # Built once per process, not per session — these load models and are the cold-start cost.
25
  accounts = AccountsService()
26
  tool_matcher = ToolMatcher()
 
21
 
22
  logger = logging.getLogger(__name__)
23
 
24
+ # HF Spaces' free tier for Gradio is ZeroGPU, whose runtime aborts at startup ("No
25
+ # @spaces.GPU function detected") unless at least one function is decorated with
26
+ # @spaces.GPU. This app is CPU-only (all inference is via the OpenAI API), so we only
27
+ # need the decorator to EXIST — the probe below is never called. `spaces` isn't a local
28
+ # dev dependency (HF injects it in the Space build), so fall back to a no-op decorator.
29
+ try:
30
+ import spaces # provided by the HF ZeroGPU runtime
31
+
32
+ _gpu = spaces.GPU
33
+ except Exception: # local / non-ZeroGPU: `spaces` not installed
34
+ def _gpu(fn=None, **_kwargs):
35
+ return fn if callable(fn) else (lambda f: f)
36
+
37
+
38
+ @_gpu
39
+ def _zero_gpu_probe():
40
+ """Exists solely so ZeroGPU detects a @spaces.GPU function at startup; unused."""
41
+ return None
42
+
43
+
44
  # Built once per process, not per session — these load models and are the cold-start cost.
45
  accounts = AccountsService()
46
  tool_matcher = ToolMatcher()