akshaylinson commited on
Commit
c6607dc
Β·
1 Parent(s): 98e72e1

fix: define FastAPI routes before gr.mount_gradio_app

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -84,13 +84,13 @@ demo = gr.Interface(
84
  )
85
 
86
  # ── FastAPI routes mounted on Gradio app ──────────────────────────────────────
87
- app = gr.mount_gradio_app(FastAPI(), demo, path="/")
88
 
89
- @app.get("/health")
90
  def health():
91
  return JSONResponse({"status": "ok"})
92
 
93
- @app.post("/synthesize")
94
  async def synthesize(
95
  text: str = Form(...),
96
  ref_text: str = Form(...),
@@ -110,3 +110,5 @@ async def synthesize(
110
  buf = io.BytesIO()
111
  sf.write(buf, audio_out, sample_rate, format="WAV")
112
  return Response(content=buf.getvalue(), media_type="audio/wav")
 
 
 
84
  )
85
 
86
  # ── FastAPI routes mounted on Gradio app ──────────────────────────────────────
87
+ _api = FastAPI()
88
 
89
+ @_api.get("/health")
90
  def health():
91
  return JSONResponse({"status": "ok"})
92
 
93
+ @_api.post("/synthesize")
94
  async def synthesize(
95
  text: str = Form(...),
96
  ref_text: str = Form(...),
 
110
  buf = io.BytesIO()
111
  sf.write(buf, audio_out, sample_rate, format="WAV")
112
  return Response(content=buf.getvalue(), media_type="audio/wav")
113
+
114
+ app = gr.mount_gradio_app(_api, demo, path="/")