In this blog, you’ll learn how to interface with Rasa via Flask. Read on!
To get started with Rasa, first you need to install Rasa by executing the code below in your command line application:
After installing Rasa, to create a new project use, rasa init --no-prompt
. This will create a basic template of a chatbot.
Now just simply run the command, rasa train
. This will train your chatbot.
After training the chatbot run the command rasa shell --debug
After executing the command you can see something like this. This is the Rasa shell where you can test your chatbot.
Type some basic commands like “hi”, “hello”, “bye”. This will give the response that you defined in the domain.yml file.
Looks like everything is fine in our shell!
Let’s see how we can run the Rasa server in our local machine. This Rasa server will return all the responses in the form of a JSON response. To run the Rasa server use this command,
After running this command you can make HTTP requests in http://localhost:5005
Setting up our Flask server:
Install Flask using the command,
The above code imports all the necessary modules to make all HTTP requests.
On our website, we are going to have a simple form that gets the text from the user and gives the response to the user.
Create a folder called “Template”, inside the folder create a “index.html” file. The HTML will look like this,
Now let’s integrate this form on our site.
The above code will render a form on the homepage.
The above line will get the text parameter entered in the form and convert it as a string.
After getting the string from the user text, convert it into the JSON format.
Now make the post request to our Rasa server.
It responds with JSON. Something like this
Let’s wrap it up!
The whole code will look like this in the final part. Now in your terminal run app.py
Hope you found this blog useful, now you can integrate your Rasa chatbot with your Flask server.