Spaces:
Running on Zero
Running on Zero
Download app.py from ZephyrNTempest/jetboost-api: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/ZephyrNTempest/jetboost-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/ZephyrNTempest/jetboost-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ZephyrNTempest/jetboost-api/resolve/main/app.py
1.28 kB
| import gradio as gr | |
| import spaces | |
| import uvicorn | |
| from inference import app | |
| 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) |