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()