Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Refine target tabs and translator alignment
Browse files
app.py
CHANGED
|
@@ -375,6 +375,8 @@ def render_target_tabs(
|
|
| 375 |
classes.append("loading")
|
| 376 |
if language in completed_set:
|
| 377 |
classes.append("complete")
|
|
|
|
|
|
|
| 378 |
safe_language = html.escape(language, quote=True)
|
| 379 |
status = (
|
| 380 |
'<span class="tab-spinner" aria-hidden="true"></span>'
|
|
@@ -391,6 +393,10 @@ def render_target_tabs(
|
|
| 391 |
f'aria-selected="{str(language == active).lower()}">'
|
| 392 |
f"<span>{safe_language}</span>{status}</button>"
|
| 393 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 394 |
return f'<div class="target-tabs" role="tablist">{"".join(tabs)}</div>'
|
| 395 |
|
| 396 |
|
|
@@ -658,6 +664,9 @@ APP_JS = """
|
|
| 658 |
const tab = event.target.closest("[data-target-tab]");
|
| 659 |
if (tab) sendValue("target-tab-bridge", tab.dataset.targetTab);
|
| 660 |
|
|
|
|
|
|
|
|
|
|
| 661 |
const example = event.target.closest("[data-example-index]");
|
| 662 |
if (example) sendValue("example-bridge", example.dataset.exampleIndex);
|
| 663 |
});
|
|
@@ -746,14 +755,6 @@ def build_demo() -> gr.Blocks:
|
|
| 746 |
),
|
| 747 |
elem_id="target-tabs-shell",
|
| 748 |
)
|
| 749 |
-
target_add = gr.Button(
|
| 750 |
-
"+",
|
| 751 |
-
variant="secondary",
|
| 752 |
-
size="sm",
|
| 753 |
-
scale=0,
|
| 754 |
-
min_width=40,
|
| 755 |
-
elem_id="target-add-button",
|
| 756 |
-
)
|
| 757 |
target_picker = gr.CheckboxGroup(
|
| 758 |
choices=SUPPORTED_LANGUAGES,
|
| 759 |
value=list(DEFAULT_TARGETS),
|
|
@@ -794,6 +795,12 @@ def build_demo() -> gr.Blocks:
|
|
| 794 |
container=False,
|
| 795 |
elem_id="target-tab-bridge",
|
| 796 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
example_bridge = gr.Textbox(
|
| 798 |
value="",
|
| 799 |
show_label=False,
|
|
@@ -816,7 +823,7 @@ def build_demo() -> gr.Blocks:
|
|
| 816 |
queue=False,
|
| 817 |
)
|
| 818 |
|
| 819 |
-
|
| 820 |
fn=lambda open_value: toggle_picker(open_value, "target"),
|
| 821 |
inputs=target_open,
|
| 822 |
outputs=[target_picker, target_open],
|
|
|
|
| 375 |
classes.append("loading")
|
| 376 |
if language in completed_set:
|
| 377 |
classes.append("complete")
|
| 378 |
+
else:
|
| 379 |
+
classes.append("unavailable")
|
| 380 |
safe_language = html.escape(language, quote=True)
|
| 381 |
status = (
|
| 382 |
'<span class="tab-spinner" aria-hidden="true"></span>'
|
|
|
|
| 393 |
f'aria-selected="{str(language == active).lower()}">'
|
| 394 |
f"<span>{safe_language}</span>{status}</button>"
|
| 395 |
)
|
| 396 |
+
tabs.append(
|
| 397 |
+
'<button type="button" class="target-add" data-target-add '
|
| 398 |
+
'aria-label="Add target languages">+</button>'
|
| 399 |
+
)
|
| 400 |
return f'<div class="target-tabs" role="tablist">{"".join(tabs)}</div>'
|
| 401 |
|
| 402 |
|
|
|
|
| 664 |
const tab = event.target.closest("[data-target-tab]");
|
| 665 |
if (tab) sendValue("target-tab-bridge", tab.dataset.targetTab);
|
| 666 |
|
| 667 |
+
const addTarget = event.target.closest("[data-target-add]");
|
| 668 |
+
if (addTarget) sendValue("target-add-bridge", String(Date.now()));
|
| 669 |
+
|
| 670 |
const example = event.target.closest("[data-example-index]");
|
| 671 |
if (example) sendValue("example-bridge", example.dataset.exampleIndex);
|
| 672 |
});
|
|
|
|
| 755 |
),
|
| 756 |
elem_id="target-tabs-shell",
|
| 757 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
target_picker = gr.CheckboxGroup(
|
| 759 |
choices=SUPPORTED_LANGUAGES,
|
| 760 |
value=list(DEFAULT_TARGETS),
|
|
|
|
| 795 |
container=False,
|
| 796 |
elem_id="target-tab-bridge",
|
| 797 |
)
|
| 798 |
+
target_add_bridge = gr.Textbox(
|
| 799 |
+
value="",
|
| 800 |
+
show_label=False,
|
| 801 |
+
container=False,
|
| 802 |
+
elem_id="target-add-bridge",
|
| 803 |
+
)
|
| 804 |
example_bridge = gr.Textbox(
|
| 805 |
value="",
|
| 806 |
show_label=False,
|
|
|
|
| 823 |
queue=False,
|
| 824 |
)
|
| 825 |
|
| 826 |
+
target_add_bridge.change(
|
| 827 |
fn=lambda open_value: toggle_picker(open_value, "target"),
|
| 828 |
inputs=target_open,
|
| 829 |
outputs=[target_picker, target_open],
|
style.css
CHANGED
|
@@ -119,8 +119,7 @@ footer {
|
|
| 119 |
z-index: 30;
|
| 120 |
}
|
| 121 |
|
| 122 |
-
#source-language-button
|
| 123 |
-
#target-add-button {
|
| 124 |
width: max-content;
|
| 125 |
min-width: 0 !important;
|
| 126 |
border: 0 !important;
|
|
@@ -135,8 +134,7 @@ footer {
|
|
| 135 |
padding: 7px 10px !important;
|
| 136 |
}
|
| 137 |
|
| 138 |
-
#source-language-button:hover
|
| 139 |
-
#target-add-button:hover {
|
| 140 |
background: var(--marble-200) !important;
|
| 141 |
}
|
| 142 |
|
|
@@ -195,17 +193,20 @@ footer {
|
|
| 195 |
}
|
| 196 |
|
| 197 |
#instructions-input {
|
|
|
|
| 198 |
min-height: 128px;
|
| 199 |
border-radius: 22px !important;
|
| 200 |
}
|
| 201 |
|
| 202 |
#source-text-input {
|
|
|
|
| 203 |
min-height: 218px;
|
| 204 |
border-radius: 24px !important;
|
| 205 |
}
|
| 206 |
|
| 207 |
#translation-output {
|
| 208 |
-
|
|
|
|
| 209 |
border-radius: 28px !important;
|
| 210 |
background: #f0f2f3 !important;
|
| 211 |
}
|
|
@@ -214,6 +215,7 @@ footer {
|
|
| 214 |
#source-text-input textarea,
|
| 215 |
#translation-output textarea {
|
| 216 |
height: 100% !important;
|
|
|
|
| 217 |
padding: 18px 20px !important;
|
| 218 |
border: 0 !important;
|
| 219 |
background: transparent !important;
|
|
@@ -323,6 +325,15 @@ footer {
|
|
| 323 |
opacity: 0.38;
|
| 324 |
}
|
| 325 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
.tab-spinner,
|
| 327 |
.tab-check {
|
| 328 |
display: inline-flex;
|
|
@@ -349,14 +360,27 @@ footer {
|
|
| 349 |
height: 12px;
|
| 350 |
}
|
| 351 |
|
| 352 |
-
|
|
|
|
| 353 |
flex: 0 0 36px;
|
|
|
|
|
|
|
| 354 |
width: 36px;
|
| 355 |
height: 36px;
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
}
|
| 361 |
|
| 362 |
/* Examples */
|
|
@@ -444,6 +468,7 @@ footer {
|
|
| 444 |
}
|
| 445 |
|
| 446 |
#target-tab-bridge,
|
|
|
|
| 447 |
#example-bridge {
|
| 448 |
display: none !important;
|
| 449 |
}
|
|
@@ -484,6 +509,7 @@ footer {
|
|
| 484 |
}
|
| 485 |
|
| 486 |
#translation-output {
|
|
|
|
| 487 |
min-height: 280px;
|
| 488 |
}
|
| 489 |
|
|
|
|
| 119 |
z-index: 30;
|
| 120 |
}
|
| 121 |
|
| 122 |
+
#source-language-button {
|
|
|
|
| 123 |
width: max-content;
|
| 124 |
min-width: 0 !important;
|
| 125 |
border: 0 !important;
|
|
|
|
| 134 |
padding: 7px 10px !important;
|
| 135 |
}
|
| 136 |
|
| 137 |
+
#source-language-button:hover {
|
|
|
|
| 138 |
background: var(--marble-200) !important;
|
| 139 |
}
|
| 140 |
|
|
|
|
| 193 |
}
|
| 194 |
|
| 195 |
#instructions-input {
|
| 196 |
+
height: 128px;
|
| 197 |
min-height: 128px;
|
| 198 |
border-radius: 22px !important;
|
| 199 |
}
|
| 200 |
|
| 201 |
#source-text-input {
|
| 202 |
+
height: 218px;
|
| 203 |
min-height: 218px;
|
| 204 |
border-radius: 24px !important;
|
| 205 |
}
|
| 206 |
|
| 207 |
#translation-output {
|
| 208 |
+
height: 412px;
|
| 209 |
+
min-height: 412px;
|
| 210 |
border-radius: 28px !important;
|
| 211 |
background: #f0f2f3 !important;
|
| 212 |
}
|
|
|
|
| 215 |
#source-text-input textarea,
|
| 216 |
#translation-output textarea {
|
| 217 |
height: 100% !important;
|
| 218 |
+
min-height: 0 !important;
|
| 219 |
padding: 18px 20px !important;
|
| 220 |
border: 0 !important;
|
| 221 |
background: transparent !important;
|
|
|
|
| 325 |
opacity: 0.38;
|
| 326 |
}
|
| 327 |
|
| 328 |
+
.target-tab.unavailable {
|
| 329 |
+
opacity: 0.38;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
.target-tab.unavailable:hover,
|
| 333 |
+
.target-tab.unavailable.active {
|
| 334 |
+
opacity: 0.55;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
.tab-spinner,
|
| 338 |
.tab-check {
|
| 339 |
display: inline-flex;
|
|
|
|
| 360 |
height: 12px;
|
| 361 |
}
|
| 362 |
|
| 363 |
+
.target-add {
|
| 364 |
+
display: inline-flex;
|
| 365 |
flex: 0 0 36px;
|
| 366 |
+
align-items: center;
|
| 367 |
+
justify-content: center;
|
| 368 |
width: 36px;
|
| 369 |
height: 36px;
|
| 370 |
+
margin-left: 2px;
|
| 371 |
+
padding: 0;
|
| 372 |
+
border: 0;
|
| 373 |
+
border-radius: 999px;
|
| 374 |
+
background: transparent;
|
| 375 |
+
color: var(--volcanic-900);
|
| 376 |
+
cursor: pointer;
|
| 377 |
+
font-family: var(--sans);
|
| 378 |
+
font-size: 21px;
|
| 379 |
+
font-weight: 400;
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
.target-add:hover {
|
| 383 |
+
background: var(--marble-200);
|
| 384 |
}
|
| 385 |
|
| 386 |
/* Examples */
|
|
|
|
| 468 |
}
|
| 469 |
|
| 470 |
#target-tab-bridge,
|
| 471 |
+
#target-add-bridge,
|
| 472 |
#example-bridge {
|
| 473 |
display: none !important;
|
| 474 |
}
|
|
|
|
| 509 |
}
|
| 510 |
|
| 511 |
#translation-output {
|
| 512 |
+
height: 280px;
|
| 513 |
min-height: 280px;
|
| 514 |
}
|
| 515 |
|