Spaces:
Running
on
Zero
Running
on
Zero
| """ | |
| Analysis tabs component. | |
| Provides Error, Ghunnah, Madd, and Dev analysis tabs. | |
| """ | |
| import gradio as gr | |
| from config import DEV_TAB_VISIBLE | |
| from i8n import t | |
| def create_dev_tab_content(init_phonemes: str) -> dict: | |
| """ | |
| Create Dev tab internal components. | |
| Args: | |
| init_phonemes: Initial phonemes string for the textboxes | |
| Returns: | |
| Dict with keys: | |
| - canonical_phonemes: gr.Textbox | |
| - detected_phonemes: gr.Textbox | |
| - simulate_btn: gr.Button | |
| - reset_btn: gr.Button | |
| - save_btn: gr.Button | |
| - load_btn: gr.Button | |
| - test_name: gr.Textbox | |
| - test_source: gr.Radio | |
| - simulation_output: gr.HTML | |
| - save_status: gr.HTML | |
| - tests_output: gr.HTML | |
| """ | |
| gr.Markdown("### Error Simulation\nTest error detection by modifying detected phonemes.") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| canonical_phonemes = gr.Textbox( | |
| label="Canonical Phonemes (from phonemizer)", | |
| value=init_phonemes, | |
| lines=3, | |
| interactive=False, | |
| ) | |
| with gr.Column(scale=1): | |
| detected_phonemes = gr.Textbox( | |
| label="Detected Phonemes (edit to simulate errors)", | |
| value=init_phonemes, | |
| lines=3, | |
| interactive=True, | |
| placeholder="Modify phonemes here to simulate detection errors...", | |
| ) | |
| with gr.Row(): | |
| simulate_btn = gr.Button("Simulate Errors", variant="primary") | |
| reset_btn = gr.Button("Reset to Canonical", variant="secondary") | |
| simulation_output = gr.HTML(value="", label="Simulation Result") | |
| # Test Case Management Section | |
| with gr.Row(): | |
| test_name = gr.Textbox( | |
| label="Test Name", | |
| placeholder="Enter a name for this test case...", | |
| scale=2, | |
| ) | |
| save_btn = gr.Button("Save Test Case", variant="secondary", scale=1) | |
| save_status = gr.HTML(value="", label="Save Status") | |
| gr.Markdown("### Test Runner") | |
| with gr.Row(): | |
| test_source = gr.Radio( | |
| choices=["MDD Tests (mdd_tests.yaml)", "Formal Tests (error_analysis/)"], | |
| value="MDD Tests (mdd_tests.yaml)", | |
| label="Test Source", | |
| scale=2, | |
| ) | |
| load_btn = gr.Button("Load & Run Tests", variant="primary", scale=1) | |
| tests_output = gr.HTML(value="", label="Test Results") | |
| return { | |
| "canonical_phonemes": canonical_phonemes, | |
| "detected_phonemes": detected_phonemes, | |
| "simulate_btn": simulate_btn, | |
| "reset_btn": reset_btn, | |
| "save_btn": save_btn, | |
| "load_btn": load_btn, | |
| "test_name": test_name, | |
| "test_source": test_source, | |
| "simulation_output": simulation_output, | |
| "save_status": save_status, | |
| "tests_output": tests_output, | |
| } | |
| def create_analysis_tabs( | |
| init_ghunnah_html: str, | |
| init_madd_html: str, | |
| init_phonemes: str | |
| ) -> dict: | |
| """ | |
| Create all analysis tabs. | |
| Args: | |
| init_ghunnah_html: Initial ghunnah analysis HTML | |
| init_madd_html: Initial madd analysis HTML | |
| init_phonemes: Initial phonemes string for dev tab | |
| Returns: | |
| Dict with keys: | |
| - tabs: gr.Tabs container | |
| - error_display: gr.HTML | |
| - ghunnah_display: gr.HTML | |
| - madd_display: gr.HTML | |
| - dev: dict (from create_dev_tab_content) | |
| """ | |
| with gr.Tabs() as tabs: | |
| with gr.Tab(t("tabs.error_analysis")): | |
| error_display = gr.HTML(value="", label=t("tabs.error_analysis")) | |
| with gr.Tab(t("tabs.ghunnah_analysis")): | |
| ghunnah_display = gr.HTML(value=init_ghunnah_html, label=t("tabs.ghunnah_analysis")) | |
| with gr.Tab(t("tabs.madd_analysis")): | |
| madd_display = gr.HTML(value=init_madd_html, label=t("tabs.madd_analysis")) | |
| if DEV_TAB_VISIBLE: | |
| with gr.Tab(t("tabs.dev")): | |
| dev = create_dev_tab_content(init_phonemes) | |
| else: | |
| dev = None | |
| return { | |
| "tabs": tabs, | |
| "error_display": error_display, | |
| "ghunnah_display": ghunnah_display, | |
| "madd_display": madd_display, | |
| "dev": dev, | |
| } | |