Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,16 +5,36 @@ from torch import device as Device
|
|
5 |
from torch.cuda import is_available as cuda_is_available
|
6 |
from transformers import AutoTokenizer
|
7 |
from indicai_projects.lang_detection import IndicLangDet
|
8 |
-
from indicai_projects.text2text_translation import IndicTrans
|
|
|
9 |
from indicai_projects.transliteration_rnn import Transliteration_RNN , rnn_conf
|
10 |
from indicai_projects.transliteration_transformer import Transliteration_Transformer
|
11 |
|
12 |
en2indic_rnn_lang = getenv("en2indic_rnn_lang","hi")
|
13 |
en2indic_lang = getenv("en2indic_lang","hi")
|
14 |
device = Device("cuda" if cuda_is_available() else "cpu")
|
15 |
-
|
|
|
16 |
en2indic_model = Transliteration_Transformer({en2indic_lang:hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts",f"{en2indic_lang}_word_prob_dict.json")},hf_hub_download("ai4bharat/IndicXlit","indicxlit-en-indic-v1.0/transformer/indicxlit.pt"),hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts", "corpus.zip"),{en2indic_lang},device)
|
17 |
indic2en_model = Transliteration_Transformer({"en":hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts","en_word_prob_dict.json")},hf_hub_download("ai4bharat/IndicXlit","indicxlit-indic-en-v1.0/transformer/indicxlit.pt"),hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts", "corpus.zip"),{"en"},device)
|
18 |
-
indic_trans_model = IndicTrans(
|
|
|
19 |
|
20 |
-
gr.TabbedInterface(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from torch.cuda import is_available as cuda_is_available
|
6 |
from transformers import AutoTokenizer
|
7 |
from indicai_projects.lang_detection import IndicLangDet
|
8 |
+
from indicai_projects.text2text_translation import IndicTrans as IndicTrans_OLD
|
9 |
+
from indicai_projects.krutrim_text2text_translation import IndicTrans
|
10 |
from indicai_projects.transliteration_rnn import Transliteration_RNN , rnn_conf
|
11 |
from indicai_projects.transliteration_transformer import Transliteration_Transformer
|
12 |
|
13 |
en2indic_rnn_lang = getenv("en2indic_rnn_lang","hi")
|
14 |
en2indic_lang = getenv("en2indic_lang","hi")
|
15 |
device = Device("cuda" if cuda_is_available() else "cpu")
|
16 |
+
LID_model = IndicLangDet(hf_hub_download("ai4bharat/IndicLID-BERT","basline_nn_simple.pt"),hf_hub_download("ai4bharat/IndicLID-FTR","model_baseline_roman.bin"),hf_hub_download("ai4bharat/IndicLID-FTN","model_baseline_roman.bin"),AutoTokenizer.from_pretrained("ai4bharat/IndicBERTv2-MLM-only"),device)
|
17 |
+
en2indic_RNN_model = Transliteration_RNN(hf_hub_download("shethjenil/Indic-Transliteration-RNN", rnn_conf[en2indic_rnn_lang]["weight"]) ,hf_hub_download("shethjenil/Indic-Transliteration-RNN", rnn_conf[en2indic_rnn_lang]["script"]),hf_hub_download("shethjenil/Indic-Transliteration-RNN", rnn_conf[en2indic_rnn_lang]["vocab"]),device)
|
18 |
en2indic_model = Transliteration_Transformer({en2indic_lang:hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts",f"{en2indic_lang}_word_prob_dict.json")},hf_hub_download("ai4bharat/IndicXlit","indicxlit-en-indic-v1.0/transformer/indicxlit.pt"),hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts", "corpus.zip"),{en2indic_lang},device)
|
19 |
indic2en_model = Transliteration_Transformer({"en":hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts","en_word_prob_dict.json")},hf_hub_download("ai4bharat/IndicXlit","indicxlit-indic-en-v1.0/transformer/indicxlit.pt"),hf_hub_download("shethjenil/Indic-Transliteration-Word-Prob-Dicts", "corpus.zip"),{"en"},device)
|
20 |
+
indic_trans_model = IndicTrans(device)
|
21 |
+
indic_trans_model_old = IndicTrans_OLD()
|
22 |
|
23 |
+
gr.TabbedInterface(
|
24 |
+
[
|
25 |
+
gr.Interface(LID_model.predict,gr.Textbox(label="Enter text"),[gr.Textbox(label="Language"), gr.Number(label="Accuracy in %")],title="Language Detection",),
|
26 |
+
gr.Interface(en2indic_RNN_model.predict,[gr.Textbox(label="Enter Word"),gr.Number(label="Enter Variation Number", value=1),],gr.List(label="Transliteration Result"),title="RNN Transliteration",),
|
27 |
+
gr.Interface(lambda word, topk: en2indic_model._transliterate_word(word, "en", en2indic_lang, topk, nativize_numerals=True),[gr.Textbox(label="Enter Word"),gr.Number(label="Enter Variation Number", value=1),],gr.List(label="Transliteration Result"),title=f"En2Indic Transliteration",),
|
28 |
+
gr.Interface(lambda word, topk, indic2en_lang: indic2en_model._transliterate_word(word, indic2en_lang, "en", topk, nativize_numerals=True),[gr.Textbox(label="Enter Word"),gr.Number(label="Enter Variation Number", value=1),gr.Dropdown(indic2en_model.all_supported_langs,label="input lang")],gr.List(label="Transliteration Result"),title="Indic2En Transliteration",),
|
29 |
+
gr.Interface(indic_trans_model.predict,[gr.Textbox(label="Input Text"),gr.Dropdown(indic_trans_model.all_lang, label="Source Language"),gr.Dropdown(indic_trans_model.all_lang, label="Target Language")],gr.Textbox(label="Result")),
|
30 |
+
gr.Interface(indic_trans_model_old.predict,[gr.Textbox(label="Input Text"),gr.Dropdown(indic_trans_model_old.all_lang, label="Source Language"),gr.Dropdown(indic_trans_model_old.all_lang, label="Target Language")],gr.Textbox(label="Result")),
|
31 |
+
],
|
32 |
+
[
|
33 |
+
"Language Detection",
|
34 |
+
f"RNN en2{en2indic_rnn_lang} Transliteration",
|
35 |
+
f"TRANSFORMER en2{en2indic_lang} Transliteration",
|
36 |
+
"Indic2en Transliteration",
|
37 |
+
"Text Translatation (Fast)",
|
38 |
+
"Text Translatation OLD",
|
39 |
+
],
|
40 |
+
).launch()
|