diff --git a/Dockerfile b/Dockerfile index b9f072a..f460d7e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,9 +2,6 @@ FROM python:3.8 WORKDIR /app -# This expects the models submodule to be present -COPY models models - RUN pip install --upgrade pip # Avoid rebuilding this step if no changes to requirements.txt diff --git a/app/init.py b/app/init.py index 54d1100..91e36b9 100644 --- a/app/init.py +++ b/app/init.py @@ -1,33 +1,26 @@ import os from pathlib import Path -from argostranslate import settings - -INSTALLED_MODELS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "installed_models")) -os.environ["ARGOS_TRANSLATE_PACKAGES_DIR"] = INSTALLED_MODELS_DIR -settings.package_dirs = [Path(INSTALLED_MODELS_DIR)] - -from argostranslate import translate +from argostranslate import settings, package, translate import os, glob, shutil, zipfile def boot(): check_and_install_models() def check_and_install_models(force=False): - if os.path.exists(INSTALLED_MODELS_DIR) and not force: - return + if len(package.get_installed_packages()) == 0 or force: + # Update package definitions from remote + print("Updating language models") + package.update_package_index() - if os.path.exists(INSTALLED_MODELS_DIR): - print("Removing old %s" % INSTALLED_MODELS_DIR) - shutil.rmtree(INSTALLED_MODELS_DIR) + # Load available packages from local package index + available_packages = package.load_available_packages() + print("Found %s models" % len(available_packages)) - print("Creating %s" % INSTALLED_MODELS_DIR) - os.makedirs(INSTALLED_MODELS_DIR, exist_ok=True) + # Download and install all available packages + for available_package in available_packages: + print("Downloading %s (%s) ..." % (available_package, available_package.package_version)) + download_path = available_package.download() + package.install_from_path(download_path) - - for f in glob.glob("models/**.argosmodel"): - print("Installing %s..." % f) - with zipfile.ZipFile(f, 'r') as zip: - zip.extractall(path=INSTALLED_MODELS_DIR) - - print("Installed %s language models!" % (len(translate.load_installed_languages()))) + print("Loaded support for %s languages (%s models total)!" % (len(translate.load_installed_languages()), len(available_packages))) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b0f465a..8cc97da 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -argostranslate==1.0.3 +argostranslate==1.1.0 Flask==1.1.2 flask-swagger==0.2.14 flask-swagger-ui==3.36.0