2020-12-19 23:40:37 +01:00
|
|
|
import os
|
2020-12-20 17:55:56 +01:00
|
|
|
from pathlib import Path
|
2021-02-08 16:56:45 +01:00
|
|
|
from argostranslate import settings, package, translate
|
2020-12-20 17:55:56 +01:00
|
|
|
import os, glob, shutil, zipfile
|
2020-12-19 23:40:37 +01:00
|
|
|
|
|
|
|
def boot():
|
|
|
|
check_and_install_models()
|
|
|
|
|
|
|
|
def check_and_install_models(force=False):
|
2021-02-09 14:12:32 +01:00
|
|
|
if len(package.get_installed_packages()) < 2 or force:
|
2021-02-08 16:56:45 +01:00
|
|
|
# Update package definitions from remote
|
|
|
|
print("Updating language models")
|
|
|
|
package.update_package_index()
|
|
|
|
|
|
|
|
# Load available packages from local package index
|
|
|
|
available_packages = package.load_available_packages()
|
|
|
|
print("Found %s models" % len(available_packages))
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
print("Loaded support for %s languages (%s models total)!" % (len(translate.load_installed_languages()), len(available_packages)))
|
2020-12-19 23:40:37 +01:00
|
|
|
|