Spaces:
Sleeping
Sleeping
JJFrancisco
commited on
Commit
•
1c44ded
1
Parent(s):
605181f
Update app.py
Browse files
app.py
CHANGED
@@ -19,15 +19,16 @@ model_dir_en_gl = download_model("proxectonos/Nos_MT-OpenNMT-en-gl", revision="m
|
|
19 |
|
20 |
def translate(input_text):
|
21 |
print(input_text)
|
22 |
-
|
|
|
|
|
|
|
23 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
24 |
stdout, stderr = process.communicate()
|
25 |
if process.returncode != 0:
|
26 |
raise Exception(f"Error occurred: {stderr.decode().strip()}")
|
27 |
with open ('./output_file.txt','r') as f:
|
28 |
resultado= f.read()
|
29 |
-
# return stdout.decode().strip()
|
30 |
-
print(resultado)
|
31 |
return resultado
|
32 |
|
33 |
demo = gr.Interface(fn=translate, inputs="textbox", outputs="textbox")
|
|
|
19 |
|
20 |
def translate(input_text):
|
21 |
print(input_text)
|
22 |
+
def write_text_to_file(input.txt, input_text):
|
23 |
+
with open(input.txt, 'w') as file:
|
24 |
+
file.write(input_text)
|
25 |
+
command = f"onmt_translate -src input.txt -model {os.path.join(MODELS_PATH, model_dir_en_gl)}/NOS-MT-OpenNMT-en-gl --output ./output_file.txt --replace_unk"
|
26 |
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
27 |
stdout, stderr = process.communicate()
|
28 |
if process.returncode != 0:
|
29 |
raise Exception(f"Error occurred: {stderr.decode().strip()}")
|
30 |
with open ('./output_file.txt','r') as f:
|
31 |
resultado= f.read()
|
|
|
|
|
32 |
return resultado
|
33 |
|
34 |
demo = gr.Interface(fn=translate, inputs="textbox", outputs="textbox")
|