Spaces:
Runtime error
Runtime error
File size: 688 Bytes
a88db4c bd27b28 a88db4c afe1ac2 b59dc4d 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 Chinese to English: " + text
enc = tokenizer(inp, return_tensors="pt").input_ids
tokens = mdl.generate(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()
|