File size: 1,224 Bytes
c98d0b1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()