Update install_model.py
Browse files- install_model.py +23 -6
install_model.py
CHANGED
@@ -1,17 +1,34 @@
|
|
1 |
-
import argostranslate.package
|
2 |
import os
|
|
|
|
|
3 |
|
4 |
model_dir = "/app/models"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
print(f"Model directory {model_dir} not found.")
|
8 |
-
exit(1)
|
9 |
|
10 |
for filename in os.listdir(model_dir):
|
11 |
if filename.endswith(".argosmodel"):
|
12 |
model_path = os.path.join(model_dir, filename)
|
|
|
|
|
|
|
|
|
|
|
13 |
try:
|
14 |
-
print(f"Installing model: {
|
15 |
argostranslate.package.install_from_path(model_path)
|
16 |
except Exception as e:
|
17 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
+
import zipfile
|
3 |
+
import argostranslate.package
|
4 |
|
5 |
model_dir = "/app/models"
|
6 |
+
install_dir = "/app/.local/share/argos-translate/packages"
|
7 |
+
|
8 |
+
def is_valid_argosmodel(path):
|
9 |
+
try:
|
10 |
+
with zipfile.ZipFile(path, 'r') as z:
|
11 |
+
return 'metadata.json' in z.namelist()
|
12 |
+
except zipfile.BadZipFile:
|
13 |
+
return False
|
14 |
|
15 |
+
print(f"Looking for models in: {model_dir}")
|
|
|
|
|
16 |
|
17 |
for filename in os.listdir(model_dir):
|
18 |
if filename.endswith(".argosmodel"):
|
19 |
model_path = os.path.join(model_dir, filename)
|
20 |
+
|
21 |
+
if not is_valid_argosmodel(model_path):
|
22 |
+
print(f"Skipping invalid model: {filename}")
|
23 |
+
continue
|
24 |
+
|
25 |
try:
|
26 |
+
print(f"Installing model: {filename}")
|
27 |
argostranslate.package.install_from_path(model_path)
|
28 |
except Exception as e:
|
29 |
+
print(f"Error installing {filename}: {e}")
|
30 |
+
|
31 |
+
print("\nInstallation complete. Installed model directories:")
|
32 |
+
for root, dirs, files in os.walk(install_dir):
|
33 |
+
for d in dirs:
|
34 |
+
print(f"Folder {os.path.join(root, d)}")
|