Spaces:
Running
Running
File size: 1,518 Bytes
3d4f13a 501291b 3d4f13a 1335053 501291b 3d4f13a 501291b 3d4f13a 1335053 |
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
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) |