|
a |
|
b/medbot.sh |
|
|
1 |
#!/bin/bash |
|
|
2 |
|
|
|
3 |
# Find out GNU/Linux version and distribution |
|
|
4 |
if [ -f /etc/os-release ]; then |
|
|
5 |
. /etc/os-release |
|
|
6 |
OS=$NAME |
|
|
7 |
VER=$VERSION_ID |
|
|
8 |
elif type lsb_release >/dev/null 2>&1; then |
|
|
9 |
OS=$(lsb_release -si) |
|
|
10 |
VER=$(lsb_release -sr) |
|
|
11 |
elif [ -f /etc/lsb-release ]; then |
|
|
12 |
. /etc/lsb-release |
|
|
13 |
OS=$DISTRIB_ID |
|
|
14 |
VER=$DISTRIB_RELEASE |
|
|
15 |
elif [ -f /etc/debian_version ]; then |
|
|
16 |
OS=Debian |
|
|
17 |
VER=$(cat /etc/debian_version) |
|
|
18 |
else |
|
|
19 |
OS=$(uname -s) |
|
|
20 |
VER=$(uname -r) |
|
|
21 |
fi |
|
|
22 |
|
|
|
23 |
# Check GNU/Linux distribution, version and MySQL server has been installed or not |
|
|
24 |
if [[ $OS == 'Ubuntu' ]]; then |
|
|
25 |
if (($(echo "$VER >= 18.04" | bc -l))); then |
|
|
26 |
# Check if MySQL server is installed or not |
|
|
27 |
if (dpkg -l | grep -Fq "mysql-server"); then |
|
|
28 |
read -rep "Warning: You already have MySQL server installed on your system. This script will modify your MySQL configuration. And this may cause data loss in your databases. Please follow the installation manually according to the Wikis. If you insist to follow setup procedures, please type YES. In the case of exit, press any other keys: " follow |
|
|
29 |
if [[ $follow != 'YES' ]]; then |
|
|
30 |
exit 0 |
|
|
31 |
fi |
|
|
32 |
fi |
|
|
33 |
else |
|
|
34 |
echo "Unfortunately we're not support your operating system officially. But you can follow our instruction in the Wikis to install chatbot manually or use Docker to install this chatbot." |
|
|
35 |
exit 0 |
|
|
36 |
fi |
|
|
37 |
else |
|
|
38 |
echo "Unfortunately we're not support your operating system officially. But you can follow our instruction in the Wikis to install chatbot manually or use Docker to install this chatbot." |
|
|
39 |
exit 0 |
|
|
40 |
fi |
|
|
41 |
|
|
|
42 |
# Set environment virables |
|
|
43 |
echo "Set environment virables from .env file" |
|
|
44 |
|
|
|
45 |
set -a |
|
|
46 |
source production/.env |
|
|
47 |
set +a |
|
|
48 |
|
|
|
49 |
if [[ $OS == 'Ubuntu' && (($(echo "$VER >= 18.04" | bc -l))) ]]; then |
|
|
50 |
# Install chatbot dependencies |
|
|
51 |
echo "Install requirements" |
|
|
52 |
sudo apt-get update |
|
|
53 |
sudo apt-get install -y wget build-essential python3.8 python3.8-dev python3.8-venv python3-pip mysql-server libmysqlclient-dev |
|
|
54 |
|
|
|
55 |
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/ |
|
|
56 |
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld |
|
|
57 |
|
|
|
58 |
sudo apt install -f |
|
|
59 |
|
|
|
60 |
# Download and install libmysqlclient20 in the case of newer version of Ubuntu, which libmysqlclient20 is replaced by libmysqlclient21 |
|
|
61 |
if (($(echo "$VER > 18.04" | bc -l))); then |
|
|
62 |
TEMP_DEB="$(mktemp)" |
|
|
63 |
wget -O "$TEMP_DEB" 'http://security.ubuntu.com/ubuntu/pool/main/m/mysql-5.7/libmysqlclient20_5.7.35-0ubuntu0.18.04.1_amd64.deb' |
|
|
64 |
sudo dpkg -i "$TEMP_DEB" |
|
|
65 |
rm -f "$TEMP_DEB" |
|
|
66 |
fi |
|
|
67 |
|
|
|
68 |
# Configure MySQL server |
|
|
69 |
echo "Configure MySQL settings" |
|
|
70 |
|
|
|
71 |
# Change mysql user password plugin to mysql_native_password |
|
|
72 |
sudo mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '${MYSQL_ROOT_PASSWORD}'" |
|
|
73 |
|
|
|
74 |
# Make our changes take effect |
|
|
75 |
sudo mysql -u ${SQL_USER} -p${MYSQL_ROOT_PASSWORD} -e "FLUSH PRIVILEGES" |
|
|
76 |
|
|
|
77 |
# Create mysql database for datasets storing |
|
|
78 |
sudo mysql -u ${SQL_USER} -p${MYSQL_ROOT_PASSWORD} -e "CREATE DATABASE IF NOT EXISTS ${MYSQL_DATABASE}" |
|
|
79 |
|
|
|
80 |
# Create mysql database to store logs |
|
|
81 |
sudo mysql -u ${SQL_USER} -p${MYSQL_ROOT_PASSWORD} -e "CREATE DATABASE IF NOT EXISTS ${MYSQL_EVENTS_DATABASE}" |
|
|
82 |
|
|
|
83 |
# Load datasets to the MySQL server |
|
|
84 |
echo "Load mysql dumps to the dataset" |
|
|
85 |
|
|
|
86 |
# Change charset of MySQL dump |
|
|
87 |
sed -i 's/utf8mb4_0900_ai_ci/utf8_general_ci/g' production/mysql-server/datasets.sql |
|
|
88 |
sed -i 's/utf8mb4/utf8/g' production/mysql-server/datasets.sql |
|
|
89 |
mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" datasets <production/mysql-server/datasets.sql |
|
|
90 |
fi |
|
|
91 |
|
|
|
92 |
# Create python virtual environment for rasa chatbot |
|
|
93 |
echo "Create virtual environment for rasa" |
|
|
94 |
python3.8 -m venv ~/.env/rasa_env |
|
|
95 |
source ~/.env/rasa_env/bin/activate |
|
|
96 |
|
|
|
97 |
# Install python requirements |
|
|
98 |
pip install --upgrade pip |
|
|
99 |
pip install -r production/rasa-server/requirements.txt -r production/action-server/requirements.txt |
|
|
100 |
|
|
|
101 |
echo "Download spacy mode weights" |
|
|
102 |
python -m spacy download en_core_web_md |
|
|
103 |
|
|
|
104 |
echo "Make data directory in rasa" |
|
|
105 |
mkdir -p production/rasa-server/autocorrect/data |
|
|
106 |
( |
|
|
107 |
cd production/rasa-server |
|
|
108 |
python -c "import autocorrect; autocorrect.Speller('en_med')" |
|
|
109 |
) |
|
|
110 |
|
|
|
111 |
envsubst <production/rasa-server/rasa/endpoints.yml | tee production/rasa-server/rasa/endpoints.yml >/dev/null |
|
|
112 |
|
|
|
113 |
echo "Download model weights" |
|
|
114 |
mkdir -p production/rasa-server/rasa/models production/rasa-server/rasa/logs |
|
|
115 |
wget -c https://www.dropbox.com/s/u1o8s2u96lpt8cv/v0.1.0.tar.gz -P production/rasa-server/rasa/models |
|
|
116 |
|
|
|
117 |
# Configure action server |
|
|
118 |
mkdir -p production/action-server/logs |
|
|
119 |
cp production/.env production/action-server/.env |
|
|
120 |
|
|
|
121 |
# UI server |
|
|
122 |
echo "Create virtual environment for Streamlit UI" |
|
|
123 |
python3.8 -m venv ~/.env/ui_env |
|
|
124 |
source ~/.env/ui_env/bin/activate |
|
|
125 |
|
|
|
126 |
# Install python requirements |
|
|
127 |
pip install --upgrade pip |
|
|
128 |
pip install -r production/streamlit-server/requirements.txt |
|
|
129 |
|
|
|
130 |
# Configure UI server |
|
|
131 |
cp production/.env production/streamlit-server/.env |
|
|
132 |
|
|
|
133 |
echo -e "It's Done. Run the following commands to start chatbot\n |
|
|
134 |
In the $(pwd)/production/action-server directory: |
|
|
135 |
(source ~/.env/rasa_env/bin/activate; rasa run --log-file logs/action-server.log actions --actions actions)\n |
|
|
136 |
In the $(pwd)/production/rasa-server/rasa directory: |
|
|
137 |
(source ~/.env/rasa_env/bin/activate; rasa run --log-file logs/rasa-server.log --enable-api)\n |
|
|
138 |
And In the $(pwd)/production/streamlit-server/streamlit |
|
|
139 |
(source ~/.env/ui_env/bin/activate; streamlit run medbot_ui.py)" |