update fast api
Browse files
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
|
| 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 |
-
|
| 247 |
-
|
|
|
|
| 248 |
|
| 249 |
if __name__ == "__main__":
|
| 250 |
-
|
| 251 |
-
threading.Thread(target=
|
| 252 |
-
|
| 253 |
-
|
|
|
|
| 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()
|