Named volume for db, --update-models arg

This commit is contained in:
Piero Toffanin 2022-12-20 11:13:56 -05:00
parent 5285697203
commit 959f4638cc
6 changed files with 20 additions and 18 deletions

View file

@ -130,8 +130,8 @@ Then open a web browser to http://localhost:5000
### Run with Docker ### Run with Docker
Linux/MacOS: `./lt.sh` Linux/MacOS: `./lt.sh [args]`
Windows: double-click `lt.bat` Windows: `lt.bat [args]`
Then open a web browser to http://localhost:5000 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 | | --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS |
| --disable-files-translation | Disable files translation | `false` | LT_DISABLE_FILES_TRANSLATION | | --disable-files-translation | Disable files translation | `false` | LT_DISABLE_FILES_TRANSLATION |
| --disable-web-ui | Disable web ui | `false` | LT_DISABLE_WEB_UI | | --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. 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

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

View file

@ -156,6 +156,11 @@ _default_options_objects = [
'default_value': False, 'default_value': False,
'value_type': 'bool' '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 import app.language
def boot(load_only=None): def boot(load_only=None, update_models=False):
try: 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: except Exception as e:
print("Cannot update models (normal if you're offline): %s" % str(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( parser.add_argument(
"--disable-web-ui", default=DEFARGS['DISABLE_WEB_UI'], action="store_true", help="Disable web ui" "--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() return parser.parse_args()

18
lt.sh
View file

@ -14,17 +14,6 @@ case $uname in
;; ;;
esac 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(){ usage(){
echo "Usage: $0 [--port N]" echo "Usage: $0 [--port N]"
echo echo
@ -53,6 +42,11 @@ case $key in
ARGS+=("$1") ARGS+=("$1")
shift # past argument shift # past argument
;; ;;
--api-keys)
export DB_VOLUME="-v lt-db:/app/db"
ARGS+=("$1")
shift # past argument
;;
--help) --help)
usage usage
;; ;;
@ -92,4 +86,4 @@ environment_check(){
} }
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[@]} docker run -ti --rm -p $LT_PORT:$LT_PORT $DB_VOLUME -v lt-local:/home/libretranslate/.local libretranslate/libretranslate ${ARGS[@]}