Spaces:
Runtime error
Runtime error
Harveenchadha
commited on
Commit
•
1508faf
1
Parent(s):
f80a870
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,14 @@ import os
|
|
3 |
|
4 |
os.system('wget -q https://storage.googleapis.com/vakyaansh-open-models/translation_models/indic-en.zip')
|
5 |
os.system('unzip /home/user/app/indic-en.zip')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
os.system('pip uninstall -y numpy')
|
7 |
os.system('pip install numpy')
|
8 |
#os.system('pip uninstall -y numba')
|
@@ -12,25 +20,33 @@ from fairseq import checkpoint_utils, distributed_utils, options, tasks, utils
|
|
12 |
import gradio as grd
|
13 |
from inference.engine import Model
|
14 |
indic2en_model = Model(expdir='indic-en')
|
|
|
|
|
15 |
|
16 |
-
INDIC = {"Assamese": "as", "Bengali": "bn", "Gujarati": "gu", "Hindi": "hi","Kannada": "kn","Malayalam": "ml", "Marathi": "mr", "Odia": "or","Punjabi": "pa","Tamil": "ta", "Telugu" : "te"}
|
17 |
-
|
18 |
|
19 |
-
def translate(text, lang):
|
20 |
-
return indic2en_model.translate_paragraph(text, INDIC[lang], 'en')
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
languages = list(INDIC.keys())
|
25 |
|
26 |
#print(translate('helo how are you'))
|
27 |
-
|
|
|
|
|
28 |
txt = grd.inputs.Textbox( lines=5, placeholder="Enter Text to translate", default="", label="Enter Text in Source Language")
|
29 |
txt_ouptut = grd.outputs.Textbox(type="auto", label="Translated text in English Language")
|
30 |
|
31 |
-
example=[['मैं इस वाक्य का हिंदी में अनुवाद करना चाहता हूं','Hindi'],
|
32 |
-
['আজ আমার খুব ভালো লাগছে', 'Bengali']]
|
33 |
|
34 |
supp = ','.join(languages)
|
35 |
-
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
|
36 |
iface.launch(enable_queue=True)
|
|
|
3 |
|
4 |
os.system('wget -q https://storage.googleapis.com/vakyaansh-open-models/translation_models/indic-en.zip')
|
5 |
os.system('unzip /home/user/app/indic-en.zip')
|
6 |
+
os.system('wget -q https://storage.googleapis.com/vakyaansh-open-models/translation_models/en-indic.zip')
|
7 |
+
os.system('unzip /home/user/app/en-indic.zip')
|
8 |
+
os.system('wget -q https://storage.googleapis.com/vakyaansh-open-models/translation_models/m2m.zip')
|
9 |
+
os.system('unzip /home/user/app/m2m.zip')
|
10 |
+
os.system('rm /home/user/app/indic-en.zip')
|
11 |
+
os.system('rm /home/user/app/en-indic.zip')
|
12 |
+
os.system('rm /home/user/app/m2m.zip')
|
13 |
+
|
14 |
os.system('pip uninstall -y numpy')
|
15 |
os.system('pip install numpy')
|
16 |
#os.system('pip uninstall -y numba')
|
|
|
20 |
import gradio as grd
|
21 |
from inference.engine import Model
|
22 |
indic2en_model = Model(expdir='indic-en')
|
23 |
+
en2indic_model = Model(expdir='en-indic')
|
24 |
+
indic2indic_model = Model(expdir='m2m')
|
25 |
|
26 |
+
INDIC = {"Assamese": "as", "Bengali": "bn", "Gujarati": "gu", "Hindi": "hi","Kannada": "kn","Malayalam": "ml", "Marathi": "mr", "Odia": "or","Punjabi": "pa","Tamil": "ta", "Telugu" : "te", "English": "en"}
|
|
|
27 |
|
|
|
|
|
28 |
|
29 |
+
def translate(text, source_lang, dest_lang):
|
30 |
+
if source_lang == 'en':
|
31 |
+
return en2indic_model.translate_paragraph(text, 'en', INDIC[dest_lang])
|
32 |
+
elif dest_lang == 'en':
|
33 |
+
return indic2en_model.translate_paragraph(text, INDIC[source_lang], 'en')
|
34 |
+
else:
|
35 |
+
return indic2indic_model.translate_paragraph(text, INDIC[source_lang], INDIC[dest_lang])
|
36 |
|
37 |
|
38 |
languages = list(INDIC.keys())
|
39 |
|
40 |
#print(translate('helo how are you'))
|
41 |
+
ddwn_src = grd.inputs.Dropdown(languages, type="value", default="English", label="Select Source Language")
|
42 |
+
ddwn_tar = grd.inputs.Dropdown(languages, type="value", default="Hindi", label="Select Target Language")
|
43 |
+
|
44 |
txt = grd.inputs.Textbox( lines=5, placeholder="Enter Text to translate", default="", label="Enter Text in Source Language")
|
45 |
txt_ouptut = grd.outputs.Textbox(type="auto", label="Translated text in English Language")
|
46 |
|
47 |
+
example=[['मैं इस वाक्य का हिंदी में अनुवाद करना चाहता हूं','Hindi', 'English'],
|
48 |
+
['আজ আমার খুব ভালো লাগছে', 'Bengali' , 'Hindi']]
|
49 |
|
50 |
supp = ','.join(languages)
|
51 |
+
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 is an attempt to create open version of Translation for Indic languages. </b>', examples=example)
|
52 |
iface.launch(enable_queue=True)
|