petter2025 commited on
Commit
462ba16
·
verified ·
1 Parent(s): cbd8fcc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -6,6 +6,7 @@ from typing import Dict, Any, Optional
6
 
7
  from fastapi import FastAPI
8
  from fastapi.middleware.cors import CORSMiddleware
 
9
  from pydantic import BaseModel
10
  import gradio as gr
11
 
@@ -224,5 +225,27 @@ with gr.Blocks(title="ARF v4 Demo") as demo:
224
  # - The Gradio UI at the root `/`
225
  app = gr.mount_gradio_app(fastapi_app, demo, path="/api")
226
 
227
- # Note: No manual server start! The Dockerfile will run uvicorn on this `app` object.
228
- # Make sure your Dockerfile's CMD is: CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  from fastapi import FastAPI
8
  from fastapi.middleware.cors import CORSMiddleware
9
+ from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
10
  from pydantic import BaseModel
11
  import gradio as gr
12
 
 
225
  # - The Gradio UI at the root `/`
226
  app = gr.mount_gradio_app(fastapi_app, demo, path="/api")
227
 
228
+ # ========================= Add Documentation Routes =========================
229
+ # The mounted fastapi_app's docs are not automatically exposed.
230
+ # We manually add routes to serve Swagger UI and ReDoc at /api/docs and /api/redoc,
231
+ # pointing to the OpenAPI schema from the mounted app.
232
+ @app.get("/api/docs", include_in_schema=False)
233
+ async def swagger_ui():
234
+ return get_swagger_ui_html(
235
+ openapi_url="/api/openapi.json",
236
+ title="ARF API Docs"
237
+ )
238
+
239
+ @app.get("/api/redoc", include_in_schema=False)
240
+ async def redoc_ui():
241
+ return get_redoc_html(
242
+ openapi_url="/api/openapi.json",
243
+ title="ARF API ReDoc"
244
+ )
245
+
246
+ @app.get("/api/openapi.json", include_in_schema=False)
247
+ async def openapi():
248
+ return fastapi_app.openapi()
249
+
250
+ # Note: The Dockerfile should run uvicorn on this `app` object.
251
+ # Ensure your Dockerfile's CMD is: CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]