atakan Claude Sonnet 5 commited on
Commit
f950fd2
·
1 Parent(s): 9a21cc0

fix: Move the ZeroGPU probe function to module scope

Browse files

The startup scan for a registered @spaces.GPU Gradio handler apparently
doesn't see decorated functions defined inline inside a `with
gr.Blocks():` block -- only module-level functions referenced by name.
Moved the probe function out to match the pattern used by the two real
inference wrappers.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -96,6 +96,15 @@ def _run_on_gpu(agent: ControlAIAgent, message: str, history: list[dict[str, str
96
  return agent.run(message, history=history, verbose=False)
97
 
98
 
 
 
 
 
 
 
 
 
 
99
  class ChatRequest(BaseModel):
100
  message: str
101
  history: list[dict[str, str]] = []
@@ -280,12 +289,6 @@ with _gpu_demo:
280
  _probe_in = gr.Textbox(visible=False)
281
  _probe_out = gr.Textbox(visible=False)
282
  _probe_btn = gr.Button(visible=False)
283
-
284
- @spaces.GPU(duration=120)
285
- def _zerogpu_registration_probe(message: str) -> str:
286
- result = get_agent().run(message or "hi", history=[], verbose=False)
287
- return result.final_response
288
-
289
  _probe_btn.click(fn=_zerogpu_registration_probe, inputs=_probe_in, outputs=_probe_out)
290
 
291
  app = gr.mount_gradio_app(app, _gpu_demo, path="/gradio")
 
96
  return agent.run(message, history=history, verbose=False)
97
 
98
 
99
+ # ZeroGPU's startup check statically looks for a @spaces.GPU function wired
100
+ # to a Gradio event handler -- must be a module-level function referenced by
101
+ # name, not one defined inline inside a `with gr.Blocks():` block.
102
+ @spaces.GPU(duration=120)
103
+ def _zerogpu_registration_probe(message: str) -> str:
104
+ result = get_agent().run(message or "hi", history=[], verbose=False)
105
+ return result.final_response
106
+
107
+
108
  class ChatRequest(BaseModel):
109
  message: str
110
  history: list[dict[str, str]] = []
 
289
  _probe_in = gr.Textbox(visible=False)
290
  _probe_out = gr.Textbox(visible=False)
291
  _probe_btn = gr.Button(visible=False)
 
 
 
 
 
 
292
  _probe_btn.click(fn=_zerogpu_registration_probe, inputs=_probe_in, outputs=_probe_out)
293
 
294
  app = gr.mount_gradio_app(app, _gpu_demo, path="/gradio")