hussain-shk's picture
added examples
cda5887
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)