Spaces:
Configuration error
Configuration error
Upload 4 files
Browse files- main-raw.py +21 -0
- main.py +35 -0
- requirements.txt +2 -0
main-raw.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import aiml
|
2 |
+
import os
|
3 |
+
|
4 |
+
kernel = aiml.Kernel()
|
5 |
+
|
6 |
+
if os.path.isfile("bot_brain.brn"):
|
7 |
+
kernel.bootstrap(brainFile = "bot_brain.brn")
|
8 |
+
else:
|
9 |
+
kernel.bootstrap(learnFiles = os.path.abspath("aiml/std-startup.xml"), commands = "load aiml b")
|
10 |
+
kernel.saveBrain("bot_brain.brn")
|
11 |
+
|
12 |
+
# kernel now ready for use
|
13 |
+
while True:
|
14 |
+
message = raw_input("Enter your message to the bot: ")
|
15 |
+
if message == "quit":
|
16 |
+
exit()
|
17 |
+
elif message == "save":
|
18 |
+
kernel.saveBrain("bot_brain.brn")
|
19 |
+
else:
|
20 |
+
bot_response = kernel.respond(message)
|
21 |
+
print bot_response
|
main.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
import aiml
|
3 |
+
import os
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
@app.route("/")
|
8 |
+
def hello():
|
9 |
+
return render_template('chat.html')
|
10 |
+
|
11 |
+
@app.route("/ask", methods=['POST'])
|
12 |
+
def ask():
|
13 |
+
message = request.form['messageText'].encode('utf-8').strip()
|
14 |
+
|
15 |
+
kernel = aiml.Kernel()
|
16 |
+
|
17 |
+
if os.path.isfile("bot_brain.brn"):
|
18 |
+
kernel.bootstrap(brainFile = "bot_brain.brn")
|
19 |
+
else:
|
20 |
+
kernel.bootstrap(learnFiles = os.path.abspath("aiml/std-startup.xml"), commands = "load aiml b")
|
21 |
+
kernel.saveBrain("bot_brain.brn")
|
22 |
+
|
23 |
+
# kernel now ready for use
|
24 |
+
while True:
|
25 |
+
if message == "quit":
|
26 |
+
exit()
|
27 |
+
elif message == "save":
|
28 |
+
kernel.saveBrain("bot_brain.brn")
|
29 |
+
else:
|
30 |
+
bot_response = kernel.respond(message)
|
31 |
+
# print bot_response
|
32 |
+
return jsonify({'status':'OK','answer':bot_response})
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
app.run(host='0.0.0.0', debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
flask>=0.12.3
|
2 |
+
aiml==0.8.6
|