Chatbot: Complete Pycharm App
Chatterbot, Django, Python and Pycharm all unified in this ready to go Chatbot App.
Motivation:
Are you looking for a completely ready-to-go chatbot that you can easily adapt to your needs? Look no further if you are willing to use Python, Pycharm, Django, and Chatterbot combined. This app has an SQLite database to analyze user input and Chatbot output.
This post focuses on how to get a FAQ chatbot up and running without going into the theoretical background of chatterbot, which will be the topic of another related post.
Solution:
First of all please make sure you have PyCharm installed. If not, please do so now:
go to www.jetbrains.com and install the free community edition.
Afterwards, before starting a new project in PyCharm, please copy all files from my Google Drive folder: https://drive.google.com/drive/folders/1IXXJzNr8pbGFSIYpWj92fXnQX35eZOFT?usp=sharing
..and copy that into your PyCharm Projects folder (usually in your users folder):
Then open PyCharm and click on "New Project":
Choose the ChatbotProject folder (which you have downloaded from my Google Cloud just before) as the location for your new virtual environment (virtualenv) project. Make also sure that the Python Interpreter is directed to Python 3.7:
After confirming you want to create from existing sources:
As a next step, add Configuration:
..and click on the plus symbol in the left top corner:
where these settings have to be entered:
From now on you can simply start Manage.py by clicking the Run button:
..and click on the localhost link which will be started after a few seconds:
In case there are now import errors popping up, similar to this:
..all you have to do is to go to settings and import the necessary packages in the Python Interpreter section:
Please make sure that Django 2.2 and Chatterbot 1.0.2. is installed. That will ensure to work well with Python 3.7 for our chatterbot:
If you now run "manage.py" again, you might receive this message the first time you want to start your chatbot:
In this case please go to your Terminal and enter:
python manage.py migrate
Now run manage.py again and your Chatbot should work in your browser:
You enter a question and our bot will hopefully give us the right answer:
You can enter a question and your chatbot will give you an answer to this question. The reason the chatbot might know the right answer is due to your chats.txt, which you can adapt here:
If you prefer yaml files instead of the chats.txt, you can also adapt any of these corpus files:
Please note that all of them are chatterbot modules, except the FAQ. That one has been created by myself, for learning purposes:
Chatterbot is an extremely interesting chatbot which uses machine learning techniques. Please have a look at the Chatterbot website if you are looking for more details behind chatterbot.
Anything more to add?
Everything is now working well. But wouldnโt it be cool to even add a database connectivity, so we can analyze chatbotโs output to that userโs input?
Therefore we have to go to settings again, but this time we will install in the Plugin sector. Search for Database Navigator and install that plugin:
Then enter a new DB Connection:
Choose SQLite and add db.sqlite3 as Database file:
Looking into the table "statement", we can see all trained conversations, after we have run our Chatbot the first time after we have installed Database Navigator:
Congratulations. We have a complete chatbot running! We will discuss the chatterbot learning in detail in another post.
For the time being, many thanks for reading! I hope this article is helpful for you. Feel free to connect with me on LinkedIn, Twitter or Workrooms.
Originally published on my website DAR-Analytics.
Share This Article
Towards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.
Write for TDS