Daryl Lim Claude Opus 4.6 (1M context) commited on
Commit
be7cb6a
·
1 Parent(s): 459c8a5

refactor: extract _format_info helper for info string

Browse files

Single source of truth for the hint and character count template,
used by both the initial textbox info and the change handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -86,8 +86,12 @@ def translate(
86
  return result
87
 
88
 
 
 
 
 
89
  def _update_char_count(text: str) -> dict:
90
- return gr.update(info=f"Press Ctrl+Enter to apply · {len(text)} / 2,000")
91
 
92
 
93
  def _translate_with_loading(
@@ -115,7 +119,7 @@ def _build_demo() -> gr.Blocks:
115
  lines=6,
116
  show_label=False,
117
  buttons=["clear"],
118
- info="Press Ctrl+Enter to apply · 0 / 2,000",
119
  )
120
  with gr.Column():
121
  target_language = gr.Dropdown(
 
86
  return result
87
 
88
 
89
+ def _format_info(char_count: int) -> str:
90
+ return f"Press Ctrl+Enter to apply · {char_count} / 2,000"
91
+
92
+
93
  def _update_char_count(text: str) -> dict:
94
+ return gr.update(info=_format_info(len(text)))
95
 
96
 
97
  def _translate_with_loading(
 
119
  lines=6,
120
  show_label=False,
121
  buttons=["clear"],
122
+ info=_format_info(0),
123
  )
124
  with gr.Column():
125
  target_language = gr.Dropdown(