Skip to content

Commit

Permalink
Update scripts, PyProcess.js
Browse files Browse the repository at this point in the history
  • Loading branch information
NguyenAnhTuan1912 committed Aug 18, 2024
1 parent fee3e50 commit 2a50b9c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions backend/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ infoln "Done!"
cd /home/backend

# Create `temp` and `uploads` folders
infoln "Create \`temp\` and \`uploads\` folders..."
mkdir temp
mkdir uploads
infoln "Done!"

# Start server
infoln "Booting server..."
Expand Down
2 changes: 2 additions & 0 deletions backend/nodejs/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export NVM_DIR="$HOME/.nvm"
# Change directory to `nodejs`
cd /home/backend/nodejs

export PYTHON_PATH="/home/backend/python/venv/bin/python"

# Start NodeJS Server
npm start

Expand Down
7 changes: 5 additions & 2 deletions backend/nodejs/src/classes/PyProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export class PyProcess {
DatatableImageToText: root + "/python/datatable_image_to_text.py",
};

constructor() {}
constructor() {
this.pythonPath = process.env.PYTHON_PATH || "python3";
}

/**
* Dùng phương thức này để tạo ra một python executer.
Expand All @@ -26,10 +28,11 @@ export class PyProcess {
*/
exec(script, ...args) {
// Use python3 (Linux)
const py_process = spawn("python3", [
const py_process = spawn(this.pythonPath, [
PyProcess.ScriptPaths[script],
...args,
]);

try {
return new Promise(function (res, rej) {
py_process.stdout.on("data", (data) => {
Expand Down
7 changes: 6 additions & 1 deletion backend/python/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ printf "Python has been just installed: $(python3 --version)"
apt install python3-pip
printf "PIP has just been installed: $(node -v)"

# Change directory to `backend`
# Change directory to `/home/backend/python`
cd /home/backend/python

## Install virtualenv and create virtual environment
pip3 install virtualenv
virtualenv venv
source venv/bin/activate

## Install packages in `requirements.txt`
pip3 install -r requirements.txt

Expand Down

0 comments on commit 2a50b9c

Please sign in to comment.