Skip to content

Install from source code

Omid Foroqi edited this page Sep 7, 2021 · 15 revisions

Clone Rasa branch

git clone https://github.com/MedBot-team/NaBot --single-branch --depth 1

Directory tree

To run the NaBot, we need to run actions-server and chatbot-server separately. So we've separated actions, datasets, and the chatbot from each other.

Action-Server will contain actions and datasets, and Rasa-Server will contain the chatbot model and its autocorrect component.

production/
├── action-server
│   ├── actions
│   └── docker
├── datasets-server
├── events-server
├── monitoring-server
│   └── monitoring_ui
├── nginx
├── rasa-server
│   ├── docker
│   └── rasa
│       ├── data
│       ├── dictionary
│       ├── domain
│       ├── tests
│       └── train_test_split
└── streamlit-server
    └── streamlit

In the rest of the document, we will install requirements and then run chatbot and action servers.

Install requirements

Create python environment

pip install --user virtualenv
python -m venv rasa_env

Activate your python environment

source rasa_env/bin/activate
pip install --upgrade pip

Install rasa chatbot server and actions server requirements

pip install --no-cache-dir -r production/rasa-server/requirements.txt -r production/action-server/requirements.txt

Download Spacy weights

python -m spacy download en_core_web_md

Download the autocorrect module dictionaries. This dictionary consists of English and medical words.

cd production/rasa-server
python -c "import autocorrect; autocorrect.Speller('en_med')"

Train rasa model ⌛

cd production/rasa-server/rasa
rasa train

You can also download model weights from Dropbox and then put them into models directory.

Run rasa server

We are almost done. Now we can run the rasa and actions server.

  • Change rasa action_endpoint:

    Edit production/rasa-server/rasa/endpoints.yml file and then change it to the following line:

 url: "http://app:5055/webhook"

to:

 url: "http://localhost:5055/webhook"
  • Run the Rasa server. If you would like to run the Rasa server with tokens to authenticate requests, You can add --auth-token YOUR_TOKEN at the end of the following command
cd production/rasa-server/rasa
mkdir -p logs ../autocorrect/data
rasa run --log-file logs/rasa-server.log --enable-api

Run the MySQL server

 mysql -uroot -p"$MYSQL_ROOT_PASSWORD" datasets < mysql-server/datasets.sql

Run the action server

  • Create logs directory
cd production/action-server/actions
mkdir logs
  • Create .env file in action-server directory, to read database information:
$ cat action-server/.env
MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
SQL_USER=root
HOST=localhost
MYSQL_DATABASE=datasets
DRUG_TABLE=drugs
LAB_TABLE=labs
  • Run action server
rasa run --log-file logs/action-server.log actions --actions actions

Enjoy chatting with NaBot 🤗

  • Using curl
curl --location --request POST 'http://localhost:5005/webhooks/rest/webhook' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message" : "Can you give me dosage information of Abilify?",
    "sender" : "default"
}'
  • Use Streamlit UI

Create .env file in the streamlit directory:

$ cat ./production/streamlit-server/streamlit/.env
RASA_SERVER_URL=http://localhost:5005/webhooks/rest/webhook

Install build dependencies

python -m venv streamlit
source streamlit/bin/activate
pip install --upgrade pip

Install python development packages in the your OS. For example in the Ubuntu case: (x in the following command is your python version. It should be greater than 3.6

sudo apt install python3.x-dev build-essential

Install Streamlit:

pip install --no-cache-dir -r production/streamlit-server/requirements.txt

Run Streamlit UI:

cd ./production/streamlit-server/streamlit
streamlit run medbot_ui.py

Open the following URL in your browser

http://localhost:8501

More examples of sending a request to the chatbot

Clone this wiki locally