File size: 893 Bytes
3a47a2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)