File size: 829 Bytes
f470ace
edcca00
2eb99f4
edcca00
eb4a125
 
 
 
 
 
696fe3b
 
 
2eb99f4
8997f2f
2eb99f4
 
 
 
 
 
 
2ff2e3b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr

import subprocess

from transformers import AutoModel

model = AutoModel.from_pretrained("proxectonos/Nos_MT-OpenNMT-en-gl")

# Push the model to your namespace with the name "my-finetuned-bert".
model.push_to_hub("Nos_MT-OpenNMT-en-gl")

# NOS-MT-en-gl.p

def translate(input_text):
    command = f"onmt_translate -src {input_text} -model NOS-MT-en-gl.p --output ./output_file.txt --replace_unk -gpu 0"
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()
    if process.returncode != 0:
        raise Exception(f"Error occurred: {stderr.decode().strip()}")
    return stdout.decode().strip()

demo = gr.Interface(fn=translate, inputs="textbox", outputs="textbox")
    
if __name__ == "__main__":
    demo.launch()