Spaces:
Runtime error
Runtime error
fix: mount Gradio at /gradio and serve FastAPI on root with uvicorn
Browse files
app.py
CHANGED
|
@@ -33,30 +33,15 @@ with gr.Blocks(title="AttendX AI API Gateway") as demo:
|
|
| 33 |
test_btn.click(fn=zerogpu_face_inference_probe, outputs=status_box)
|
| 34 |
|
| 35 |
# ---------------------------------------------------------------------------
|
| 36 |
-
# Mount
|
| 37 |
# ---------------------------------------------------------------------------
|
| 38 |
-
#
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
allow_origins=settings.cors_origins_list,
|
| 42 |
-
allow_credentials=True,
|
| 43 |
-
allow_methods=["*"],
|
| 44 |
-
allow_headers=["*"],
|
| 45 |
-
)
|
| 46 |
-
|
| 47 |
-
# Register all FastAPI routes directly onto Gradio's FastAPI application so /api/*, /docs, /openapi.json take priority over Gradio's catch-all
|
| 48 |
-
demo.app.include_router(fastapi_app.router)
|
| 49 |
-
|
| 50 |
-
# Mount static file directory for student photos and exports
|
| 51 |
-
import os
|
| 52 |
-
from fastapi.staticfiles import StaticFiles
|
| 53 |
-
os.makedirs(settings.STORAGE_DIR, exist_ok=True)
|
| 54 |
-
demo.app.mount("/storage", StaticFiles(directory=settings.STORAGE_DIR), name="storage")
|
| 55 |
-
|
| 56 |
-
# Expose app for ASGI servers
|
| 57 |
-
app = demo.app
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
|
|
|
|
| 33 |
test_btn.click(fn=zerogpu_face_inference_probe, outputs=status_box)
|
| 34 |
|
| 35 |
# ---------------------------------------------------------------------------
|
| 36 |
+
# Mount Gradio App onto FastAPI
|
| 37 |
# ---------------------------------------------------------------------------
|
| 38 |
+
# Mount Gradio at /gradio so FastAPI handles root, /docs, /api/*, and /storage/* directly,
|
| 39 |
+
# while the @spaces.GPU registered Gradio interface is hosted at /gradio.
|
| 40 |
+
app = gr.mount_gradio_app(fastapi_app, demo, path="/gradio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
if __name__ == "__main__":
|
| 43 |
+
import uvicorn
|
| 44 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 45 |
+
|
| 46 |
|
| 47 |
|