Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Importing the libraries
- from chatterbot import ChatBot
- from chatterbot.trainers import ListTrainer
- def convert_to_ascii(statement):
- """
- Converts unicode characters to ASCII character equivalents.
- For example: "på fédéral" becomes "pa federal".
- """
- import unicodedata
- text = unicodedata.normalize('NFKD', statement.text)
- text = text.encode('ascii', 'ignore').decode('utf-8')
- statement.text = str(text)
- return statement
- chatbot = ChatBot(
- 'Bob the Bot',
- preprocessors=[
- 'chatterbot.preprocessors.clean_whitespace'
- ],
- )
- #create the bot
- conv = open('chats.txt','r', encoding = 'utf-8', errors= 'ignore').read().split('\n')
- trainer = ListTrainer(chatbot)
- trainer.train(conv) #train the bot
- preprocessors = [
- 'chatterbot.preprocessors.clean_whitespace']
- logic_adapters = ['chatterbot.logic.BestMatch']
- while True:
- request = input('You: ')
- response = chatbot.get_response(request)
- print('bot:', response)
Advertisement
Add Comment
Please, Sign In to add comment