Merge pull request #366 from pierotofy/lt

Run helper script, misc improvements
This commit is contained in:
Piero Toffanin 2022-12-20 11:57:46 -05:00 committed by GitHub
commit 5a2e0fe656
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 147 additions and 12 deletions

View file

@ -24,7 +24,7 @@ FROM python:3.8.14-slim-bullseye
ARG with_models=false
ARG models=
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate
RUN addgroup --system --gid 1032 libretranslate && adduser --system --uid 1032 libretranslate && mkdir -p /home/libretranslate/.local && chown -R libretranslate:libretranslate /home/libretranslate/.local
USER libretranslate
COPY --from=builder --chown=1032:1032 /app /app

View file

@ -130,11 +130,8 @@ Then open a web browser to http://localhost:5000
### Run with Docker
Simply run:
```bash
docker run -ti --rm -p 5000:5000 libretranslate/libretranslate
```
Linux/MacOS: `./run.sh [args]`
Windows: `run.bat [args]`
Then open a web browser to http://localhost:5000
@ -160,7 +157,7 @@ docker-compose up -d --build
> Feel free to change the [`docker-compose.yml`](https://github.com/LibreTranslate/LibreTranslate/blob/main/docker-compose.yml) file to adapt it to your deployment needs, or use an extra `docker-compose.prod.yml` file for your deployment configuration.
> The models are stored inside the container under `/root/.local/share` and `/root/.local/cache`. Feel free to use volumes if you do not want to redownload the models when the container is destroyed. Be aware that this will prevent the models from being updated!
> The models are stored inside the container under `/home/libretranslate/.local/share` and `/home/libretranslate/.local/cache`. Feel free to use volumes if you do not want to redownload the models when the container is destroyed. To update the models, use the `--update-models` argument.
### CUDA
@ -198,6 +195,7 @@ docker-compose -f docker-compose.cuda.yml up -d --build
| --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS |
| --disable-files-translation | Disable files translation | `false` | LT_DISABLE_FILES_TRANSLATION |
| --disable-web-ui | Disable web ui | `false` | LT_DISABLE_WEB_UI |
| --update-models | Update language models at startup | `false` | LT_UPDATE_MODELS |
Note that each argument has an equivalent environment variable that can be used instead. The env. variables overwrite the default values but have lower priority than the command arguments and are particularly useful if used with Docker. The environment variable names are the upper-snake-case of the equivalent command argument's name with a `LT` prefix.

View file

@ -1 +1 @@
1.3.3
1.3.4

View file

@ -100,7 +100,7 @@ def get_routes_limits(default_req_limit, daily_req_limit, api_keys_db):
def create_app(args):
from app.init import boot
boot(args.load_only)
boot(args.load_only, args.update_models)
from app.language import load_languages

View file

@ -156,6 +156,11 @@ _default_options_objects = [
'default_value': False,
'value_type': 'bool'
},
{
'name': 'UPDATE_MODELS',
'default_value': False,
'value_type': 'bool'
},
]

View file

@ -5,9 +5,9 @@ from argostranslate import package, translate
import app.language
def boot(load_only=None):
def boot(load_only=None, update_models=False):
try:
check_and_install_models(load_only_lang_codes=load_only)
check_and_install_models(force=update_models, load_only_lang_codes=load_only)
except Exception as e:
print("Cannot update models (normal if you're offline): %s" % str(e))

View file

@ -144,7 +144,9 @@ def get_args():
parser.add_argument(
"--disable-web-ui", default=DEFARGS['DISABLE_WEB_UI'], action="store_true", help="Disable web ui"
)
parser.add_argument(
"--update-models", default=DEFARGS['UPDATE_MODELS'], action="store_true", help="Update language models at startup"
)
return parser.parse_args()

0
db/.gitignore vendored Normal file
View file

41
run.bat Normal file
View file

@ -0,0 +1,41 @@
@ECHO OFF
SETLOCAL
SET LT_PORT=5000
:loop
IF NOT "%1"=="" (
IF "%1"=="--port" (
SET LT_PORT=%2
SHIFT
)
IF "%1"=="--help" (
echo Usage: run.bat [--port N]
echo:
echo Run LibreTranslate using docker.
echo:
GOTO :done
)
IF "%1"=="--api-keys" (
SET DB_VOLUME=-v lt-db:/app/db
SHIFT
)
SHIFT
GOTO :loop
)
WHERE /Q docker
IF %ERRORLEVEL% NEQ 0 GOTO :install_docker
docker run -ti --rm -p %LT_PORT%:%LT_PORT% %DB_VOLUME% -v lt-local:/home/libretranslate/.local libretranslate/libretranslate %*
GOTO :done
:install_docker
ECHO Cannot find docker! Go to https://docs.docker.com/desktop/install/windows-install/ and install docker before running this script (pressing Enter will open the page)
pause
start "" https://docs.docker.com/desktop/install/windows-install/
GOTO :done
:done

89
run.sh Executable file
View file

@ -0,0 +1,89 @@
#!/bin/bash
set -eo pipefail
__dirname=$(cd "$(dirname "$0")"; pwd -P)
cd "${__dirname}"
platform="Linux" # Assumed
uname=$(uname)
case $uname in
"Darwin")
platform="MacOS / OSX"
;;
MINGW*)
platform="Windows"
;;
esac
usage(){
echo "Usage: $0 [--port N]"
echo
echo "Run LibreTranslate using docker."
echo
exit
}
export LT_PORT=5000
# Parse args for overrides
ARGS=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--port)
export LT_PORT="$2"
ARGS+=("$1")
ARGS+=("$2") # save it in an array for later
shift # past argument
shift # past value
;;
--debug)
export LT_DEBUG=YES
ARGS+=("$1")
shift # past argument
;;
--api-keys)
export DB_VOLUME="-v lt-db:/app/db"
ARGS+=("$1")
shift # past argument
;;
--help)
usage
;;
*) # unknown option
ARGS+=("$1")
shift # past argument
;;
esac
done
# $1 = command | $2 = help_text | $3 = install_command (optional)
check_command(){
hash "$1" 2>/dev/null || not_found=true
if [[ $not_found ]]; then
check_msg_prefix="Checking for $1... "
# Can we attempt to install it?
if [[ -n "$3" ]]; then
echo -e "$check_msg_prefix \033[93mnot found, we'll attempt to install\033[39m"
$3 || sudo $3
# Recurse, but don't pass the install command
check_command "$1" "$2"
else
check_msg_result="\033[91m can't find $1! Check that the program is installed and that you have added the proper path to the program to your PATH environment variable before launching WebODM. If you change your PATH environment variable, remember to close and reopen your terminal. $2\033[39m"
fi
fi
echo -e "$check_msg_prefix $check_msg_result"
if [[ $not_found ]]; then
return 1
fi
}
environment_check(){
check_command "docker" "https://www.docker.com/"
}
environment_check
docker run -ti --rm -p $LT_PORT:$LT_PORT $DB_VOLUME -v lt-local:/home/libretranslate/.local libretranslate/libretranslate ${ARGS[@]}