Spaces:
Runtime error
Runtime error
File size: 6,867 Bytes
d4a2937 03e97cd c4a0750 d4a2937 03e97cd d4a2937 03e97cd c4a0750 03e97cd d4a2937 e6fb89b 03e97cd e6fb89b c4a0750 e6fb89b d4a2937 03e97cd d4a2937 c4a0750 d4a2937 c4a0750 b3f551c d4a2937 03e97cd d4a2937 03e97cd d4a2937 03e97cd c4a0750 d4a2937 03e97cd d4a2937 03e97cd d4a2937 03e97cd d4a2937 03e97cd d4a2937 |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
import gradio as gr
from gradio_rich_textbox import RichTextbox
from helper.text_preprocess import space_punc
from helper.alignment_mappers import select_model, get_alignments_table
from helper.translators import select_target_lang_code, google_translation, get_better_translation
def process_alignments(src, language_name, model_name):
"""
Bangla PoS Tagger
"""
tgt = None
tgt_base = None
html_table = None
src = space_punc(src)
tgt_lang_code = select_target_lang_code(language_name)
tgt = get_better_translation(src, tgt_lang_code)
tgt = space_punc(tgt)
tgt_base = google_translation(src, tgt_lang_code)
model_name = select_model(model_name)
html_table, alignment_accuracy = get_alignments_table(
source=src,
target=tgt,
model_name=model_name
)
return tgt_base, html_table, alignment_accuracy
with gr.Blocks(css="styles.css") as demo:
gr.HTML("<h1>Multilingual Sentence Alignments</h1>")
gr.HTML("<p>Align Parallel Sentences using mBERT</p>")
gr.HTML("<a href='https://github.com/google-research/bert/blob/master/multilingual.md#list-of-languages' alt='mBERT Repo'>Support Alignments Between 104 Languages</a>")
with gr.Row():
with gr.Column():
inputs = [
gr.Textbox(
label="Enter a Sentence (Auto Detect Language)",
),
gr.Dropdown(
choices=
[
"Afrikaans",
"Albanian",
"Arabic",
"Aragonese",
"Armenian",
"Asturian",
"Azerbaijani",
"Bashkir",
"Basque",
"Bavarian",
"Belarusian",
"Bengali",
"Bishnupriya Manipuri",
"Bosnian",
"Breton",
"Bulgarian",
"Burmese",
"Catalan",
"Cebuano",
"Chechen",
"Chinese (Simplified)",
"Chinese (Traditional)",
"Chuvash",
"Croatian",
"Czech",
"Danish",
"Dutch",
"English",
"Estonian",
"Finnish",
"French",
"Galician",
"Georgian",
"German",
"Greek",
"Gujarati",
"Haitian",
"Hebrew",
"Hindi",
"Hungarian",
"Icelandic",
"Ido",
"Indonesian",
"Irish",
"Italian",
"Japanese",
"Javanese",
"Kannada",
"Kazakh",
"Kirghiz",
"Korean",
"Latin",
"Latvian",
"Lithuanian",
"Lombard",
"Low Saxon",
"Luxembourgish",
"Macedonian",
"Malagasy",
"Malay",
"Malayalam",
"Marathi",
"Minangkabau",
"Nepali",
"Newar",
"Norwegian (Bokmal)",
"Norwegian (Nynorsk)",
"Occitan",
"Persian (Farsi)",
"Piedmontese",
"Polish",
"Portuguese",
"Punjabi",
"Romanian",
"Russian",
"Scots",
"Serbian",
"Serbo-Croatian",
"Sicilian",
"Slovak",
"Slovenian",
"South Azerbaijani",
"Spanish",
"Sundanese",
"Swahili",
"Swedish",
"Tagalog",
"Tajik",
"Tamil",
"Tatar",
"Telugu",
"Turkish",
"Ukrainian",
"Urdu",
"Uzbek",
"Vietnamese",
"Volapük",
"Waray-Waray",
"Welsh",
"West Frisian",
"Western Punjabi",
"Yoruba",
"Thai",
"Mongolian"
],
label="Select Target Language"
),
gr.Dropdown(
choices=["Google-mBERT (Base-Multilingual)", "Neulab-AwesomeAlign (Bn-En-0.5M)", "BUET-BanglaBERT (Large)", "SagorSarker-BanglaBERT (Base)", "SentenceTransformers-LaBSE (Multilingual)"],
label="Select a Model"
)
]
btn = gr.Button(value="Submit", elem_classes="mybtn")
gr.ClearButton(inputs)
with gr.Column():
outputs = [
gr.Textbox(label="English Translation"),
RichTextbox(label="Alignments Mapping (Source to Target)"),
gr.Textbox(label="Alignment Accuracy")
]
btn.click(process_alignments, inputs, outputs)
gr.Examples([
[
"বাংলাদেশ দক্ষিণ এশিয়ার একটি সার্বভৌম রাষ্ট্র।",
"English",
"SentenceTransformers-LaBSE (Multilingual)",
],
[
"বাংলাদেশের সংবিধানিক নাম কি?",
"English",
"Google-mBERT (Base-Multilingual)",
],
[
"বাংলাদেশের সাংবিধানিক নাম গণপ্রজাতন্ত্রী বাংলাদেশ।",
"Hindi",
"Google-mBERT (Base-Multilingual)",
]
], inputs)
# Launch the Gradio app
if __name__ == "__main__":
demo.launch() |