-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
35 lines (26 loc) · 877 Bytes
/
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
from flask import Flask, render_template, request, jsonify
import aiml
import os
app = Flask(__name__)
@app.route("/")
def hello():
return render_template('chat.html')
@app.route("/ask", methods=['POST'])
def ask():
message = request.form['messageText'].encode('utf-8').strip()
kernel = aiml.Kernel()
if os.path.isfile("bot_brain.brn"):
kernel.bootstrap(brainFile = "bot_brain.brn")
else:
kernel.bootstrap(learnFiles = os.path.abspath("aiml/std-startup.xml"), commands = "load aiml b")
kernel.saveBrain("bot_brain.brn")
while True:
if message == "quit":
exit()
elif message == "save":
kernel.saveBrain("bot_brain.brn")
else:
bot_response = kernel.respond(message)
return jsonify({'status':'OK','answer':bot_response})
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)