mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-10-31 22:08:59 +00:00
30 lines
No EOL
882 B
Python
30 lines
No EOL
882 B
Python
import os
|
|
from argostranslate import translate
|
|
import os, glob, shutil, zipfile
|
|
|
|
INSTALLED_MODELS_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "installed_models"))
|
|
|
|
os.environ["ARGOS_TRANSLATE_PACKAGES_DIR"] = INSTALLED_MODELS_DIR
|
|
|
|
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 os.path.exists(INSTALLED_MODELS_DIR):
|
|
print("Removing old %s" % INSTALLED_MODELS_DIR)
|
|
shutil.rmtree(INSTALLED_MODELS_DIR)
|
|
|
|
print("Creating %s" % INSTALLED_MODELS_DIR)
|
|
os.makedirs(INSTALLED_MODELS_DIR, exist_ok=True)
|
|
|
|
|
|
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())))
|
|
|