-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathchatbot.py
More file actions
executable file
·28 lines (24 loc) · 768 Bytes
/
chatbot.py
File metadata and controls
executable file
·28 lines (24 loc) · 768 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
#!/usr/bin/python3
import os
import aiml
BRAIN_FILE="brain.dump"
k = aiml.Kernel()
# To increase the startup speed of the bot it is
# possible to save the parsed aiml files as a
# dump. This code checks if a dump exists and
# otherwise loads the aiml from the xml files
# and saves the brain dump.
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="std-startup.aiml", commands="load aiml b")
print("Saving brain file: " + BRAIN_FILE)
k.saveBrain(BRAIN_FILE)
# Endless loop which passes the input to the bot and prints
# its response
while True:
input_text = input("> ")
response = k.respond(input_text)
print(response)