import gradio as gr from gradio.mix import Parallel, Series from transformers import pipeline translater = pipeline("translation", model="VietAI/envit5-translation") def translate(inp, direction): if direction == 'en->vi': text = "en: " + inp else: text = "vi: " + inp res = translater( text, max_length=512, early_stopping=True, )[0]['translation_text'][3:] return res description = """
by VietAI Research | Github | Contact: Hieu Tran
" examples = [ ["Dear God, thank you for granting us the evergreen garden of this world", "en->vi"], ["Thuốc này đã bị cấm sử dụng trong ngành thú y tại Ấn Độ.", "vi->en"] ] iface = gr.Interface( fn=translate, title="🌸MTet Translation🌸", description=description, article=article, examples=examples, inputs=[ gr.inputs.Textbox(lines=5, placeholder="Enter text (maximum 5 lines)", label="Input"), gr.inputs.Radio( choices=[ 'en->vi', 'vi->en'], default='en->vi', label='Direction'), ], outputs="text") iface.launch(enable_queue=True)