File size: 622 Bytes
6ac8934
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 os

def pred(text):
    model = "averaged-10-epoch.pt"
    hf_repo_id = "malloc/OpenNMT-py-English-German-Transformer"
    src = "src-test.txt"
    with open(src, 'w') as f:
        f.write(text)
    output = "pred.txt"
    os.system(f"onmt_translate -model {model} -hf_repo_id {hf_repo_id} -src {src} -output {output}")

    with open(output) as f:
        translation =  f.read()
    return translation


iface = gr.Interface(
    fn=pred,
    inputs= gr.inputs.Textbox(lines=2, placeholder="Enter English text to translate..."),
    outputs=["text"],
    theme="huggingface")

iface.launch()