-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (53 loc) · 1.96 KB
/
main.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from fastapi import FastAPI, Request, Path, Query
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi import Form
import os
from responsebuilder.buildresponse import BuildResponse, ConfigReader
templates = Jinja2Templates(directory="templates")
# initialize 'fastAPI'
app = FastAPI()
config_data = ConfigReader().get_yaml_data()
br = BuildResponse(config_data=config_data)
# create endpoints / route
@app.get('/')
def home():
html_content = """
<html>
<body>
<form action="/qasubmit" method="POST">
<h3>Enter your Query : </h3>
<p>
<textarea id="query" name="query" rows="10" cols="50">Write your query ! </textarea>
</p>
<p><input type='submit' value='Submit Query'/></p>
</form>
</body>
</html>
"""
return HTMLResponse(content=html_content, status_code=200)
@app.post("/qasubmit")
async def qasubmit(query: str = Form(...)):
answer = br.get_response(question=query)
html_content = f"""
<html>
<body>
<form action="/qasubmit" method="POST">
<h3>Enter your Query : </h3>
<p>
<textarea id="query" name="query" rows="10" cols="50">Write your query ! </textarea>
</p>
<p><input type='submit' value='Submit Query'/></p>
</form>
<p>
Question Asked : {query}
</p>
<p>
Proposed Answer from OpenAI and VectorDB <br/>
{answer}
</p>
</body>
</html>
"""
# return {"Query asked was ": query}
return HTMLResponse(content=html_content, status_code=200)