Spaces:
Runtime error
Runtime error
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() | |