LijinDurairaj
commited on
Commit
·
3a47a2c
1
Parent(s):
d060f89
translating english to tamil
Browse files
app.py
CHANGED
@@ -1 +1,29 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
+
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
|
7 |
+
checkpoint = "suriya7/English-to-Tamil"
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint)
|
10 |
+
|
11 |
+
|
12 |
+
pipe=pipeline("text2text-generation", model="suriya7/English-to-Tamil")
|
13 |
+
|
14 |
+
def language_translator(text):
|
15 |
+
tokenized = tokenizer([text], return_tensors='pt')
|
16 |
+
out = model.generate(**tokenized, max_length=128)
|
17 |
+
return tokenizer.decode(out[0],skip_special_tokens=True)
|
18 |
+
|
19 |
+
with gr.Blocks() as demo:
|
20 |
+
with gr.Row():
|
21 |
+
with gr.Column():
|
22 |
+
english=gr.Textbox(label='English text')
|
23 |
+
translate_btn=gr.Button(value='Translate')
|
24 |
+
with gr.Column():
|
25 |
+
german=gr.Textbox(label='Tamil text')
|
26 |
+
|
27 |
+
translate_btn.click(language_translator, inputs=english,outputs=german)
|
28 |
+
|
29 |
+
demo.launch(share=True)
|