-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (34 loc) · 944 Bytes
/
main.py
File metadata and controls
46 lines (34 loc) · 944 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
37
38
39
40
41
42
43
44
45
46
#
# Author: Lucas Rager
# A chatbot api.
#
from flask import Flask, request
from collections import namedtuple
app = Flask(__name__)
# Home page
@app.route('/')
def index():
return f'<h1>Test Home Page.</h1>'
# Api endpoint
@app.route('/api')
def api():
user_input = request.args.get('input')
response = generate_response(user_input)
json = {
'input': user_input,
'response': response.response,
'accuracy': response.accuracy
}
return json
# Tuple for returning responses
Response = namedtuple('Response', 'response accuracy')
def generate_response(user_input: str) -> Response:
lowercase_input = user_input.lower()
if lowercase_input == "hello":
return Response("Hey there!", 1)
elif lowercase_input == "goodbye":
return Response("See you later!", 1)
else:
return Response("Could not understand.", 0)
if __name__ == '__main__':
app.run()