File size: 829 Bytes
a412c18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)