nz-nz commited on
Commit
4e70816
·
verified ·
1 Parent(s): efca112

Add required @app .api endpoint to gradio.Server (empty Blocks exits on Space)

Browse files
Files changed (1) hide show
  1. server.py +12 -1
server.py CHANGED
@@ -106,10 +106,21 @@ IMAGE_ONLY_MSG = (
106
  # gradio-SDK Space and wires up the queue + ZeroGPU GPU allocation. A plain
107
  # FastAPI + manual `uvicorn.run(7860)` collides with the Space's own gradio
108
  # server ("address already in use") — `gradio.Server` is the supported way to run
109
- # a custom frontend on a gradio Space. Present since gradio 6.17 (the pinned ver).
110
  app = gr.Server(title="Recall")
111
 
112
 
 
 
 
 
 
 
 
 
 
 
 
113
  # ---- serialization ---------------------------------------------------------
114
 
115
  def _card_out(card: dict | None) -> dict | None:
 
106
  # gradio-SDK Space and wires up the queue + ZeroGPU GPU allocation. A plain
107
  # FastAPI + manual `uvicorn.run(7860)` collides with the Space's own gradio
108
  # server ("address already in use") — `gradio.Server` is the supported way to run
109
+ # a custom frontend on a gradio Space.
110
  app = gr.Server(title="Recall")
111
 
112
 
113
+ # A gradio.Server MUST register at least one `@app.api(...)` endpoint: launch()
114
+ # builds its internal Blocks from these, and on a Space an *empty* Blocks doesn't
115
+ # stay "running" (launch returns and the process exits → RUNTIME_ERROR). This is
116
+ # also the gradio-native handle (`gradio_client` / the JS Client) onto the same
117
+ # backend the custom frontend drives over plain JSON `/api/*` routes below.
118
+ @app.api(name="health")
119
+ def health() -> str:
120
+ """Liveness probe + the Server's required gradio endpoint."""
121
+ return "ok"
122
+
123
+
124
  # ---- serialization ---------------------------------------------------------
125
 
126
  def _card_out(card: dict | None) -> dict | None: