#install the module:
# pip install chatterbot
# Import "chatbot" from
# chatterbot package.
from chatterbot import ChatBot
# Inorder to train our bot, we have
# to import a trainer package
# "ChatterBotCorpusTrainer"
from chatterbot.trainers import ChatterBotCorpusTrainer
# Give a name to the chatbot “chat bot”
# and assign a trainer component.
chatbot=ChatBot('chat bot')
# Create a new trainer for the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)
# Now let us train our bot with multiple corpus
trainer.train("chatterbot.corpus.english.greetings",
"chatterbot.corpus.english.conversations" )
response = chatbot.get_response('What is your Number')
print(response)
response = chatbot.get_response('Who are you?')
print(response)
#****************** Create chatbot in Python - Source: NAYCode.com
from nltk.chat.util import Chat, reflections
pairs = [
[
r"my name is (.*)",
["Hello %1, How are you today ?",]
],
]
def MyChatbot_test():
print("Hi, I am your chatbot.")
chatbot=Chat(pairs, reflections)
chatbot.converse()
if __name__ == '__main__':
MyChatbot_test()
#**************** For more tutorial, visit NAYCode.com
from nltk.chat.util import Chat, reflections
pairs = [
[
r"my name is (.*)",
["Hello %1, How are you today ?",]
],
]
def MyChatbot_test():
print("Hi, I am your chatbot.")
chatbot=Chat(pairs, reflections)
chatbot.converse()
if __name__ == '__main__':
MyChatbot_test()