razent's picture
Update app.py
1335053
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 = """
<p>
<center>
Multi-domain Translation Between English and Vietnamese
</center>
</p>
"""
article = "<p style='text-align: center'><a href='http://translate.vietai.org' target='_blank'>by VietAI Research</a> | <a href='https://github.com/vietai/mTet' target='_blank'>Github</a> | Contact: <a href='mailto:[email protected]' target='_blank'>Hieu Tran</a></p></center></p>"
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)