Spaces:
Sleeping
Sleeping
Commit
·
a499383
1
Parent(s):
d42e603
API: serve FastAPI at root; mount UI at /app; add root index and /health alias for integration without proxy
Browse files
app.py
CHANGED
|
@@ -258,6 +258,24 @@ def _require_auth(authorization: str | None = Header(default=None)):
|
|
| 258 |
raise HTTPException(status_code=401, detail="Invalid token")
|
| 259 |
|
| 260 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
@api.get("/api/attributes")
|
| 262 |
def list_attributes(_: None = Depends(_require_auth)):
|
| 263 |
items = {}
|
|
@@ -367,8 +385,8 @@ _register_attribute_endpoint("/api/orange-hair-text", "Orange hair (text)")
|
|
| 367 |
_register_attribute_endpoint("/api/blonde-hair-text", "Blonde hair (text)")
|
| 368 |
|
| 369 |
|
| 370 |
-
# Mount Gradio
|
| 371 |
-
app = gr.mount_gradio_app(api, demo, path="/")
|
| 372 |
|
| 373 |
|
| 374 |
@GPU()
|
|
|
|
| 258 |
raise HTTPException(status_code=401, detail="Invalid token")
|
| 259 |
|
| 260 |
|
| 261 |
+
@api.get("/")
|
| 262 |
+
def root_index():
|
| 263 |
+
return {
|
| 264 |
+
"name": "Smile Changer API",
|
| 265 |
+
"status": "ok",
|
| 266 |
+
"ui": "/app",
|
| 267 |
+
"endpoints": {
|
| 268 |
+
"GET /health": "public health",
|
| 269 |
+
"GET /api/health": "public health (alias)",
|
| 270 |
+
"GET /api/ping": "auth check",
|
| 271 |
+
"GET /api/attributes": "list attributes",
|
| 272 |
+
"POST /api/edit": "generic edit",
|
| 273 |
+
"POST /api/edit/{attribute}": "edit by attribute name",
|
| 274 |
+
},
|
| 275 |
+
"auth": "set API_AUTH_TOKEN to require Authorization: Bearer <token> (except /health)",
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
|
| 279 |
@api.get("/api/attributes")
|
| 280 |
def list_attributes(_: None = Depends(_require_auth)):
|
| 281 |
items = {}
|
|
|
|
| 385 |
_register_attribute_endpoint("/api/blonde-hair-text", "Blonde hair (text)")
|
| 386 |
|
| 387 |
|
| 388 |
+
# Mount Gradio under /app and expose FastAPI at root for clean API base
|
| 389 |
+
app = gr.mount_gradio_app(api, demo, path="/app")
|
| 390 |
|
| 391 |
|
| 392 |
@GPU()
|