File size: 1,797 Bytes
87dca7d
dabb276
c829c5b
4236010
c829c5b
4f8631f
e220ed1
ff4fabf
 
3814228
 
513f022
627d9cd
1842d01
87dca7d
5476941
 
 
 
 
87dca7d
86b5efd
 
d68e7cc
86b5efd
5476941
 
50f28bf
1903514
d6d572c
fc2a883
 
0ee68a4
6135bab
 
5476941
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
32
33
34
35
36
37
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('pip uninstall -y numpy')
os.system('pip install numpy')
#os.system('pip uninstall -y numba')
#os.system('pip install numba==0.53')

from fairseq import checkpoint_utils, distributed_utils, options, tasks, utils
import gradio as grd
from inference.engine import Model
indic2en_model = Model(expdir='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())

#print(translate('helo how are you'))
ddwn = grd.inputs.Dropdown(languages, type="value", default="Hindi", label="Select Target Language")
txt = grd.inputs.Textbox( lines=5, placeholder="Enter Text to translate", default="", label="Enter Text in English")
txt_ouptut = grd.outputs.Textbox(type="auto", label="Translated text in Target Language")

example=[['I want to translate this sentence in Hindi','Hindi'],
        ['I am feeling very good today.', 'Bengali']]

supp = ','.join(languages)
iface = grd.Interface(fn=translate, inputs=[txt,ddwn] , outputs=txt_ouptut, title='Translation for 11 Indic Languages', description = 'This is a demo based on IndicTrans. Languages Supported: '+supp, article = 'Original repo [link](https://github.com/AI4Bharat/indicTrans) by AI4Bharat. <b>Note: This space can only perform translation from English to Indic languages. Support for other combinations will be provided soon.', examples=example)
iface.launch(enable_queue=True)