From 959f4638cc9bbccf70764e78e5364a7aaf7d7b00 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Tue, 20 Dec 2022 11:13:56 -0500 Subject: [PATCH] Named volume for db, --update-models arg --- README.md | 5 +++-- app/app.py | 2 +- app/default_values.py | 5 +++++ app/init.py | 4 ++-- app/main.py | 4 +++- lt.sh | 18 ++++++------------ 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b63f1f3..852b265 100644 --- a/README.md +++ b/README.md @@ -130,8 +130,8 @@ Then open a web browser to http://localhost:5000 ### Run with Docker -Linux/MacOS: `./lt.sh` -Windows: double-click `lt.bat` +Linux/MacOS: `./lt.sh [args]` +Windows: `lt.bat [args]` Then open a web browser to http://localhost:5000 @@ -195,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 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. diff --git a/app/app.py b/app/app.py index 9976ac0..f4c5019 100644 --- a/app/app.py +++ b/app/app.py @@ -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 diff --git a/app/default_values.py b/app/default_values.py index 343f22c..263d4ad 100644 --- a/app/default_values.py +++ b/app/default_values.py @@ -156,6 +156,11 @@ _default_options_objects = [ 'default_value': False, 'value_type': 'bool' }, + { + 'name': 'UPDATE_MODELS', + 'default_value': False, + 'value_type': 'bool' + }, ] diff --git a/app/init.py b/app/init.py index 4b081ac..d0c4de4 100644 --- a/app/init.py +++ b/app/init.py @@ -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)) diff --git a/app/main.py b/app/main.py index 6e24158..52aa06e 100644 --- a/app/main.py +++ b/app/main.py @@ -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() diff --git a/lt.sh b/lt.sh index 96526e4..ee43d30 100755 --- a/lt.sh +++ b/lt.sh @@ -14,17 +14,6 @@ case $uname in ;; esac -if [[ $platform = "Windows" ]]; then - export COMPOSE_CONVERT_WINDOWS_PATHS=1 -fi - -# define realpath replacement function -if [[ $platform = "MacOS / OSX" ]]; then - realpath() { - [[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}" - } -fi - usage(){ echo "Usage: $0 [--port N]" echo @@ -53,6 +42,11 @@ case $key in ARGS+=("$1") shift # past argument ;; + --api-keys) + export DB_VOLUME="-v lt-db:/app/db" + ARGS+=("$1") + shift # past argument + ;; --help) usage ;; @@ -92,4 +86,4 @@ environment_check(){ } environment_check -docker run -ti --rm --entrypoint bash -p $LT_PORT:$LT_PORT -v lt-share:/home/libretranslate/.local/share libretranslate/libretranslate #${ARGS[@]} \ No newline at end of file +docker run -ti --rm -p $LT_PORT:$LT_PORT $DB_VOLUME -v lt-local:/home/libretranslate/.local libretranslate/libretranslate ${ARGS[@]} \ No newline at end of file