-
Notifications
You must be signed in to change notification settings - Fork 15
/
bot.py
42 lines (31 loc) · 958 Bytes
/
bot.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
from flask import Flask, render_template, request
import os
import aiml
from autocorrect import spell
app = Flask(__name__)
BRAIN_FILE="./pretrained_model/aiml_pretrained_model.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 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()
app.run(host='0.0.0.0', port='5000')