kadsai commited on
Commit
a4670bd
·
verified ·
1 Parent(s): 332ae01

update fast api

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -216,11 +216,19 @@ with gr.Blocks(theme=gr.themes.Soft(), css=".gradio-container {background-color:
216
  # --- FastAPI app
217
  app_fastapi = FastAPI()
218
 
 
 
 
 
 
 
 
 
219
  class RequestData(BaseModel):
220
  message: str
221
  history: list = []
222
  system_message: str = ""
223
- domain: str = "corismoney"
224
  model_name: str = "gpt-3.5-turbo"
225
  max_tokens: int = 800
226
  temperature: float = 0.7
@@ -242,12 +250,16 @@ async def api_respond(data: RequestData):
242
  top_p=data.top_p
243
  )
244
  return {"history": response}
 
 
 
245
 
246
- def start_gradio():
247
- app.launch(server_name="0.0.0.0", server_port=7861, share=False)
 
248
 
249
  if __name__ == "__main__":
250
- # Lancer Gradio dans un thread à part
251
- threading.Thread(target=start_gradio, daemon=True).start()
252
- # Lancer FastAPI avec uvicorn
253
- uvicorn.run(app_fastapi, host="0.0.0.0", port=7860)
 
216
  # --- FastAPI app
217
  app_fastapi = FastAPI()
218
 
219
+ app_fastapi.add_middleware(
220
+ CORSMiddleware,
221
+ allow_origins=["*"],
222
+ allow_credentials=True,
223
+ allow_methods=["*"],
224
+ allow_headers=["*"],
225
+ )
226
+
227
  class RequestData(BaseModel):
228
  message: str
229
  history: list = []
230
  system_message: str = ""
231
+ domain: str
232
  model_name: str = "gpt-3.5-turbo"
233
  max_tokens: int = 800
234
  temperature: float = 0.7
 
250
  top_p=data.top_p
251
  )
252
  return {"history": response}
253
+ # -- Start FastApi
254
+ def start_api():
255
+ uvicorn.run(app_fastapi, host="0.0.0.0", port=7880)
256
 
257
+ # -- Start Gradio
258
+ #def start_gradio():
259
+ # app.launch(server_name="0.0.0.0", server_port=7860, share=False)
260
 
261
  if __name__ == "__main__":
262
+ # --Lancer FastAPI avec uvicorn
263
+ threading.Thread(target=start_api).start()
264
+ # --Lancer Gradio
265
+ app.launch()