File size: 649 Bytes
689aca1
 
 
 
 
 
 
f3cf0ce
689aca1
 
 
 
 
 
f3cf0ce
689aca1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from transformers import T5ForConditionalGeneration, T5Tokenizer
import gradio as grad

text2text_tkn= T5Tokenizer.from_pretrained("t5-small")
mdl = T5ForConditionalGeneration.from_pretrained("t5-small")

def text2text_translation(text):
     inp = "translate English to French:: "+text
     enc = text2text_tkn(inp, return_tensors="pt")
     tokens = mdl.generate(**enc)
     response=text2text_tkn.batch_decode(tokens)
     return response

para=grad.Textbox(lines=1, label="English Text", placeholder="Text in English")
out=grad.Textbox(lines=1, label="French Translation")
grad.Interface(text2text_translation, inputs=para, outputs=out).launch()