wagner-austin commited on
Commit
f4a567c
·
1 Parent(s): 98dfa93

reverted to block arabic check box, but not hide it

Browse files
Files changed (1) hide show
  1. app.py +12 -42
app.py CHANGED
@@ -1,6 +1,7 @@
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
@@ -17,40 +18,18 @@ def transliterate(text, lang, include_arabic, output_format):
17
  result = to_ipa(text, lang)
18
  format_label = "IPA"
19
  result = ud.normalize("NFC", result)
20
- stats_md = (f"**UTF-8 bytes:** Cyrillic = {len(text.encode('utf8'))}, "
21
- f"{format_label} = {len(result.encode('utf8'))}")
22
  return result, stats_md
23
  except Exception as e:
24
  raise gr.Error(str(e))
25
 
26
- # Function to toggle Arabic checkbox visibility based on output format
27
- # Uses 'hidden' class to keep layout stable
28
-
29
- def _toggle_arabic_visibility(mode: str):
30
- hidden = mode != "Latin"
31
- new_classes = ["fade", "fade-hidden"] if hidden else ["fade", "fade-visible"]
32
- return gr.update(elem_classes=new_classes)
33
 
34
  # Create the Gradio interface
35
- demo = gr.Blocks(
36
- title="Turkic Transliteration Demo",
37
- css="""
38
- /* baseline footprint & margin */
39
- #arabic-box { margin-top:0.25rem; }
40
-
41
- /* animation helpers */
42
- .fade { transition:opacity .25s ease; }
43
- .fade-visible { opacity:1; }
44
- .fade-hidden {
45
- opacity:0;
46
- pointer-events:none;
47
- background:transparent !important;
48
- padding:0 !important;
49
- }
50
- """
51
- )
52
-
53
- with demo:
54
  gr.Markdown("# Turkic Transliteration Demo")
55
  gr.Markdown("Enter Cyrillic text for Kazakh (kk) or Kyrgyz (ky) and see the Latin transliteration")
56
 
@@ -73,12 +52,7 @@ with demo:
73
  info="Latin = Standard Latin alphabet, IPA = International Phonetic Alphabet",
74
  value="Latin"
75
  )
76
- include_arabic = gr.Checkbox(
77
- value=False,
78
- label="Also transliterate embedded Arabic (Latin-mode only)",
79
- elem_id="arabic-box",
80
- elem_classes=["fade", "fade-visible"] # start visible; we’ll flip later
81
- )
82
 
83
  with gr.Column():
84
  output_text = gr.Textbox(
@@ -121,17 +95,13 @@ with demo:
121
  inputs=[input_text, lang, include_arabic, output_format],
122
  outputs=[output_text, stats]
123
  )
124
- # Register the handler for fade effect (before transliteration)
125
- output_format.change(_toggle_arabic_visibility, output_format, include_arabic)
126
-
127
- # Register transliteration handler
128
  output_format.change(
129
- transliterate,
130
- [input_text, lang, include_arabic, output_format],
131
- [output_text, stats]
132
  )
133
 
134
-
135
  # Launch the app
136
  if __name__ == "__main__":
137
  demo.queue().launch()
 
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
 
18
  result = to_ipa(text, lang)
19
  format_label = "IPA"
20
  result = ud.normalize("NFC", result)
21
+ stats_md = (f"**Bytes** Cyrillic : {len(text.encode('utf8'))}, "
22
+ f"{format_label} : {len(result.encode('utf8'))}")
23
  return result, stats_md
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:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  gr.Markdown("# Turkic Transliteration Demo")
34
  gr.Markdown("Enter Cyrillic text for Kazakh (kk) or Kyrgyz (ky) and see the Latin transliteration")
35
 
 
52
  info="Latin = Standard Latin alphabet, IPA = International Phonetic Alphabet",
53
  value="Latin"
54
  )
55
+ include_arabic = gr.Checkbox(False, label="Also transliterate Arabic script (Latin mode only)")
 
 
 
 
 
56
 
57
  with gr.Column():
58
  output_text = gr.Textbox(
 
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__":
107
  demo.queue().launch()