File size: 3,986 Bytes
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
import gradio as gr
from gradio_rich_textbox import RichTextbox

from helper.text_preprocess import space_punc
from helper.alignment_mappers import select_model
from helper.pos_taggers import select_pos_tagger
from helper.translators import select_translator


def bn_postagger(src, translator, model_name, tagger):
    """
    Bangla PoS Tagger
    """
    
    src = space_punc(src)

    tgt_base, tgt = select_translator(src, translator)

    model_name = select_model(model_name)

    result, pos_accuracy = select_pos_tagger(src, tgt, model_name, tagger)

    return tgt_base, result, pos_accuracy
    

with gr.Blocks(css="styles.css") as demo:
    gr.HTML("<h1>Bangla PoS Taggers</h1>")
    gr.HTML("<p>Parts of Speech (PoS) Tagging of Bangla Sentence using Bangla-English <strong>Word Alignment</strong></p>")

    with gr.Row():
        with gr.Column():
            inputs = [
                gr.Textbox(
                    label="Enter Bangla Sentence", 
                    placeholder="বাংলা বাক্য লিখুন"
                ),
                gr.Dropdown(
                    choices=["Google", "BanglaNMT", "MyMemory"], 
                    label="Select a Translator"
                ),
                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"
                ),
                gr.Dropdown(
                    choices=["spaCy", "NLTK", "Flair", "TextBlob"], 
                    label="Select a PoS Tagger"
                )
            ]

            btn = gr.Button(value="Submit", elem_classes="mybtn")
            gr.ClearButton(inputs)

        with gr.Column():
            outputs = [
                gr.Textbox(label="English Translation"), 
                RichTextbox(label="PoS Tags"),
                gr.Textbox(label="PoS Tagging Accuracy (Based on Unknown(UNK) Tags)")
            ]

    btn.click(bn_postagger, inputs, outputs)

    gr.Examples([
        [
            "বাংলাদেশ দক্ষিণ এশিয়ার একটি সার্বভৌম রাষ্ট্র।", 
            "Google", 
            "Neulab-AwesomeAlign (Bn-En-0.5M)", 
            "NLTK"
        ],
        [
            "বাংলাদেশের সংবিধানিক নাম কি?", 
            "Google", 
            "Google-mBERT (Base-Multilingual)",
            "spaCy"
        ],
        [
            "বাংলাদেশের সাংবিধানিক নাম গণপ্রজাতন্ত্রী বাংলাদেশ।", 
            "Google", 
            "Google-mBERT (Base-Multilingual)",
            "TextBlob"
        ],
        [
            "তিনজনের কেউই বাবার পথ ধরে প্রযুক্তি দুনিয়ায় হাঁটেননি।", 
            "Google", 
            "Neulab-AwesomeAlign (Bn-En-0.5M)", 
            "spaCy"
        ],
        [
            "তিনজনের কেউই বাবার পথ ধরে প্রযুক্তি দুনিয়ায় হাঁটেননি।", 
            "BanglaNMT",
            "Google-mBERT (Base-Multilingual)", 
            "spaCy"
        ],
        [
            "তিনজনের কেউই বাবার পথ ধরে প্রযুক্তি দুনিয়ায় হাঁটেননি।", 
            "MyMemory",
            "Google-mBERT (Base-Multilingual)", 
            "spaCy"
        ],
        [
            "বিশ্বের আরও একটি সেরা ক্লাব।", 
            "Google", 
            "Neulab-AwesomeAlign (Bn-En-0.5M)", 
            "Flair"
        ]

    ], inputs)



# Launch the Gradio app
if __name__ == "__main__":
    demo.launch()