wagner-austin commited on
Commit
ddc7b60
·
1 Parent(s): b4b94d4

UI: Arabic checkbox disables/unchecks in IPA mode; Examples now run transliteration

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -1,7 +1,6 @@
1
  """
2
  A simple web interface to demonstrate the Turkish transliteration.
3
  """
4
- import os
5
  import gradio as gr
6
  from turkic_translit.core import to_latin, to_ipa
7
  import unicodedata as ud
@@ -24,9 +23,14 @@ def transliterate(text, lang, include_arabic, output_format):
24
  except Exception as e:
25
  raise gr.Error(str(e))
26
 
27
- # Function to enable/disable Arabic checkbox based on output format
28
- def toggle_arabic_checkbox(mode):
29
- return gr.update(interactive=(mode == "Latin"))
 
 
 
 
 
30
 
31
  # Create the Gradio interface
32
  with gr.Blocks(title="Turkic Transliteration Demo") as demo:
@@ -69,7 +73,12 @@ with gr.Blocks(title="Turkic Transliteration Demo") as demo:
69
  ["Кыргыз тили - Түрк тилдеринин бири.", "ky", "Latin"],
70
  ["Кыргыз тили - Түрк тилдеринин бири.", "ky", "IPA"]
71
  ]
72
- gr.Examples(examples, [input_text, lang, output_format])
 
 
 
 
 
73
 
74
  # Live preview: update output after user pauses typing
75
  input_text.input(
@@ -95,12 +104,8 @@ with gr.Blocks(title="Turkic Transliteration Demo") as demo:
95
  inputs=[input_text, lang, include_arabic, output_format],
96
  outputs=[output_text, stats]
97
  )
98
- # Disable Arabic checkbox in IPA mode
99
- output_format.change(
100
- fn=toggle_arabic_checkbox,
101
- inputs=output_format,
102
- outputs=include_arabic
103
- )
104
 
105
  # Launch the app
106
  if __name__ == "__main__":
 
1
  """
2
  A simple web interface to demonstrate the Turkish transliteration.
3
  """
 
4
  import gradio as gr
5
  from turkic_translit.core import to_latin, to_ipa
6
  import unicodedata as ud
 
23
  except Exception as e:
24
  raise gr.Error(str(e))
25
 
26
+ # Function to reset & (de)activate the Arabic checkbox when mode changes
27
+ def _sync_arabic_checkbox(mode: str):
28
+ """Uncheck and disable in IPA; leave state untouched in Latin."""
29
+ if mode == "IPA":
30
+ # Forced off + greyed-out
31
+ return gr.update(value=False, interactive=False)
32
+ # Latin: keep whatever the user last chose, stay interactive
33
+ return gr.update(interactive=True)
34
 
35
  # Create the Gradio interface
36
  with gr.Blocks(title="Turkic Transliteration Demo") as demo:
 
73
  ["Кыргыз тили - Түрк тилдеринин бири.", "ky", "Latin"],
74
  ["Кыргыз тили - Түрк тилдеринин бири.", "ky", "IPA"]
75
  ]
76
+ gr.Examples(
77
+ examples,
78
+ [input_text, lang, output_format], # inputs populated by the row
79
+ [output_text, stats], # widgets to update
80
+ fn=transliterate # run on click
81
+ )
82
 
83
  # Live preview: update output after user pauses typing
84
  input_text.input(
 
104
  inputs=[input_text, lang, include_arabic, output_format],
105
  outputs=[output_text, stats]
106
  )
107
+ # Sync Arabic checkbox with mode
108
+ output_format.change(_sync_arabic_checkbox, output_format, include_arabic)
 
 
 
 
109
 
110
  # Launch the app
111
  if __name__ == "__main__":