SeyedAli's picture
Create app.txt
a412c18
raw
history blame
829 Bytes
import gradio as gr
from transformers import MT5ForConditionalGeneration, MT5Tokenizer
model_name = "SeyedAli/Persian-to-English-Translation-mT5-V1"
tokenizer = MT5Tokenizer.from_pretrained(model_name)
model = MT5ForConditionalGeneration.from_pretrained(model_name)
text_input = gr.TextArea(label="جمله فارسی",text_align="right",rtl=True,type="text")
text_output = gr.TextArea(label="ترجمه انگلیسی",text_align="right",rtl=True,type="text")
def Translate(text, **generator_args):
input_ids = tokenizer.encode(input_string, return_tensors="pt")
res = model.generate(input_ids, **generator_args)
output = tokenizer.batch_decode(res, skip_special_tokens=True)
print(output)
return output
iface = gr.Interface(fn=Translate, inputs=text_input, outputs=text_output)
iface.launch(share=False)