Spaces:
Sleeping
Sleeping
| 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) | |