Spaces:
Running
Running
Daryl Lim Claude Sonnet 4.6 commited on
Commit ·
77df3a5
1
Parent(s): 12ff0ac
feat: add character limit display and keyboard shortcut hint
Browse filesCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- app.py +5 -3
- tests/test_app.py +14 -0
app.py
CHANGED
|
@@ -86,7 +86,7 @@ def translate(
|
|
| 86 |
|
| 87 |
|
| 88 |
def _update_char_count(text: str) -> str:
|
| 89 |
-
return f"{len(text)}
|
| 90 |
|
| 91 |
|
| 92 |
def _build_demo() -> gr.Blocks:
|
|
@@ -105,7 +105,9 @@ def _build_demo() -> gr.Blocks:
|
|
| 105 |
lines=6,
|
| 106 |
show_label=False,
|
| 107 |
)
|
| 108 |
-
|
|
|
|
|
|
|
| 109 |
with gr.Column():
|
| 110 |
target_language = gr.Dropdown(
|
| 111 |
choices=language_names,
|
|
@@ -141,7 +143,7 @@ def _build_demo() -> gr.Blocks:
|
|
| 141 |
outputs=char_count,
|
| 142 |
)
|
| 143 |
clear_btn.click(
|
| 144 |
-
fn=lambda: ("", "", "0
|
| 145 |
outputs=[input_text, output_text, char_count],
|
| 146 |
)
|
| 147 |
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
def _update_char_count(text: str) -> str:
|
| 89 |
+
return f"{len(text)} / 2,000"
|
| 90 |
|
| 91 |
|
| 92 |
def _build_demo() -> gr.Blocks:
|
|
|
|
| 105 |
lines=6,
|
| 106 |
show_label=False,
|
| 107 |
)
|
| 108 |
+
with gr.Row():
|
| 109 |
+
char_count = gr.Markdown("0 / 2,000")
|
| 110 |
+
gr.Markdown("Ctrl+Enter to submit")
|
| 111 |
with gr.Column():
|
| 112 |
target_language = gr.Dropdown(
|
| 113 |
choices=language_names,
|
|
|
|
| 143 |
outputs=char_count,
|
| 144 |
)
|
| 145 |
clear_btn.click(
|
| 146 |
+
fn=lambda: ("", "", "0 / 2,000"),
|
| 147 |
outputs=[input_text, output_text, char_count],
|
| 148 |
)
|
| 149 |
|
tests/test_app.py
CHANGED
|
@@ -201,6 +201,20 @@ def test_input_textbox_has_no_placeholder(demo):
|
|
| 201 |
assert interactive[0].placeholder is None, f"Expected no placeholder, got {interactive[0].placeholder!r}"
|
| 202 |
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
# --- Slow tests (require CUDA + model download) ---
|
| 205 |
|
| 206 |
gpu_available = torch.cuda.is_available()
|
|
|
|
| 201 |
assert interactive[0].placeholder is None, f"Expected no placeholder, got {interactive[0].placeholder!r}"
|
| 202 |
|
| 203 |
|
| 204 |
+
def test_char_count_shows_limit(demo):
|
| 205 |
+
"""Character count should show '0 / 2,000' format."""
|
| 206 |
+
markdowns = [b for b in demo.blocks.values() if type(b).__name__ == "Markdown"]
|
| 207 |
+
limit_mds = [m for m in markdowns if "2,000" in m.value]
|
| 208 |
+
assert len(limit_mds) == 1, f"Expected one markdown with '2,000', found {len(limit_mds)}"
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def test_shortcut_hint_exists(demo):
|
| 212 |
+
"""Keyboard shortcut hint should be visible."""
|
| 213 |
+
markdowns = [b for b in demo.blocks.values() if type(b).__name__ == "Markdown"]
|
| 214 |
+
hints = [m for m in markdowns if "Ctrl+Enter" in m.value]
|
| 215 |
+
assert len(hints) == 1, f"Expected one shortcut hint, found {len(hints)}"
|
| 216 |
+
|
| 217 |
+
|
| 218 |
# --- Slow tests (require CUDA + model download) ---
|
| 219 |
|
| 220 |
gpu_available = torch.cuda.is_available()
|