File size: 1,576 Bytes
7edceed
2bc76b6
 
83bccb7
 
 
7edceed
2bc76b6
7edceed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cda5887
 
7edceed
 
cda5887
7edceed
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
30
31
import os
import gradio as gr

os.system('wget -q https://storage.googleapis.com/vakyaansh-open-models/translation_models/en-indic.zip')
os.system('unzip /home/user/app/en-indic.zip')

os.system('unzip /home/user/app/en-indic.zip')

from fairseq import checkpoint_utils, distributed_utils, options, tasks, utils
import gradio as gr
from inference.engine import Model
indic2en_model = Model(expdir='/home/user/app/en-indic')

INDIC = {"Assamese": "as", "Bengali": "bn", "Gujarati": "gu", "Hindi": "hi","Kannada": "kn","Malayalam": "ml", "Marathi": "mr", "Odia": "or","Punjabi": "pa","Tamil": "ta", "Telugu" : "te"}


def translate(text, lang):
  return indic2en_model.translate_paragraph(text, 'en', INDIC[lang])


languages = list(INDIC.keys())
drop_down = gr.inputs.Dropdown(languages, type="value", default="Hindi", label="Select Target Language")
text = gr.inputs.Textbox(lines=5, placeholder="Enter Text to translate", default="", label="Enter Text in English")
text_ouptut = gr.outputs.Textbox(type="auto", label="Translated text in Target Language")

example=[['Farmers are backbone of our Indian economy.','Hindi'],
        ['India, officially the Republic of India, is a country in South Asia.', 'Marathi']]

supported_lang = ', '.join(languages)
iface = gr.Interface(fn=translate, inputs=[text,drop_down] , outputs=text_ouptut, title='IndicTrans NMT System', description = 'Currently the model supports ' + supported_lang, article = 'Original repository can be found [here](https://github.com/AI4Bharat/indicTrans)' , examples=example)
iface.launch(enable_queue=True)