owlninjam commited on
Commit
0fe4bd2
Β·
verified Β·
1 Parent(s): 628d37c

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -533,18 +533,36 @@ with gr.Blocks(
533
  logger.info("βœ… Gradio UI built successfully")
534
 
535
  # ---------------------------------------------------------------------------
536
- # Health check
537
  # ---------------------------------------------------------------------------
538
- @api_app.get("/api/health")
539
- async def health():
540
- return {"status": "ok", "model_loaded": MODEL is not None}
541
 
542
- # ---------------------------------------------------------------------------
543
- # Mount & Launch
544
- # ---------------------------------------------------------------------------
545
- logger.info("πŸ”— Mounting Gradio UI onto FastAPI (redirect_slashes=False)...")
546
- app = gr.mount_gradio_app(api_app, demo, path="/")
547
- logger.info("βœ… App mounted β€” ready to serve!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+