Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -533,18 +533,36 @@ with gr.Blocks(
|
|
| 533 |
logger.info("β
Gradio UI built successfully")
|
| 534 |
|
| 535 |
# ---------------------------------------------------------------------------
|
| 536 |
-
#
|
| 537 |
# ---------------------------------------------------------------------------
|
| 538 |
-
|
| 539 |
-
async def health():
|
| 540 |
-
return {"status": "ok", "model_loaded": MODEL is not None}
|
| 541 |
|
| 542 |
-
# -
|
| 543 |
-
#
|
| 544 |
-
#
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
logger.info("")
|
| 549 |
logger.info("π Endpoints:")
|
| 550 |
logger.info(" UI: http://0.0.0.0:7860/")
|
|
@@ -559,3 +577,4 @@ if __name__ == "__main__":
|
|
| 559 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 560 |
|
| 561 |
|
|
|
|
|
|
| 533 |
logger.info("β
Gradio UI built successfully")
|
| 534 |
|
| 535 |
# ---------------------------------------------------------------------------
|
| 536 |
+
# Combine Gradio + API into one app
|
| 537 |
# ---------------------------------------------------------------------------
|
| 538 |
+
logger.info("π Building combined app...")
|
|
|
|
|
|
|
| 539 |
|
| 540 |
+
# Pre-set attributes that launch() would normally set
|
| 541 |
+
# (needed because we're using demo.app directly, not launch())
|
| 542 |
+
demo.max_file_size = None # no upload size limit
|
| 543 |
+
demo.blocked_paths = [] # no blocked paths
|
| 544 |
+
|
| 545 |
+
# Queue for async processing
|
| 546 |
+
demo.queue()
|
| 547 |
+
|
| 548 |
+
# Get Gradio's own ASGI app (handles "/" correctly β no 307 redirect!)
|
| 549 |
+
app = demo.app
|
| 550 |
+
|
| 551 |
+
# Inject our API routes at the FRONT so they take priority
|
| 552 |
+
# (Gradio has catch-all routes that would shadow them otherwise)
|
| 553 |
+
for route in api_app.routes:
|
| 554 |
+
app.router.routes.insert(0, route)
|
| 555 |
+
|
| 556 |
+
# Health check
|
| 557 |
+
from starlette.routing import Route
|
| 558 |
+
from starlette.responses import JSONResponse
|
| 559 |
+
|
| 560 |
+
async def health_endpoint(request):
|
| 561 |
+
return JSONResponse({"status": "ok", "model_loaded": MODEL is not None})
|
| 562 |
+
|
| 563 |
+
app.router.routes.insert(0, Route("/api/health", health_endpoint))
|
| 564 |
+
|
| 565 |
+
logger.info("β
App ready!")
|
| 566 |
logger.info("")
|
| 567 |
logger.info("π Endpoints:")
|
| 568 |
logger.info(" UI: http://0.0.0.0:7860/")
|
|
|
|
| 577 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 578 |
|
| 579 |
|
| 580 |
+
|