axxam commited on
Commit
0ac7341
·
verified ·
1 Parent(s): ce72de2

Update install_model.py

Browse files
Files changed (1) hide show
  1. install_model.py +8 -35
install_model.py CHANGED
@@ -1,37 +1,10 @@
1
- import os
2
- import zipfile
3
  import argostranslate.package
4
- import shutil
5
-
6
- model_dir = "/app/models"
7
- install_dir = "/app/.local/share/argos-translate/packages"
8
-
9
- # Cleanup: Remove invalid model folder if it exists
10
- bad_path = os.path.join(install_dir, "model")
11
- if os.path.isdir(bad_path):
12
- shutil.rmtree(bad_path)
13
- print(f"Removed invalid leftover package: {bad_path}")
14
-
15
- def is_valid_argosmodel(path):
16
- try:
17
- with zipfile.ZipFile(path, 'r') as archive:
18
- return 'metadata.json' in archive.namelist()
19
- except zipfile.BadZipFile:
20
- return False
21
-
22
- # Install all valid .argosmodel files
23
- for filename in os.listdir(model_dir):
24
- if filename.endswith(".argosmodel"):
25
- full_path = os.path.join(model_dir, filename)
26
-
27
- if not is_valid_argosmodel(full_path):
28
- print(f"Skipping invalid model file: {filename}")
29
- continue
30
-
31
- try:
32
- print(f"Installing model: {filename}")
33
- argostranslate.package.install_from_path(full_path)
34
- except Exception as e:
35
- print(f"Error installing {filename}: {e}")
36
 
37
- print("All valid models installed.")
 
 
 
 
 
 
 
 
 
1
  import argostranslate.package
2
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ model_path = "/app/models/en_kab_comp"
5
+ if os.path.isdir(model_path):
6
+ package = argostranslate.package.Package(model_path)
7
+ argostranslate.package.install_from_path(package)
8
+ print("Kabyle model installed.")
9
+ else:
10
+ print("Model path not found.")