File size: 832 Bytes
dc43547
 
 
 
8504ea6
57f2927
dc43547
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from chat import chat_conversations
import spacy

app = FastAPI()

templates = Jinja2Templates(directory="templates")

@app.get("/", response_class=HTMLResponse)
async def read_root(request: Request):
    return templates.TemplateResponse("chatwidget.html", {"request": request})

@app.get("/chat", response_class=HTMLResponse)
async def read_root(request: Request):
    return templates.TemplateResponse("chatwidget.html", {"request": request})

@app.post("/chatwidget", response_class=HTMLResponse)
async def read_root(request: Request):
    print(request)
    form_data = await request.json()
    query = form_data.get('query')
    response_text = chat_conversations(query)
    return response_text