Spaces:
Sleeping
Sleeping
Commit ·
06c38b4
1
Parent(s): dcc78fa
fastapi
Browse files
app.py
CHANGED
|
@@ -271,8 +271,20 @@ with gr.Blocks() as demo:
|
|
| 271 |
)
|
| 272 |
|
| 273 |
# ---------- 3. FastAPI layer --------------------------------------------------
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
)
|
| 272 |
|
| 273 |
# ---------- 3. FastAPI layer --------------------------------------------------
|
| 274 |
+
class IngestReq(BaseModel):
|
| 275 |
+
user_id:str
|
| 276 |
+
docs:list[str]
|
| 277 |
+
|
| 278 |
+
class QueryReq(BaseModel):
|
| 279 |
+
user_id:str
|
| 280 |
+
question:str
|
| 281 |
+
|
| 282 |
+
api = FastAPI()
|
| 283 |
+
api = gr.mount_gradio_app(api, demo, path="/")
|
| 284 |
+
|
| 285 |
+
# ---------- 5. run both (FastAPI + Gradio) -----------------------------------
|
| 286 |
+
if __name__ == "__main__":
|
| 287 |
+
# launch Gradio on a background thread
|
| 288 |
+
demo.queue().launch(share=False, prevent_thread_lock=True)
|
| 289 |
+
# then start FastAPI (uvicorn blocks main thread)
|
| 290 |
+
uvicorn.run(api, host="0.0.0.0", port=8000)
|