import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("./mt5")
model = AutoModelForSeq2SeqLM.from_pretrained("./mt5")
model.resize_token_embeddings(len(tokenizer))
model.eval()
def translate(hakubun):
input_ids = tokenizer.encode(hakubun, return_tensors="pt", max_length=20, truncation=True)
output = model.generate(input_ids)
kakikudashi = tokenizer.decode(output[0], skip_special_tokens=True)
return kakikudashi
title = "Kanbun-LM"
description = "Gradio Demo for Kanbun-LM. Upload a hakubun then you can earn get its kanbun. Texts other than Tang poetry may not be translated correctly.
" \
"書き下し文生成のデモです。白文を入力し、翻訳された書き下し文を得ることができます。唐詩以外の漢文は正しく翻訳されない可能性があります。"
article = "