|
import torch |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline |
|
|
|
import gradio as gr |
|
|
|
|
|
checkpoint = "suriya7/English-to-Tamil" |
|
tokenizer = AutoTokenizer.from_pretrained(checkpoint) |
|
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint) |
|
|
|
|
|
pipe=pipeline("text2text-generation", model="suriya7/English-to-Tamil") |
|
|
|
def language_translator(text): |
|
tokenized = tokenizer([text], return_tensors='pt') |
|
out = model.generate(**tokenized, max_length=128) |
|
return tokenizer.decode(out[0],skip_special_tokens=True) |
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
with gr.Column(): |
|
english=gr.Textbox(label='English text') |
|
translate_btn=gr.Button(value='Translate') |
|
with gr.Column(): |
|
german=gr.Textbox(label='Tamil text') |
|
|
|
translate_btn.click(language_translator, inputs=english,outputs=german) |
|
|
|
demo.launch(share=True) |