LogicGoInfotechSpaces commited on
Commit
d42e603
·
1 Parent(s): e3f5da2

API: add startup self-check that hits /api/health and logs result

Browse files
Files changed (1) hide show
  1. app.py +11 -0
app.py CHANGED
@@ -6,6 +6,7 @@ from typing import Tuple, Dict
6
  import gradio as gr
7
  from fastapi import FastAPI, UploadFile, File, Form, Header, HTTPException, Depends
8
  from fastapi.responses import StreamingResponse, JSONResponse
 
9
  import io
10
  from spaces import GPU
11
  from huggingface_hub import snapshot_download
@@ -276,6 +277,16 @@ def ping(_: None = Depends(_require_auth)):
276
  return {"status": "ok", "auth": True}
277
 
278
 
 
 
 
 
 
 
 
 
 
 
279
  @api.post("/api/edit")
280
  async def api_edit(
281
  file: UploadFile = File(...),
 
6
  import gradio as gr
7
  from fastapi import FastAPI, UploadFile, File, Form, Header, HTTPException, Depends
8
  from fastapi.responses import StreamingResponse, JSONResponse
9
+ from fastapi.testclient import TestClient
10
  import io
11
  from spaces import GPU
12
  from huggingface_hub import snapshot_download
 
277
  return {"status": "ok", "auth": True}
278
 
279
 
280
+ @api.on_event("startup")
281
+ def _self_check():
282
+ try:
283
+ client = TestClient(api)
284
+ r = client.get("/api/health")
285
+ logger.info("Self-check /api/health -> %s %s", r.status_code, r.json() if r.headers.get("content-type"," ").startswith("application/json") else "")
286
+ except Exception as e:
287
+ logger.error("Self-check failed: %s", e)
288
+
289
+
290
  @api.post("/api/edit")
291
  async def api_edit(
292
  file: UploadFile = File(...),