assafvayner HF Staff Claude Sonnet 4.5 commited on
Commit
275d5a1
·
1 Parent(s): bd64b4c

Fix FastAPI route registration

Browse files

Get app reference before adding routes to ensure proper registration timing.

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

Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -215,9 +215,12 @@ with gr.Blocks(title="HuggingFace Webhook Processor") as demo:
215
  outputs=[status_text, message_count, batch_count, latest_batch]
216
  )
217
 
 
 
218
 
219
- # Add webhook endpoints to Gradio's FastAPI app (Gradio 5 method)
220
- @demo.app.post("/webhooks/hub")
 
221
  async def webhook_endpoint(request: Request):
222
  """
223
  Webhook endpoint for HuggingFace Hub events.
@@ -259,7 +262,7 @@ async def webhook_endpoint(request: Request):
259
  raise HTTPException(status_code=500, detail=str(e))
260
 
261
 
262
- @demo.app.get("/webhooks/health")
263
  async def health_check():
264
  """Health check endpoint."""
265
  with message_lock:
 
215
  outputs=[status_text, message_count, batch_count, latest_batch]
216
  )
217
 
218
+ # Get the FastAPI app instance
219
+ app = demo.app
220
 
221
+
222
+ # Add webhook endpoints to FastAPI app
223
+ @app.post("/webhooks/hub")
224
  async def webhook_endpoint(request: Request):
225
  """
226
  Webhook endpoint for HuggingFace Hub events.
 
262
  raise HTTPException(status_code=500, detail=str(e))
263
 
264
 
265
+ @app.get("/webhooks/health")
266
  async def health_check():
267
  """Health check endpoint."""
268
  with message_lock: