Spaces:
Sleeping
Sleeping
JJFrancisco
commited on
Commit
•
48a14b6
1
Parent(s):
4d4c779
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,17 @@ import subprocess
|
|
4 |
|
5 |
from transformers import AutoModel
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
def translate(input_text):
|
10 |
-
command = f"onmt_translate -src {input_text} -model
|
11 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
12 |
stdout, stderr = process.communicate()
|
13 |
if process.returncode != 0:
|
|
|
4 |
|
5 |
from transformers import AutoModel
|
6 |
|
7 |
+
MODELS_PATH = "./models"
|
8 |
+
HF_CACHE_DIR = "./hf_cache"
|
9 |
+
|
10 |
+
def download_model(repo_id, revision="main"):
|
11 |
+
return snapshot_download(repo_id=repo_id, revision=revision, local_dir=os.path.join(MODELS_PATH, repo_id), cache_dir=HF_CACHE_DIR)
|
12 |
+
|
13 |
+
model_dir_gl_en = download_model("proxectonos/Nos_MT-OpenNMT-gl-en", revision="main")
|
14 |
+
model_dir_en_gl = download_model("proxectonos/Nos_MT-OpenNMT-en-gl", revision="main")
|
15 |
|
16 |
def translate(input_text):
|
17 |
+
command = f"onmt_translate -src {input_text} -model model_dir_en_gl --output ./output_file.txt --replace_unk"
|
18 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
19 |
stdout, stderr = process.communicate()
|
20 |
if process.returncode != 0:
|