-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz_bot.py
65 lines (50 loc) · 1.58 KB
/
quiz_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
import string
import aiml
from nlp.nlp import NLP
from nlp.BERTnlp import BERTNLP
from utils.util import from_mic, response_agent, read_from_file
from utils.constants import AIML, NAME_FILE, TOPIC_FILE
kern = aiml.Kernel()
kern.setTextEncoding(None)
kern.bootstrap(learnFiles=AIML)
nlp = None
if (len(sys.argv) >= 2 and sys.argv[1].lower().strip() == "bert"):
print("Loading BERT NLP")
nlp = BERTNLP()
else:
print("Loading standard NLP")
nlp = NLP()
# Set any previously mentioned data back into aiml
name = read_from_file(NAME_FILE).strip()
fav_topic = read_from_file(TOPIC_FILE).strip()
if name != "":
kern.respond("my name is " + name)
if fav_topic != "":
kern.respond("my favourite topic is " + fav_topic)
print("")
print("=======================================")
print("Hello, my name is quizo the quiz bot !")
print("I am here to serve your quiz needs (I specialise in maps).")
print("")
print("HINT: Type in 'voice' to use voice recognition.")
print("=======================================")
print("")
while True:
try:
user_input = input("> ")
except (KeyboardInterrupt, EOFError) as e:
print("Bye!")
break
voice = False
if user_input.lower().strip() == "voice":
user_input = from_mic()
print("> " + user_input)
voice = True
user_input = user_input.strip().lower()
user_input = user_input.translate(str.maketrans('', '', string.punctuation))
answer = kern.respond(user_input)
response = response_agent(answer, nlp, voice)
voice = False
if (response == "quit"):
break