Download chatbot.py from Bill-Billard-Software/Dog: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/Bill-Billard-Software/Dog/resolve/main/chatbot.py
- Command line
-
hf download hf://Bill-Billard-Software/Dog/chatbot.py
-
curl -L -o chatbot.py https://huggingface.co/Bill-Billard-Software/Dog/resolve/main/chatbot.py
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() | |