Upload app.py
Browse files
app.py
CHANGED
|
@@ -116,103 +116,76 @@ 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 |
-
/* 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 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
}
|
| 217 |
"""
|
| 218 |
|
|
@@ -521,12 +494,12 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 521 |
btn = gr.Button("Marka / Tag", variant="primary")
|
| 522 |
|
| 523 |
state = gr.State([])
|
|
|
|
| 524 |
|
| 525 |
# Hide results header + toggle until Tag
|
| 526 |
results_hdr = gr.Row(elem_id="results_hdr", visible=False)
|
| 527 |
with results_hdr:
|
| 528 |
results_title = gr.Markdown("### Úrslit / Results")
|
| 529 |
-
lang = gr.Radio(
|
| 530 |
choices=[("Føroyskt","fo"), ("English","en")],
|
| 531 |
value="fo",
|
| 532 |
show_label=False,
|
|
@@ -552,19 +525,25 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 552 |
with overview_acc:
|
| 553 |
overview_md = gr.Markdown(build_overview("fo"))
|
| 554 |
|
| 555 |
-
def on_tag(sentence,
|
| 556 |
rows = run_model(sentence)
|
| 557 |
-
df_main, df_mean, overview = render(rows,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
return (
|
| 559 |
rows,
|
| 560 |
gr.update(value=df_main, visible=True),
|
| 561 |
-
gr.update(value=df_mean),
|
| 562 |
-
gr.update(value=overview),
|
| 563 |
-
gr.update(visible=True), # expanded_acc
|
| 564 |
gr.update(visible=True), # results_hdr
|
|
|
|
|
|
|
|
|
|
| 565 |
)
|
| 566 |
|
| 567 |
-
def
|
| 568 |
df_main, df_mean, overview = render(rows, lang_choice)
|
| 569 |
return (gr.update(value=df_main), gr.update(value=df_mean), gr.update(value=overview))
|
| 570 |
|
|
@@ -575,10 +554,17 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 575 |
queue=False,
|
| 576 |
)
|
| 577 |
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
inputs=[state
|
| 581 |
-
outputs=[out_df, out_mean_df, overview_md],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 582 |
queue=False,
|
| 583 |
)
|
| 584 |
|
|
|
|
| 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 |
+
/* --- Language buttons (real buttons, not Radio pills) --- */
|
| 137 |
+
#results_hdr{
|
| 138 |
+
display:grid !important;
|
| 139 |
+
grid-template-columns: 1fr auto !important;
|
| 140 |
+
align-items:center !important;
|
| 141 |
+
gap:12px !important;
|
| 142 |
+
padding:0 !important;
|
| 143 |
+
margin:0 !important;
|
| 144 |
+
background:transparent !important;
|
| 145 |
+
box-shadow:none !important;
|
| 146 |
+
border:0 !important;
|
| 147 |
+
}
|
| 148 |
+
#results_hdr, #results_hdr *{
|
| 149 |
+
background:transparent !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 = lighter green, black text */
|
| 170 |
+
#lang_buttons .gr-button-secondary,
|
| 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 |
+
#lang_buttons .gr-button-secondary:hover,
|
| 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 |
+
/* Active already uses primary; ensure black text */
|
| 186 |
+
#lang_buttons .gr-button-primary,
|
| 187 |
+
#lang_buttons button.primary{
|
| 188 |
+
color:#0b1b19 !important;
|
| 189 |
}
|
| 190 |
"""
|
| 191 |
|
|
|
|
| 494 |
btn = gr.Button("Marka / Tag", variant="primary")
|
| 495 |
|
| 496 |
state = gr.State([])
|
| 497 |
+
lang_state = gr.State("fo")
|
| 498 |
|
| 499 |
# Hide results header + toggle until Tag
|
| 500 |
results_hdr = gr.Row(elem_id="results_hdr", visible=False)
|
| 501 |
with results_hdr:
|
| 502 |
results_title = gr.Markdown("### Úrslit / Results")
|
|
|
|
| 503 |
choices=[("Føroyskt","fo"), ("English","en")],
|
| 504 |
value="fo",
|
| 505 |
show_label=False,
|
|
|
|
| 525 |
with overview_acc:
|
| 526 |
overview_md = gr.Markdown(build_overview("fo"))
|
| 527 |
|
| 528 |
+
def on_tag(sentence, lang_current):
|
| 529 |
rows = run_model(sentence)
|
| 530 |
+
df_main, df_mean, overview = render(rows, lang_current)
|
| 531 |
+
|
| 532 |
+
fo_var = "primary" if lang_current == "fo" else "secondary"
|
| 533 |
+
en_var = "primary" if lang_current == "en" else "secondary"
|
| 534 |
+
|
| 535 |
return (
|
| 536 |
rows,
|
| 537 |
gr.update(value=df_main, visible=True),
|
| 538 |
+
gr.update(value=df_mean, visible=True),
|
| 539 |
+
gr.update(value=overview, visible=True),
|
|
|
|
| 540 |
gr.update(visible=True), # results_hdr
|
| 541 |
+
gr.update(visible=True), # expanded_acc
|
| 542 |
+
gr.update(variant=fo_var),
|
| 543 |
+
gr.update(variant=en_var),
|
| 544 |
)
|
| 545 |
|
| 546 |
+
def on_set_lang(rows, lang_choice):
|
| 547 |
df_main, df_mean, overview = render(rows, lang_choice)
|
| 548 |
return (gr.update(value=df_main), gr.update(value=df_mean), gr.update(value=overview))
|
| 549 |
|
|
|
|
| 554 |
queue=False,
|
| 555 |
)
|
| 556 |
|
| 557 |
+
btn_lang_fo.click(
|
| 558 |
+
on_set_fo,
|
| 559 |
+
inputs=[state],
|
| 560 |
+
outputs=[lang_state, out_df, out_mean_df, overview_md, btn_lang_fo, btn_lang_en],
|
| 561 |
+
queue=False,
|
| 562 |
+
)
|
| 563 |
+
|
| 564 |
+
btn_lang_en.click(
|
| 565 |
+
on_set_en,
|
| 566 |
+
inputs=[state],
|
| 567 |
+
outputs=[lang_state, out_df, out_mean_df, overview_md, btn_lang_fo, btn_lang_en],
|
| 568 |
queue=False,
|
| 569 |
)
|
| 570 |
|