Cyantist8208 commited on
Commit
06c38b4
·
1 Parent(s): dcc78fa
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -271,8 +271,20 @@ with gr.Blocks() as demo:
271
  )
272
 
273
  # ---------- 3. FastAPI layer --------------------------------------------------
274
- @gr.on_api()
275
- def api_answer(system_prompt, context, question, user_id, history_flag, temp, top_p, top_k):
276
- return answer(system_prompt, context, question, user_id, history_flag, temp, top_p, top_k)
277
-
278
- demo.launch(show_api=True, share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
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)