-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
52 lines (42 loc) · 1.6 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
import socket
import sys
from fastapi import FastAPI,Form
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from fastapi import Request
from resources import index_html_response, enter_details, hello_html_response, login_details, chatbot_ques_html, chatbot_ans_html
app = FastAPI()
templates = Jinja2Templates(directory="templates/")
hostname = socket.gethostname()
@app.get("/")
async def read_root():
return {
"name": "babybot",
"host": hostname,
"version": f"Hello world! From FastAPI running on Uvicorn. Using Python"
}
@app.get("/hello/", response_class=HTMLResponse)
async def hello():
return hello_html_response()
@app.get("/index/", response_class=HTMLResponse)
async def read_items():
return index_html_response()
@app.get("/login/", response_class=HTMLResponse)
async def details():
return enter_details()
@app.get("/chatbot_question/", response_class=HTMLResponse)
async def chatbot_ques():
return chatbot_ques_html()
@app.post("/chatbot_answer/", response_class=HTMLResponse)
async def chatbot_ans(request: Request, question: str = Form(...)):
return chatbot_ans_html(question)
@app.post("/check_login/",response_class=HTMLResponse)
async def check_details(request: Request, username: str = Form(...), password: str = Form(...)):
print(username)
print(password)
#return login_details(request)
@app.post("/form")
def form_post(request: Request, username: str = Form(...)):
result = username
print(username)
return templates.TemplateResponse('form.html', context={'request': request, 'result': result})