-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
36 lines (25 loc) · 1000 Bytes
/
app.py
File metadata and controls
36 lines (25 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
import asyncio
from test_main_function import generate_response
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
async def run_all_models(query: str):
return await asyncio.to_thread(generate_response, query, [])
@app.get("/")
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.post("/chat")
async def chat(request: Request):
data = await request.json()
query = data.get("query")
if not query:
return JSONResponse({"error": "No query provided"}, status_code=400)
try:
results = await run_all_models(query)
return JSONResponse(results)
except Exception as e:
return JSONResponse({"error": str(e)}, status_code=500)