import gradio as gr import spaces import uvicorn from inference import app @spaces.GPU def ping(): """Do nothing. ZeroGPU wants one @spaces.GPU function wired to a Gradio event.""" return "ok" with gr.Blocks() as demo: gr.Markdown("JetBoost API. The endpoint is `/predict`.") out = gr.Textbox(label="Ping") gr.Button("Ping").click(ping, outputs=out) # /predict is registered first, so it still takes priority over the Gradio page at "/" # ssr_mode=False: Spaces enable SSR via env var, which spawns a Node server # that grabs 7860 before uvicorn can. app = gr.mount_gradio_app(app, demo, path="/", ssr_mode=False) def send_zerogpu_startup_report() -> None: """Manually send the report that spaces normally sends from Blocks.launch(). uvicorn.run() never calls launch(), so without this ZeroGPU concludes there's no @spaces.GPU function and kills the Space. """ try: # Only defined on ZeroGPU hardware; missing on CPU or local runs from spaces.zero import startup except (ImportError, AttributeError): return # nothing to report off ZeroGPU startup() if __name__ == "__main__": send_zerogpu_startup_report() # must happen before the server starts uvicorn.run(app, host="0.0.0.0", port=7860)