mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-06-20 08:01:00 +00:00
First commit
This commit is contained in:
parent
64547a8acf
commit
1062ef2713
9 changed files with 296 additions and 0 deletions
30
app/init.py
Normal file
30
app/init.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
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())))
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue