Upload app.py
Browse files
app.py
CHANGED
|
@@ -116,24 +116,105 @@ a{ color:var(--primary-700)!important; }
|
|
| 116 |
#results_hdr > .gr-column:first-child{ justify-self:start !important; }
|
| 117 |
#results_hdr > .gr-column:last-child{ justify-self:end !important; }
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
/* Kill any default Gradio "pill" styling inside */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
/* The actual button */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
/* Active/selected */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
/* Hover: show #89AFA9 (inactive becomes active color on hover) */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
/* Remove Gradio's default label styling completely */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
/* Single visible button layer */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
/* Selected state (robust selectors) */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
/* Hover: only unselected gets light background */
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
#results_hdr{
|
| 138 |
display:grid !important;
|
| 139 |
grid-template-columns: 1fr auto !important;
|
|
@@ -150,41 +231,32 @@ a{ color:var(--primary-700)!important; }
|
|
| 150 |
box-shadow:none !important;
|
| 151 |
border:0 !important;
|
| 152 |
}
|
| 153 |
-
|
| 154 |
#lang_buttons{
|
| 155 |
display:flex !important;
|
| 156 |
gap:10px !important;
|
| 157 |
justify-content:flex-end !important;
|
| 158 |
align-items:center !important;
|
| 159 |
}
|
| 160 |
-
|
| 161 |
-
/* Match Marka/Tag geometry */
|
| 162 |
-
#lang_buttons .gr-button,
|
| 163 |
-
#lang_buttons button{
|
| 164 |
padding:0.35rem 0.85rem !important;
|
| 165 |
font-size:0.95rem !important;
|
| 166 |
border-radius:10px !important;
|
| 167 |
}
|
| 168 |
|
| 169 |
-
/* Inactive
|
| 170 |
-
#
|
| 171 |
-
#lang_buttons button.secondary{
|
| 172 |
background:var(--primary-200) !important;
|
| 173 |
border-color:var(--primary-600) !important;
|
| 174 |
color:#0b1b19 !important;
|
| 175 |
}
|
| 176 |
-
|
| 177 |
/* Hover inactive -> active color (#89AFA9) */
|
| 178 |
-
#
|
| 179 |
-
#lang_buttons button.secondary:hover{
|
| 180 |
background:var(--primary-500) !important;
|
| 181 |
border-color:var(--primary-600) !important;
|
| 182 |
color:#0b1b19 !important;
|
| 183 |
}
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
#lang_buttons .gr-button-primary,
|
| 187 |
-
#lang_buttons button.primary{
|
| 188 |
color:#0b1b19 !important;
|
| 189 |
}
|
| 190 |
"""
|
|
@@ -500,11 +572,11 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 500 |
results_hdr = gr.Row(elem_id="results_hdr", visible=False)
|
| 501 |
with results_hdr:
|
| 502 |
results_title = gr.Markdown("### Úrslit / Results")
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
|
| 509 |
out_df = gr.Dataframe(
|
| 510 |
value=pd.DataFrame(columns=[UI["fo"]["w"], UI["fo"]["t"], UI["fo"]["s"]]),
|
|
@@ -529,42 +601,81 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 529 |
rows = run_model(sentence)
|
| 530 |
df_main, df_mean, overview = render(rows, lang_current)
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
|
| 535 |
return (
|
| 536 |
rows,
|
| 537 |
gr.update(value=df_main, visible=True),
|
| 538 |
-
gr.update(value=df_mean
|
| 539 |
-
gr.update(value=overview
|
| 540 |
-
gr.update(visible=True), # results_hdr
|
| 541 |
gr.update(visible=True), # expanded_acc
|
| 542 |
-
gr.update(
|
| 543 |
-
gr.update(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
)
|
| 545 |
|
| 546 |
-
def on_set_lang(rows,
|
| 547 |
-
df_main, df_mean, overview = render(rows,
|
| 548 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
|
| 550 |
btn.click(
|
| 551 |
on_tag,
|
| 552 |
-
inputs=[inp,
|
| 553 |
-
outputs=[state, out_df, out_mean_df, overview_md, expanded_acc, results_hdr
|
|
|
|
| 554 |
queue=False,
|
| 555 |
)
|
| 556 |
|
| 557 |
-
|
|
|
|
| 558 |
on_set_fo,
|
| 559 |
inputs=[state],
|
| 560 |
-
outputs=[lang_state, out_df, out_mean_df, overview_md,
|
|
|
|
| 561 |
queue=False,
|
| 562 |
)
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
on_set_en,
|
| 566 |
inputs=[state],
|
| 567 |
-
outputs=[lang_state, out_df, out_mean_df, overview_md,
|
|
|
|
| 568 |
queue=False,
|
| 569 |
)
|
| 570 |
|
|
|
|
| 116 |
#results_hdr > .gr-column:first-child{ justify-self:start !important; }
|
| 117 |
#results_hdr > .gr-column:last-child{ justify-self:end !important; }
|
| 118 |
|
| 119 |
+
/* Language toggle (gr.Radio): style the LABEL as the button (robust across Gradio DOM variants) */
|
| 120 |
+
.lang_toggle{
|
| 121 |
+
background: transparent !important;
|
| 122 |
+
justify-self:end !important;
|
| 123 |
+
}
|
| 124 |
+
.lang_toggle fieldset{
|
| 125 |
+
border:0!important;
|
| 126 |
+
padding:0!important;
|
| 127 |
+
margin:0!important;
|
| 128 |
+
background:transparent!important;
|
| 129 |
+
}
|
| 130 |
+
.lang_toggle .wrap{
|
| 131 |
+
display:flex!important;
|
| 132 |
+
gap:10px!important;
|
| 133 |
+
background:transparent!important;
|
| 134 |
+
padding:0!important;
|
| 135 |
+
margin:0!important;
|
| 136 |
+
}
|
| 137 |
+
.lang_toggle input{
|
| 138 |
+
display:none!important;
|
| 139 |
+
}
|
| 140 |
|
| 141 |
/* Kill any default Gradio "pill" styling inside */
|
| 142 |
+
.lang_toggle label *{
|
| 143 |
+
background:transparent!important;
|
| 144 |
+
box-shadow:none!important;
|
| 145 |
+
border:0!important;
|
| 146 |
+
}
|
| 147 |
|
| 148 |
/* The actual button */
|
| 149 |
+
.lang_toggle label{
|
| 150 |
+
display:inline-flex !important;
|
| 151 |
+
align-items:center !important;
|
| 152 |
+
justify-content:center !important;
|
| 153 |
+
cursor:pointer !important;
|
| 154 |
+
user-select:none !important;
|
| 155 |
+
|
| 156 |
+
padding:0.35rem 0.85rem !important;
|
| 157 |
+
font-size:0.95rem !important;
|
| 158 |
+
border-radius:10px !important;
|
| 159 |
+
|
| 160 |
+
border:1px solid var(--primary-600) !important;
|
| 161 |
+
background: var(--primary-200) !important; /* inactive: lighter than #89AFA9 */
|
| 162 |
+
color:#0b1b19 !important; /* black-ish */
|
| 163 |
+
}
|
| 164 |
|
| 165 |
/* Active/selected */
|
| 166 |
+
.lang_toggle label:has(input:checked){
|
| 167 |
+
background: #89AFA9 !important;
|
| 168 |
+
border-color: var(--primary-600) !important;
|
| 169 |
+
color:#0b1b19 !important;
|
| 170 |
+
}
|
| 171 |
|
| 172 |
/* Hover: show #89AFA9 (inactive becomes active color on hover) */
|
| 173 |
+
.lang_toggle label:hover{
|
| 174 |
+
background:#89AFA9 !important;
|
| 175 |
+
border-color: var(--primary-600) !important;
|
| 176 |
+
color:#0b1b19 !important;
|
| 177 |
+
}
|
| 178 |
|
| 179 |
|
| 180 |
/* Remove Gradio's default label styling completely */
|
| 181 |
+
.lang_toggle label{
|
| 182 |
+
background:transparent!important;
|
| 183 |
+
border:0!important;
|
| 184 |
+
padding:0!important;
|
| 185 |
+
margin:0!important;
|
| 186 |
+
box-shadow:none!important;
|
| 187 |
+
}
|
| 188 |
|
| 189 |
/* Single visible button layer */
|
| 190 |
+
.lang_toggle label span{
|
| 191 |
+
all: unset;
|
| 192 |
+
display:inline-block;
|
| 193 |
+
cursor:pointer;
|
| 194 |
+
user-select:none;
|
| 195 |
+
padding:0.35rem 0.85rem;
|
| 196 |
+
font-size:0.95rem;
|
| 197 |
+
border-radius:10px;
|
| 198 |
+
border:1px solid var(--primary-600);
|
| 199 |
+
background: transparent; /* same as page */
|
| 200 |
+
color:#0b1b19;
|
| 201 |
+
box-shadow:none!important;
|
| 202 |
+
}
|
| 203 |
|
| 204 |
/* Selected state (robust selectors) */
|
| 205 |
+
.lang_toggle input:checked ~ span,
|
| 206 |
+
.lang_toggle label:has(input:checked) span{
|
| 207 |
+
background:var(--primary-500)!important;
|
| 208 |
+
border-color:var(--primary-600)!important;
|
| 209 |
+
color:#0b1b19!important;
|
| 210 |
+
}
|
| 211 |
|
| 212 |
/* Hover: only unselected gets light background */
|
| 213 |
+
.lang_toggle label:hover input:not(:checked) ~ span,
|
| 214 |
+
.lang_toggle label:hover:not(:has(input:checked)) span{
|
| 215 |
+
background:var(--primary-200)!important;
|
| 216 |
+
}
|
| 217 |
+
/* --- Language buttons (robust: 4 real buttons, show/hide to indicate active) --- */
|
| 218 |
#results_hdr{
|
| 219 |
display:grid !important;
|
| 220 |
grid-template-columns: 1fr auto !important;
|
|
|
|
| 231 |
box-shadow:none !important;
|
| 232 |
border:0 !important;
|
| 233 |
}
|
|
|
|
| 234 |
#lang_buttons{
|
| 235 |
display:flex !important;
|
| 236 |
gap:10px !important;
|
| 237 |
justify-content:flex-end !important;
|
| 238 |
align-items:center !important;
|
| 239 |
}
|
| 240 |
+
#lang_buttons .gr-button, #lang_buttons button{
|
|
|
|
|
|
|
|
|
|
| 241 |
padding:0.35rem 0.85rem !important;
|
| 242 |
font-size:0.95rem !important;
|
| 243 |
border-radius:10px !important;
|
| 244 |
}
|
| 245 |
|
| 246 |
+
/* Inactive: lighter than #89AFA9, black text */
|
| 247 |
+
#lang_fo_off, #lang_en_off{
|
|
|
|
| 248 |
background:var(--primary-200) !important;
|
| 249 |
border-color:var(--primary-600) !important;
|
| 250 |
color:#0b1b19 !important;
|
| 251 |
}
|
|
|
|
| 252 |
/* Hover inactive -> active color (#89AFA9) */
|
| 253 |
+
#lang_fo_off:hover, #lang_en_off:hover{
|
|
|
|
| 254 |
background:var(--primary-500) !important;
|
| 255 |
border-color:var(--primary-600) !important;
|
| 256 |
color:#0b1b19 !important;
|
| 257 |
}
|
| 258 |
+
/* Active: ensure black text */
|
| 259 |
+
#lang_fo_on, #lang_en_on{
|
|
|
|
|
|
|
| 260 |
color:#0b1b19 !important;
|
| 261 |
}
|
| 262 |
"""
|
|
|
|
| 572 |
results_hdr = gr.Row(elem_id="results_hdr", visible=False)
|
| 573 |
with results_hdr:
|
| 574 |
results_title = gr.Markdown("### Úrslit / Results")
|
| 575 |
+
with gr.Row(elem_id="lang_buttons"):
|
| 576 |
+
btn_lang_fo_on = gr.Button("Føroyskt", variant="primary", elem_id="lang_fo_on", visible=True)
|
| 577 |
+
btn_lang_fo_off = gr.Button("Føroyskt", variant="secondary", elem_id="lang_fo_off", visible=False)
|
| 578 |
+
btn_lang_en_on = gr.Button("English", variant="primary", elem_id="lang_en_on", visible=False)
|
| 579 |
+
btn_lang_en_off = gr.Button("English", variant="secondary", elem_id="lang_en_off", visible=True)
|
| 580 |
|
| 581 |
out_df = gr.Dataframe(
|
| 582 |
value=pd.DataFrame(columns=[UI["fo"]["w"], UI["fo"]["t"], UI["fo"]["s"]]),
|
|
|
|
| 601 |
rows = run_model(sentence)
|
| 602 |
df_main, df_mean, overview = render(rows, lang_current)
|
| 603 |
|
| 604 |
+
show_fo = (lang_current == "fo")
|
| 605 |
+
show_en = (lang_current == "en")
|
| 606 |
|
| 607 |
return (
|
| 608 |
rows,
|
| 609 |
gr.update(value=df_main, visible=True),
|
| 610 |
+
gr.update(value=df_mean),
|
| 611 |
+
gr.update(value=overview),
|
|
|
|
| 612 |
gr.update(visible=True), # expanded_acc
|
| 613 |
+
gr.update(visible=True), # results_hdr
|
| 614 |
+
gr.update(visible=show_fo), # fo_on
|
| 615 |
+
gr.update(visible=not show_fo), # fo_off
|
| 616 |
+
gr.update(visible=show_en), # en_on
|
| 617 |
+
gr.update(visible=not show_en), # en_off
|
| 618 |
+
lang_current,
|
| 619 |
)
|
| 620 |
|
| 621 |
+
def on_set_lang(rows, lang_value):
|
| 622 |
+
df_main, df_mean, overview = render(rows, lang_value)
|
| 623 |
+
|
| 624 |
+
show_fo = (lang_value == "fo")
|
| 625 |
+
show_en = (lang_value == "en")
|
| 626 |
+
|
| 627 |
+
return (
|
| 628 |
+
lang_value,
|
| 629 |
+
gr.update(value=df_main),
|
| 630 |
+
gr.update(value=df_mean),
|
| 631 |
+
gr.update(value=overview),
|
| 632 |
+
gr.update(visible=show_fo),
|
| 633 |
+
gr.update(visible=not show_fo),
|
| 634 |
+
gr.update(visible=show_en),
|
| 635 |
+
gr.update(visible=not show_en),
|
| 636 |
+
)
|
| 637 |
+
|
| 638 |
+
def on_set_fo(rows):
|
| 639 |
+
return on_set_lang(rows, "fo")
|
| 640 |
+
|
| 641 |
+
def on_set_en(rows):
|
| 642 |
+
return on_set_lang(rows, "en")
|
| 643 |
|
| 644 |
btn.click(
|
| 645 |
on_tag,
|
| 646 |
+
inputs=[inp, lang_state],
|
| 647 |
+
outputs=[state, out_df, out_mean_df, overview_md, expanded_acc, results_hdr,
|
| 648 |
+
btn_lang_fo_on, btn_lang_fo_off, btn_lang_en_on, btn_lang_en_off, lang_state],
|
| 649 |
queue=False,
|
| 650 |
)
|
| 651 |
|
| 652 |
+
# Language switch (does NOT rerun the model; just re-renders existing rows)
|
| 653 |
+
btn_lang_fo_on.click(
|
| 654 |
on_set_fo,
|
| 655 |
inputs=[state],
|
| 656 |
+
outputs=[lang_state, out_df, out_mean_df, overview_md,
|
| 657 |
+
btn_lang_fo_on, btn_lang_fo_off, btn_lang_en_on, btn_lang_en_off],
|
| 658 |
queue=False,
|
| 659 |
)
|
| 660 |
+
btn_lang_fo_off.click(
|
| 661 |
+
on_set_fo,
|
| 662 |
+
inputs=[state],
|
| 663 |
+
outputs=[lang_state, out_df, out_mean_df, overview_md,
|
| 664 |
+
btn_lang_fo_on, btn_lang_fo_off, btn_lang_en_on, btn_lang_en_off],
|
| 665 |
+
queue=False,
|
| 666 |
+
)
|
| 667 |
+
btn_lang_en_on.click(
|
| 668 |
+
on_set_en,
|
| 669 |
+
inputs=[state],
|
| 670 |
+
outputs=[lang_state, out_df, out_mean_df, overview_md,
|
| 671 |
+
btn_lang_fo_on, btn_lang_fo_off, btn_lang_en_on, btn_lang_en_off],
|
| 672 |
+
queue=False,
|
| 673 |
+
)
|
| 674 |
+
btn_lang_en_off.click(
|
| 675 |
on_set_en,
|
| 676 |
inputs=[state],
|
| 677 |
+
outputs=[lang_state, out_df, out_mean_df, overview_md,
|
| 678 |
+
btn_lang_fo_on, btn_lang_fo_off, btn_lang_en_on, btn_lang_en_off],
|
| 679 |
queue=False,
|
| 680 |
)
|
| 681 |
|