/
app.py
40 lines (30 loc) · 910 Bytes
/
app.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
import os
import aiml
from autocorrect import spell
from flask import Flask, render_template, request
app = Flask(__name__)
BRAIN_FILE = "pretrained_model/pretrainedModel.dump"
k = aiml.Kernel()
if os.path.exists(BRAIN_FILE):
print("Loading from brain file: " + BRAIN_FILE)
k.loadBrain(BRAIN_FILE)
else:
print("Parsing aiml_package files")
k.bootstrap(learnFiles="pretrained_model/learningFileList.aiml", commands="load aiml")
print("Saving brain file: " + BRAIN_FILE)
k.saveBrain(BRAIN_FILE)
@app.route("/")
def home():
return render_template("home.html")
@app.route("/get")
def get_bot_response():
query = request.args.get('msg')
query = [spell(w) for w in (query.split())]
question = " ".join(query)
response = k.respond(question)
if response:
return str(response)
else:
return str(":)")
if __name__ == "__main__":
app.run()