Mini Project : Make a Chatbot !

 
In this Mini Project, we are gonna create a ChatBot (Interaction between a man and a machine) using the ChatterBot library from Python. So let's get started !
 
Concepts used in the code :- 

  • ChatterBot Module
  • os Module
  • Print
  • If Statement

In this particular project , we are gonna train the Bot using a set of predefined speech datas called Corpus. The Corpus contains many languages like French, German, Hindi, English, etc. In our case, we are gonna use the English Corpus to train our Bot. (Download the Corpus here).

Code:-

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os

bot = ChatBot('Bot')
bot.set_Trainer(ListTrainer)

for files in os.listdir('/Users/guruela/Downloads/ChatterBot_Corpus_English/data/english/'):
    data = open('/Users/guruela/Downloads/ChatterBot_Corpus_English/data/english/' + files ,'r').readlines()
    bot.train(data)

while True:
    message = input('You:')
    if message.strip() != 'Bye':
        reply = bot.get_response(message)
        print("ChatBot:",reply)
    if message.strip() == 'Bye':
        print("ChatBot:Bye")
        break

 

Demo:-



Comments

Popular Posts