-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.py
94 lines (76 loc) · 3.16 KB
/
resources.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from fastapi.responses import HTMLResponse
import urllib
from bs4 import BeautifulSoup
from fastapi import Request as request
from fastapi import FastAPI, Form
from starlette.requests import Request
from collections import defaultdict
def index_html_response():
html_content = """
<html>
<body>
<button onclick="window.location.href='/index'">Home</button>
<button onclick="window.location.href='/hello'">Hello</button><br><br><br>
<button onclick="window.location.href='/chatbot_question'">Chatbot</button><br><br><br>
<button onclick="window.location.href='/login'">Details</button><br><br><br>
</body>
</html>
"""
return HTMLResponse(content=html_content, status_code=200)
def hello_html_response():
html_content = """
<html>
<body>
<button onclick="window.location.href='/index'">Home</button><br>
<b>hello world!</b>
</body>
</html>
"""
return HTMLResponse(content=html_content, status_code=200)
def enter_details():
html_content="""<form action=/check_login method='POST'>
<label> Username </label>
<input type='text' name='username'>
<label> Password </label>
<input type='text' name='password'>
<button type='submit'> Submit </button>
</form> """
soup = BeautifulSoup(html_content)
print(soup.get_text())
#print("html content",html_content)
return HTMLResponse(content=html_content, status_code=200)
def chatbot_ques_html():
html_content="""<form action=/chatbot_answer method='POST'>
<br><br><br><br><br><br>
<label> Ask me anything </label> <br><br>
<input type='text' name='question' maxlength="30" size="50">
<button type='submit'> Submit </button>
</form> """
return HTMLResponse(content=html_content, status_code=200)
def chatbot_ans_html(question):
with open("chatbot_sample_intents.csv", "r") as f:
content = f.readlines()
text_fields = question.split(" ")
predict_answer = {}
for line in content:
fields = line.strip().split(",")
target = fields[0]
count = sum([1 for word in text_fields if word in fields[1:]])
predict_answer[target] = count
answer = max(predict_answer, key=predict_answer.get)
html_content="""<html>
<body>
<br><br><br><br><br><br>
""" + answer + """
<br><br><button onclick="window.location.href='/chatbot_question'">Another question</button>
<button onclick="window.location.href='/index'">Home</button>
</body>
</html> """
return HTMLResponse(content=html_content, status_code=200)
def login_details(request):
print("request is--->",Request.stream('username'))
#username=request.form['username']
#password = request.form['password']
#print("username is--->",username)
#print(password)
#return username, password