File size: 3,123 Bytes
d984b22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import gradio as gr
from inference.engine import Model

e2i_model_download = "wget --load-cookies /tmp/cookies.txt \"https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1IpcnaQ2ScX_zodt2aLlXa_5Kkntl0nue' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\\n/p')&id=1IpcnaQ2ScX_zodt2aLlXa_5Kkntl0nue\" -O en-indic.zip && rm -rf /tmp/cookies.txt"
os.system(e2i_model_download)
os.system('unzip /home/user/app/en-indic.zip')

i2e_model_download = "wget --load-cookies /tmp/cookies.txt \"https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1-hzy09qi-OEogyge7rQG79K7iV4xsNWa' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\\n/p')&id=1-hzy09qi-OEogyge7rQG79K7iV4xsNWa\" -O indic-en.zip && rm -rf /tmp/cookies.txt"
os.system(i2e_model_download)
os.system('unzip /home/user/app/indic-en.zip')

i2i_model_download = "wget --show-progress -O m2m.tar https://ai4b-my.sharepoint.com/:u:/g/personal/sumanthdoddapaneni_ai4bharat_org/Eajn_jJIp5NEqeyqZ0GW4FgBdiANlZNQiy7dlwkaNr8DHw?download=1"
os.system(i2i_model_download)
os.system("tar -xvf /home/user/app/m2m.tar")

en2indic_model = Model(expdir='/home/user/app/en-indic')
indic2en_model = Model(expdir='/home/user/app/indic-en')
indic2indic_model = Model(expdir='/home/user/app/m2m')

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


def translate(text, fromLang, toLang):
    if (fromLang != "English" and toLang == "English"):
        return indic2en_model.translate_paragraph(text, LANGUAGES[fromLang], LANGUAGES[toLang])
    elif (fromLang == "English" and toLang != "English"):
        return en2indic_model.translate_paragraph(text, LANGUAGES[fromLang], LANGUAGES[toLang])
    elif (fromLang != "English" and toLang != "English"):
        return indic2indic_model.translate_paragraph(text, LANGUAGES[fromLang], LANGUAGES[toLang])
    else:
        return text


languages = list(LANGUAGES.keys())

fromChoice = gr.inputs.Dropdown(
    languages, type="value", default="Hindi", label="Select Source Language")

toChoice = gr.inputs.Dropdown(
    languages, type="value", default="Tamil", label="Select Target Language")

text_output = gr.outputs.Textbox(
    type="auto", label=f"Translation")

text = gr.inputs.Textbox(lines=5, placeholder="Enter Text to translate",
                         default="", label="Enter Text in Source Language")

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