CloudNativeDDL / app.py
Timing0311's picture
Update app.py
e055bb3
raw
history blame
682 Bytes
from transformers import MT5ForConditionalGeneration, AutoTokenizer
import gradio as grad
mdl = MT5ForConditionalGeneration.from_pretrained("google/mt5-small")
tokenizer = AutoTokenizer.from_pretrained("google/mt5-small")
def translation_CN2EN(text):
inp = "translate Chinese to English: " + text
enc = tokenizer(inp, return_tensors="pt").input_ids
tokens = mdl(**enc)
response = tokenizer.decode(tokens[0], skip_special_tokens=True)
return response
para=grad.Textbox(lines=1, label="Chinese Text", placeholder="Text in Chinese")
out=grad.Textbox(lines=1, label="English Translation")
grad.Interface(translation_CN2EN, inputs=para, outputs=out).launch()