Spaces:
Runtime error
Runtime error
File size: 656 Bytes
a88db4c bd27b28 a88db4c bd27b28 a88db4c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
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 English to Chinese:: "+text
enc = tokenizer(inp, return_tensors="pt")
tokens = mdl.generate(**enc)
response = tokenizer.batch_decode(tokens)
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()
|