Dog / chatbot.py
bill-billard's picture
Upload chatbot.py
c98d0b1 verified
Raw History Blame Contribute Delete
1.22 kB
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
# Initialize the chatbot with the name "Dog"
chatbot = ChatBot(
'Dog', # Changed chatbot name to 'Dog'
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
'chatterbot.logic.BestMatch',
'chatterbot.logic.MathematicalEvaluation'
],
database_uri='sqlite:///database.db'
)
# Create and train the chatbot
trainer = ChatterBotCorpusTrainer(chatbot)
# Train with the English language corpus
trainer.train('chatterbot.corpus.english')
# Function to interact with the chatbot
def talk_to_bot():
print("Woof! I'm Dog, your friendly chatbot. Type 'exit' to stop the conversation.")
while True:
try:
user_input = input("You: ")
if user_input.lower() == 'exit':
print("Goodbye! Bark you later!")
break
# Get a response from Dog
bot_response = chatbot.get_response(user_input)
print(f"Dog: {bot_response}")
except (KeyboardInterrupt, EOFError, SystemExit):
break
# Start the conversation
if __name__ == "__main__":
talk_to_bot()