Spaces:
Runtime error
Runtime error
Commit Β·
c39bef7
1
Parent(s): 2ef9bf1
Enable /docs and /openapi.json for Swagger UI
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ import subprocess
|
|
| 3 |
import importlib
|
| 4 |
import asyncio
|
| 5 |
|
| 6 |
-
# π‘οΈ Fix the "Exception ignored in BaseEventLoop.__del__" warning
|
| 7 |
if sys.platform != "win32":
|
| 8 |
try:
|
| 9 |
import selectors
|
|
@@ -41,13 +40,15 @@ while True:
|
|
| 41 |
|
| 42 |
import gradio as gr
|
| 43 |
import spaces
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# π 2. ZeroGPU Worker Anchor
|
| 46 |
@spaces.GPU
|
| 47 |
def zero_gpu_keepalive():
|
| 48 |
return "GPU Active"
|
| 49 |
|
| 50 |
-
# π 3. Gradio Interface
|
| 51 |
with gr.Blocks(title="Tools Backend API") as demo:
|
| 52 |
gr.Markdown("# π CloudAiRambo Tools API Running")
|
| 53 |
gr.Markdown("FastAPI Backend running live with in-memory database and 16 GB RAM.")
|
|
@@ -57,6 +58,21 @@ with gr.Blocks(title="Tools Backend API") as demo:
|
|
| 57 |
# π 4. Mount all FastAPI endpoints
|
| 58 |
demo.app.include_router(fastapi_app.router)
|
| 59 |
|
| 60 |
-
# π 5.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
if __name__ == "__main__":
|
| 62 |
-
demo.launch(ssr_mode=False, server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 3 |
import importlib
|
| 4 |
import asyncio
|
| 5 |
|
|
|
|
| 6 |
if sys.platform != "win32":
|
| 7 |
try:
|
| 8 |
import selectors
|
|
|
|
| 40 |
|
| 41 |
import gradio as gr
|
| 42 |
import spaces
|
| 43 |
+
from fastapi.openapi.docs import get_swagger_ui_html
|
| 44 |
+
from fastapi.openapi.utils import get_openapi
|
| 45 |
|
| 46 |
# π 2. ZeroGPU Worker Anchor
|
| 47 |
@spaces.GPU
|
| 48 |
def zero_gpu_keepalive():
|
| 49 |
return "GPU Active"
|
| 50 |
|
| 51 |
+
# π 3. Gradio Interface
|
| 52 |
with gr.Blocks(title="Tools Backend API") as demo:
|
| 53 |
gr.Markdown("# π CloudAiRambo Tools API Running")
|
| 54 |
gr.Markdown("FastAPI Backend running live with in-memory database and 16 GB RAM.")
|
|
|
|
| 58 |
# π 4. Mount all FastAPI endpoints
|
| 59 |
demo.app.include_router(fastapi_app.router)
|
| 60 |
|
| 61 |
+
# π 5. Enable Swagger /docs and /openapi.json on Gradio's app
|
| 62 |
+
@demo.app.get("/docs", include_in_schema=False)
|
| 63 |
+
async def custom_swagger_ui_html():
|
| 64 |
+
return get_swagger_ui_html(
|
| 65 |
+
openapi_url="/openapi.json",
|
| 66 |
+
title="Tools Backend API - Swagger UI"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
@demo.app.get("/openapi.json", include_in_schema=False)
|
| 70 |
+
async def get_open_api_endpoint():
|
| 71 |
+
return get_openapi(
|
| 72 |
+
title="Tools Backend API",
|
| 73 |
+
version="1.0.0",
|
| 74 |
+
routes=demo.app.routes
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
if __name__ == "__main__":
|
| 78 |
+
demo.launch(ssr_mode=False, server_name="0.0.0.0", server_port=7860)
|