File size: 3,671 Bytes
2b74b8d
 
1d796c6
2b74b8d
 
 
 
1d796c6
2b74b8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d796c6
2b74b8d
 
 
 
 
 
 
 
1d796c6
 
 
 
 
 
2b74b8d
 
ba61797
2b74b8d
15140f9
ba61797
2b74b8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d796c6
 
 
 
 
 
2b74b8d
 
1d796c6
2b74b8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1d796c6
2b74b8d
 
 
 
 
1d796c6
2b74b8d
 
 
1d796c6
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
import gradio as gr

# Modellarni import qilish
from uzmorph_nn.uzmorph_nn import uzmorph_nn
from uzmorph_bigru.uzmorph_bigru import uzmorph_bigru
from uzmorph_transformer.uzmorph_transformer import uzmorph_transformer

# Modellarni ishga tushirish
models = {
    "uzmorph-nn (BiLSTM)": uzmorph_nn(),
    "uzmorph-bigru (BiGRU)": uzmorph_bigru(),
    "uzmorph-transformer (Transformer)": uzmorph_transformer(),
}

def analyze(word, selected_models):
    if not word or not word.strip():
        return "Iltimos, so'z kiriting."
    if not selected_models:
        return "Kamida bitta model tanlang."

    word = word.strip().lower()
    rows = []

    for name in selected_models:
        analyzer = models[name]
        try:
            result = analyzer.analyze(word)
            rows.append(
                f"### {name}\n"
                f"| Xususiyat | Qiymat |\n"
                f"|:---|:---|\n"
                f"| **Stem (O'zak)** | `{result.stem}` |\n"
                f"| **POS (So'z turkumi)** | `{result.pos}` |\n"
                f"| **Features (Xususiyatlar)** | `{result.features}` |\n"
            )
        except Exception as e:
            rows.append(f"### {name}\nXatolik: {e}\n")

    header = f"## Natijalar: `{word}`\n---\n"
    return header + "\n---\n".join(rows)


custom_theme = gr.themes.Soft(
    primary_hue="blue",
    secondary_hue="slate",
    neutral_hue="slate",
    font=gr.themes.GoogleFont("Inter"),
    font_mono=gr.themes.GoogleFont("JetBrains Mono"),
)

with gr.Blocks(
    title="UzMorph_NN — Uzbek Neural Morphological Analyzers",
    theme=custom_theme,
    css="""
        .gradio-container { max-width: 960px; margin: auto; }
        footer { display: none !important; }
    """
) as demo:
    gr.Markdown(
        "# UzMorph_NN — Uzbek Neural Morphological Analyzers \n"
        "O'zbek tilidagi so'zlarni morfologik tahlil qilish uchun neyron tarmoq asosidagi modellar.  \n"
        "Web: <a href='https://morph.uz' target='_blank'>morph.uz</a> | "
        "Rule-based Model Version: <a href='https://huggingface.co/spaces/ulugbeksalaev/uzmorph' target='_blank'>UzMorph</a> \n"
    )

    with gr.Row():
        with gr.Column(scale=1):
            word_input = gr.Textbox(
                label="So'zni kiriting",
                placeholder="maktabimizda",
                lines=1
            )
            model_selector = gr.CheckboxGroup(
                choices=list(models.keys()),
                value=["uzmorph-nn (BiLSTM)"],
                label="Modellarni tanlang"
            )
            analyze_btn = gr.Button("Tahlil qilish", variant="primary")
            
            gr.Markdown("### Misollar")
            gr.Examples(
                examples=[["ishladik"], ["kitoblarim"], ["borgan"], ["yozdi"]],
                inputs=[word_input]
            )

        with gr.Column(scale=2):
            output = gr.Markdown(label="Natijalar", value="Tahlil natijalari bu yerda ko'rinadi...")

    analyze_btn.click(
        fn=analyze,
        inputs=[word_input, model_selector],
        outputs=output
    )
    word_input.submit(
        fn=analyze,
        inputs=[word_input, model_selector],
        outputs=output
    )

    gr.Markdown(
        "---\n"
        "### PyPI orqali o'rnatish\n"
        "```bash\n"
        "pip install uzmorph-nn          # BiLSTM\n"
        "pip install uzmorph-bigru       # BiGRU\n"
        "pip install uzmorph-transformer # Transformer\n"
        "```\n"
        "---\n"
        "**Muallif**: Ulugbek Salaev  \n"
        'Website: <a href="https://morph.uz" target="_blank">morph.uz</a>\n'
    )

if __name__ == "__main__":
    demo.launch(ssr_mode=False)