CoolFace
Apppublic

malloc/OpenNMT-EN-DE-Translation

sourceHugging Faceupdated 5y agoView on Hugging Face
3likes
app.py25 linesDownload Raw Back to root
1import gradio as gr2import os3 4def pred(text):5    model = "averaged-10-epoch.pt"6    hf_repo_id = "malloc/OpenNMT-py-English-German-Transformer"7    src = "src-test.txt"8    with open(src, 'w') as f:9        f.write(text)10    output = "pred.txt"11    os.system(f"onmt_translate -model {model} -hf_repo_id {hf_repo_id} -src {src} -output {output}")12 13    with open(output) as f:14        translation =  f.read()15    return translation16 17 18iface = gr.Interface(19    fn=pred,20    inputs= gr.inputs.Textbox(lines=2, placeholder="Enter English text to translate..."),21    outputs=["text"],22    theme="huggingface")23 24iface.launch()25