forked from mirrors/LibreTranslate
Updated argos translate to 1.1.0
This commit is contained in:
parent
7eb5081f2a
commit
9191524c04
3 changed files with 15 additions and 25 deletions
|
@ -2,9 +2,6 @@ FROM python:3.8
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# This expects the models submodule to be present
|
|
||||||
COPY models models
|
|
||||||
|
|
||||||
RUN pip install --upgrade pip
|
RUN pip install --upgrade pip
|
||||||
|
|
||||||
# Avoid rebuilding this step if no changes to requirements.txt
|
# Avoid rebuilding this step if no changes to requirements.txt
|
||||||
|
|
35
app/init.py
35
app/init.py
|
@ -1,33 +1,26 @@
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from argostranslate import settings
|
from argostranslate import settings, package, translate
|
||||||
|
|
||||||
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
|
|
||||||
import os, glob, shutil, zipfile
|
import os, glob, shutil, zipfile
|
||||||
|
|
||||||
def boot():
|
def boot():
|
||||||
check_and_install_models()
|
check_and_install_models()
|
||||||
|
|
||||||
def check_and_install_models(force=False):
|
def check_and_install_models(force=False):
|
||||||
if os.path.exists(INSTALLED_MODELS_DIR) and not force:
|
if len(package.get_installed_packages()) == 0 or force:
|
||||||
return
|
# Update package definitions from remote
|
||||||
|
print("Updating language models")
|
||||||
|
package.update_package_index()
|
||||||
|
|
||||||
if os.path.exists(INSTALLED_MODELS_DIR):
|
# Load available packages from local package index
|
||||||
print("Removing old %s" % INSTALLED_MODELS_DIR)
|
available_packages = package.load_available_packages()
|
||||||
shutil.rmtree(INSTALLED_MODELS_DIR)
|
print("Found %s models" % len(available_packages))
|
||||||
|
|
||||||
print("Creating %s" % INSTALLED_MODELS_DIR)
|
# Download and install all available packages
|
||||||
os.makedirs(INSTALLED_MODELS_DIR, exist_ok=True)
|
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)
|
||||||
|
|
||||||
|
print("Loaded support for %s languages (%s models total)!" % (len(translate.load_installed_languages()), len(available_packages)))
|
||||||
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())))
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
argostranslate==1.0.3
|
argostranslate==1.1.0
|
||||||
Flask==1.1.2
|
Flask==1.1.2
|
||||||
flask-swagger==0.2.14
|
flask-swagger==0.2.14
|
||||||
flask-swagger-ui==3.36.0
|
flask-swagger-ui==3.36.0
|
||||||
|
|
Loading…
Reference in a new issue