RASA Chatbot Deployment
RASA Chatbot Deployment
This article is a sequel of my previous article where I discussed about “My RASA journey with Tact Labs”.
After the creation of the chatbot, I tried to figure out where I could deploy it. Initially I faced many problems as there were no proper tutorials available. I figured out that deployment on Heroku using docker container was the best option.
Why HEROKU and DOCKER?
Heroku is a cloud service provider and software development platform which facilitates fast and effective building, deploying and scaling of web applications.
Its free and the deployment is really simple.
Heroku’s free tier comes with a limited amount of memory, whereas RASA chat bot with all the necessary dependencies takes up a lot of this memory.
This is where docker comes into the picture.
We use docker to containerise all the dependencies.
Deployment of the chatbot
In order to deploy a rasa chatbot and make it live , you must first have a rasa project. In case you don’t have one, you can create the basic project with the following command:
rasa init
Next go to your project directory and open the command prompt at that location
- Then Create a docker file with the following command:
nano Dockerfile
2. Add the following code to the dockerfile:
FROM ubuntu:20.04
ENTRYPOINT []
RUN
apt-get update && apt-get install -y python3 python3-pip
&& python3 -m pip install — no-cache — upgrade pip &&
pip3 install — no-cache rasa==2.0.2
ADD . /app/
RUN chmod +x /app/start_services.sh
CMD /app/start_services.sh
*** In the above code change the version of Ubuntu and RASA according to your version***
3. Next create the startservices.sh file in your project location with the following command:
nano startservices.sh
4. Add the following code to this file:
cd app/
# Start rasa server with nlu model
rasa run — model models — enable-api — cors “*” — debug \
-p $PORT
***Heroku will run the above code when accessing the project***
5. Next initialise the git repo for our project. To do this run the following commands:
git init
git add .
git commit -m “initialising project”
6. Next login to Heroku with the following command:
heroku login
7. If Heroku is not installed in your system then install it with the following command:
sudo snap install --classic heroku
8. Create an app in heroku and update all the dependencies inside a container with the following commands:
heroku create appname
heroku container:login
9. Finally push the project to the git repo that we earlier created with following commands:
heroku container:push web
***This step takes a lot of time based on your internet speed especially if its the first time you are doing it***
heroku container:release web
10. So we have completed the deployment of the chat bot. Now in order to check that the chat bot is live and running , create a python file:
nano main.py
11. Add the following code to the main.py file which sends a request to the webhook:
import requests
url = ‘http://appname.herokuapp.com/webhooks/rest/webhook'
myobj = {
“message”: “hi”,
}
x = requests.post(url, json = myobj)
print(x.text)
12. We can now access the chat bot with API calls
Now run the main.py file :
python3 main.py
We will get a json response as the output like this..
[{“recipient_id”:”1",”text”:”Hey!”}]
Author - Atul
References - https://medium.com/
Comments
Post a Comment