VOOZH about

URL: https://towardsdatascience.com/chatbot-complete-pycharm-app-3517b64075f2/

โ‡ฑ Chatbot: Complete Pycharm App | Towards Data Science


Skip to content

Chatbot: Complete Pycharm App

Chatterbot, Django, Python and Pycharm all unified in this ready to go Chatbot App.

4 min read
๐Ÿ‘ Image by author
Image by author

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):

๐Ÿ‘ Image

Then open PyCharm and click on "New Project":

๐Ÿ‘ Image

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:

๐Ÿ‘ Make sure that the folder "venv" is empty. If not, just delete all files in that folder.
Make sure that the folder "venv" is empty. If not, just delete all files in that folder.

After confirming you want to create from existing sources:

๐Ÿ‘ Image

As a next step, add Configuration:

๐Ÿ‘ Image

..and click on the plus symbol in the left top corner:

๐Ÿ‘ Image

where these settings have to be entered:

๐Ÿ‘ Image

From now on you can simply start Manage.py by clicking the Run button:

๐Ÿ‘ Image

..and click on the localhost link which will be started after a few seconds:

๐Ÿ‘ Image

In case there are now import errors popping up, similar to this:

๐Ÿ‘ Image

..all you have to do is to go to settings and import the necessary packages in the Python Interpreter section:

๐Ÿ‘ Image

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:

๐Ÿ‘ Image

If you now run "manage.py" again, you might receive this message the first time you want to start your chatbot:

๐Ÿ‘ Image

In this case please go to your Terminal and enter:

python manage.py migrate
๐Ÿ‘ Image

Now run manage.py again and your Chatbot should work in your browser:

๐Ÿ‘ Enter your input and click on the Post button below.
Enter your input and click on the Post button below.

You enter a question and our bot will hopefully give us the right answer:

๐Ÿ‘ Image

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:

๐Ÿ‘ In our example we have used English and German input-output mappings.
In our example we have used English and German input-output mappings.

If you prefer yaml files instead of the chats.txt, you can also adapt any of these corpus files:

๐Ÿ‘ Image

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:

๐Ÿ‘ Image

Then enter a new DB Connection:

๐Ÿ‘ Image

Choose SQLite and add db.sqlite3 as Database file:

๐Ÿ‘ Click on Test Connection to check if it is working properly.
Click on Test Connection to check if it is working properly.

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:

๐Ÿ‘ Image
๐Ÿ‘ Just delete these files, if you want to start learning from zero.
Just delete these files, if you want to start learning from zero.

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.

Join Medium with my referral link โ€“ Jesko Rehberg

Originally published on my website DAR-Analytics.


Written By

Jesko Rehberg

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

Related Articles