balaramas commited on
Commit
49c09fe
1 Parent(s): 43ea9a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import subprocess
3
+ subprocess.check_call(["pip", "install", "transformers"])
4
+ subprocess.check_call(["pip", "install", "torch"])
5
+
6
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained("balaramas/mbart-sahitrans_new_data")
9
+ model = AutoModelForSeq2SeqLM.from_pretrained("balaramas/mbart-sahitrans_new_data")
10
+
11
+
12
+ def sanmt(txt):
13
+
14
+ tokenizer.src_lang = "hi_IN"
15
+ encoded_ar = tokenizer(txt, return_tensors="pt")
16
+ generated_tokens = model.generate(
17
+ **encoded_ar,
18
+ forced_bos_token_id=tokenizer.lang_code_to_id["hi_IN"]
19
+ )
20
+ output = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)[0]
21
+ return output
22
+
23
+ iface = gr.Interface(
24
+ fn=sanmt,
25
+ inputs=gr.Textbox(label="Enter text in Sanskrit", placeholder="Type here..."),
26
+ outputs=gr.Textbox(label="Translated Hindi Text"),
27
+ title="Sanskrit to Hindi Translator"
28
+ )
29
+ iface.launch()