This repository was archived by the owner on Dec 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot.py
More file actions
45 lines (35 loc) · 1.21 KB
/
chatbot.py
File metadata and controls
45 lines (35 loc) · 1.21 KB
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
41
42
43
44
45
import os
import aiml
import commands_creater
ai_name = commands_creater.ai_name_parse() # The name of the AI that is to be used
def chatbot_response(command):
BRAIN_FILE="brain_dump/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="xml_file/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:
try:
#input_text = input("USER --> ")
input_text = command
#if (("exit" in input_text.lower()) == True) or (("close" in input_text.lower()) == True):
# return ("break")
#else:
response = k.respond(input_text)
print(f"{ai_name} --> {response}") # Response Format -> F.R.I.D.A.Y --> I am good
return response
except KeyboardInterrupt:
print("EXIT\nThankyou for using me")
exit()