File size: 1,763 Bytes
489c564
dd90f68
49ec14a
ef3e238
d582d22
 
 
ef3e238
d582d22
 
ef3e238
49ec14a
9adf938
 
cfa5afa
 
9adf938
 
4e07626
 
 
 
 
8e5c897
4e07626
19dae2f
2b84e99
19dae2f
 
4e07626
 
 
cfa5afa
4e8b19e
823a19b
4e8b19e
 
823a19b
 
263203b
788e42f
c9de4a3
cfa5afa
a9d4166
4e07626
d582d22
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
import gradio as gr
from transformers import pipeline

examples = [
    'Alisher Navoiy – ulug‘ o‘zbek va boshqa turkiy xalqlarning <mask>, mutafakkiri va davlat arbobi bo‘lgan.',
    'Oʻzbekistonning poytaxti <mask> shahri boʻlib, davlat tili oʻzbek tili hisoblanadi.',
    'Oʻzbekiston iqtisodiyoti bozor <mask> bosqichma-bosqich oʻtadi, tashqi savdo siyosati import oʻrnini bosishga asoslangan.',
    'Kuchli yomg‘irlar tufayli bir qator <mask> kuchli sel oqishi kuzatildi.',
    'Registon maydoni - tarixda shaharning ilm-fan, siyosat va <mask> markazi boʻlgan.',
    'Venera - Quyosh tizimidagi o‘z o‘qi atrofida soat sohasi farqli ravishda aylanadigan yagona <mask>.'
]

models = [
    "sinonimayzer/UzRoBERTa-v1", 
    "tahrirchi/tahrirchi-bert-base", 
    "rifkat/uztext-3Gb-BPE-Roberta"
]

def df(arr):
    d = {}
    for val in arr:
        d[val['token_str']] = val['score']
    return d
    
def fn(text):
    arr = []
    for model in models:
        arr.append(df(pipeline("fill-mask", model=model)(text)))
    return arr[0], arr[1], arr[2]
with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            output0 = gr.Label(label=models[0])
        with gr.Column():
            output1 = gr.Label(label=models[1])
    with gr.Row():
        with gr.Column():
            output2 = gr.Label(label=models[2])
        with gr.Column():
            input = gr.Textbox(label="Input", value=examples[0], show_label=True)
            gr.Examples(examples, fn=fn, inputs=[input], outputs=[output0, output1, output2], cache_examples=True, batch=True)
            btn = gr.Button("Check")
    btn.click(fn, inputs=[input], outputs=[output0, output1, output2])
    
if __name__ == "__main__":
    demo.queue().launch()