Upload app.py
Browse files
app.py
CHANGED
|
@@ -46,16 +46,39 @@ CSS = """
|
|
| 46 |
:root{
|
| 47 |
--primary-500:#89AFA9; --primary-600:#6F9992; --primary-700:#5B7F79;
|
| 48 |
--primary-100:#E1ECEA; --primary-200:#C6DAD6;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
}
|
| 50 |
body, .gradio-container, .prose, .markdown, textarea, input, select, button, table{
|
| 51 |
font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, "Noto Sans", sans-serif !important;
|
| 52 |
}
|
|
|
|
|
|
|
| 53 |
.gr-button-primary, button.primary, .primary{
|
| 54 |
-
background:var(--primary-500)!important;
|
|
|
|
|
|
|
| 55 |
}
|
| 56 |
.gr-button-primary:hover, button.primary:hover, .primary:hover{ background:var(--primary-600)!important; }
|
| 57 |
a{ color:var(--primary-700)!important; }
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
/* Dataframe column wrapping: keep Orð + Mark on one line */
|
| 60 |
.gr-dataframe table td:nth-child(1),
|
| 61 |
.gr-dataframe table th:nth-child(1){
|
|
@@ -74,7 +97,7 @@ a{ color:var(--primary-700)!important; }
|
|
| 74 |
width: 64% !important;
|
| 75 |
}
|
| 76 |
|
| 77 |
-
/* Results header:
|
| 78 |
#results_hdr{
|
| 79 |
display:flex;
|
| 80 |
align-items:center;
|
|
@@ -83,18 +106,22 @@ a{ color:var(--primary-700)!important; }
|
|
| 83 |
padding: 0;
|
| 84 |
background: transparent !important;
|
| 85 |
}
|
| 86 |
-
#results_hdr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
background: transparent !important;
|
| 88 |
-
padding: 0 !important;
|
| 89 |
-
margin: 0 !important;
|
| 90 |
box-shadow: none !important;
|
| 91 |
border: 0 !important;
|
| 92 |
}
|
| 93 |
|
| 94 |
-
/* Language toggle
|
| 95 |
.lang_toggle{
|
| 96 |
display:flex;
|
| 97 |
-
gap: 8px;
|
| 98 |
justify-content:flex-end;
|
| 99 |
align-items:center;
|
| 100 |
}
|
|
@@ -102,31 +129,43 @@ a{ color:var(--primary-700)!important; }
|
|
| 102 |
border: 0 !important;
|
| 103 |
padding: 0 !important;
|
| 104 |
margin: 0 !important;
|
|
|
|
| 105 |
}
|
| 106 |
.lang_toggle .wrap{
|
| 107 |
display:flex !important;
|
| 108 |
-
gap:
|
|
|
|
| 109 |
}
|
| 110 |
.lang_toggle input{
|
| 111 |
-
display:none !important; /*
|
| 112 |
}
|
| 113 |
.lang_toggle label{
|
| 114 |
cursor:pointer;
|
| 115 |
-
padding:
|
| 116 |
-
border-radius:
|
| 117 |
-
border: 1px solid rgba(0,0,0,.
|
| 118 |
-
background:
|
| 119 |
user-select:none;
|
| 120 |
-
font-size: 0.
|
|
|
|
| 121 |
}
|
| 122 |
-
.lang_toggle
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
}
|
| 127 |
|
| 128 |
/* Slightly smaller primary button */
|
| 129 |
.gr-button-primary{ padding: 0.35rem 0.85rem !important; font-size: 0.95rem !important; }
|
|
|
|
|
|
|
|
|
|
| 130 |
"""
|
| 131 |
|
| 132 |
# ----------------------------
|
|
@@ -271,9 +310,8 @@ def group_code(vec: torch.Tensor, group: str) -> str:
|
|
| 271 |
# Display rules
|
| 272 |
# ----------------------------
|
| 273 |
HIDE_IN_ANALYSIS = {
|
| 274 |
-
|
| 275 |
-
("D", "subcategory", "
|
| 276 |
-
("D", "subcategory", "N"),
|
| 277 |
}
|
| 278 |
|
| 279 |
VOICE_ANALYSIS = {
|
|
@@ -500,25 +538,25 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 500 |
lines=6,
|
| 501 |
placeholder="Skriva her ... / Type here ...",
|
| 502 |
show_label=False,
|
|
|
|
| 503 |
)
|
| 504 |
-
with gr.Column(scale=1, min_width=320):
|
| 505 |
gr.Markdown(
|
| 506 |
-
"##
|
| 507 |
-
"Skriv
|
| 508 |
-
f"
|
| 509 |
)
|
| 510 |
btn = gr.Button("Marka / Tag", variant="primary")
|
| 511 |
|
| 512 |
state = gr.State([])
|
| 513 |
|
| 514 |
-
# Results header row (hidden until
|
| 515 |
with gr.Row(elem_id="results_hdr"):
|
| 516 |
-
|
| 517 |
lang = gr.Radio(
|
| 518 |
choices=[("Føroyskt","fo"), ("English","en")],
|
| 519 |
value="fo",
|
| 520 |
show_label=False,
|
| 521 |
-
visible=False,
|
| 522 |
elem_classes=["lang_toggle"],
|
| 523 |
)
|
| 524 |
|
|
@@ -532,6 +570,7 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 532 |
visible=False,
|
| 533 |
)
|
| 534 |
|
|
|
|
| 535 |
expanded_acc = gr.Accordion("Útgreinað marking / Expanded tags", open=False, visible=False)
|
| 536 |
with expanded_acc:
|
| 537 |
out_mean_df = gr.Dataframe(
|
|
@@ -543,9 +582,10 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 543 |
col_count=(3, "fixed"),
|
| 544 |
)
|
| 545 |
|
| 546 |
-
|
|
|
|
| 547 |
with overview_acc:
|
| 548 |
-
overview_md = gr.Markdown("")
|
| 549 |
|
| 550 |
def on_tag(sentence, lang_choice):
|
| 551 |
rows = run_model(sentence)
|
|
@@ -555,10 +595,7 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 555 |
gr.update(value=df_main, visible=True),
|
| 556 |
gr.update(value=df_mean),
|
| 557 |
gr.update(value=overview),
|
| 558 |
-
gr.update(visible=True), # results_title
|
| 559 |
-
gr.update(visible=True), # lang
|
| 560 |
gr.update(visible=True), # expanded_acc
|
| 561 |
-
gr.update(visible=True), # overview_acc
|
| 562 |
)
|
| 563 |
|
| 564 |
def on_lang(rows, lang_choice):
|
|
@@ -572,7 +609,7 @@ with gr.Blocks(theme=theme, css=CSS, title="Marka") as demo:
|
|
| 572 |
btn.click(
|
| 573 |
on_tag,
|
| 574 |
inputs=[inp, lang],
|
| 575 |
-
outputs=[state, out_df, out_mean_df, overview_md,
|
| 576 |
queue=False,
|
| 577 |
)
|
| 578 |
|
|
|
|
| 46 |
:root{
|
| 47 |
--primary-500:#89AFA9; --primary-600:#6F9992; --primary-700:#5B7F79;
|
| 48 |
--primary-100:#E1ECEA; --primary-200:#C6DAD6;
|
| 49 |
+
--page-bg: #f7f7f8;
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
/* Force a consistent page background (and remove white "cards" where possible) */
|
| 53 |
+
html, body{
|
| 54 |
+
background: var(--page-bg) !important;
|
| 55 |
+
}
|
| 56 |
+
.gradio-container{
|
| 57 |
+
background: var(--page-bg) !important;
|
| 58 |
}
|
| 59 |
body, .gradio-container, .prose, .markdown, textarea, input, select, button, table{
|
| 60 |
font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, "Noto Sans", sans-serif !important;
|
| 61 |
}
|
| 62 |
+
|
| 63 |
+
/* Primary button */
|
| 64 |
.gr-button-primary, button.primary, .primary{
|
| 65 |
+
background:var(--primary-500)!important;
|
| 66 |
+
border-color:var(--primary-600)!important;
|
| 67 |
+
color:#0b1b19!important;
|
| 68 |
}
|
| 69 |
.gr-button-primary:hover, button.primary:hover, .primary:hover{ background:var(--primary-600)!important; }
|
| 70 |
a{ color:var(--primary-700)!important; }
|
| 71 |
|
| 72 |
+
/* Remove "card" background around textbox wrapper; keep textarea readable */
|
| 73 |
+
#input_box, #input_box > div, #input_box .wrap, #input_box .container{
|
| 74 |
+
background: transparent !important;
|
| 75 |
+
box-shadow: none !important;
|
| 76 |
+
border: 0 !important;
|
| 77 |
+
}
|
| 78 |
+
#input_box textarea{
|
| 79 |
+
background: #ffffff !important;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
/* Dataframe column wrapping: keep Orð + Mark on one line */
|
| 83 |
.gr-dataframe table td:nth-child(1),
|
| 84 |
.gr-dataframe table th:nth-child(1){
|
|
|
|
| 97 |
width: 64% !important;
|
| 98 |
}
|
| 99 |
|
| 100 |
+
/* Results header: clean left-title / right-language bar (no white container blocks) */
|
| 101 |
#results_hdr{
|
| 102 |
display:flex;
|
| 103 |
align-items:center;
|
|
|
|
| 106 |
padding: 0;
|
| 107 |
background: transparent !important;
|
| 108 |
}
|
| 109 |
+
#results_hdr *{
|
| 110 |
+
background: transparent !important;
|
| 111 |
+
}
|
| 112 |
+
#results_hdr .gr-block,
|
| 113 |
+
#results_hdr .gr-form,
|
| 114 |
+
#results_hdr .gr-box,
|
| 115 |
+
#results_hdr .gr-panel,
|
| 116 |
+
#results_hdr .gr-group{
|
| 117 |
background: transparent !important;
|
|
|
|
|
|
|
| 118 |
box-shadow: none !important;
|
| 119 |
border: 0 !important;
|
| 120 |
}
|
| 121 |
|
| 122 |
+
/* Language toggle: segmented buttons, selected matches primary button */
|
| 123 |
.lang_toggle{
|
| 124 |
display:flex;
|
|
|
|
| 125 |
justify-content:flex-end;
|
| 126 |
align-items:center;
|
| 127 |
}
|
|
|
|
| 129 |
border: 0 !important;
|
| 130 |
padding: 0 !important;
|
| 131 |
margin: 0 !important;
|
| 132 |
+
background: transparent !important;
|
| 133 |
}
|
| 134 |
.lang_toggle .wrap{
|
| 135 |
display:flex !important;
|
| 136 |
+
gap: 10px !important;
|
| 137 |
+
background: transparent !important;
|
| 138 |
}
|
| 139 |
.lang_toggle input{
|
| 140 |
+
display:none !important; /* no cursor ever */
|
| 141 |
}
|
| 142 |
.lang_toggle label{
|
| 143 |
cursor:pointer;
|
| 144 |
+
padding: 9px 14px;
|
| 145 |
+
border-radius: 12px;
|
| 146 |
+
border: 1px solid rgba(0,0,0,.14);
|
| 147 |
+
background: transparent !important; /* match page background */
|
| 148 |
user-select:none;
|
| 149 |
+
font-size: 0.98rem;
|
| 150 |
+
box-shadow: none !important;
|
| 151 |
}
|
| 152 |
+
.lang_toggle label:hover{
|
| 153 |
+
border-color: rgba(0,0,0,.22);
|
| 154 |
+
}
|
| 155 |
+
.lang_toggle input:checked + span{
|
| 156 |
+
background: var(--primary-500) !important;
|
| 157 |
+
color:#0b1b19 !important;
|
| 158 |
+
border-radius: 12px;
|
| 159 |
+
padding: 9px 14px;
|
| 160 |
+
border: 1px solid var(--primary-600) !important;
|
| 161 |
+
display:inline-block;
|
| 162 |
}
|
| 163 |
|
| 164 |
/* Slightly smaller primary button */
|
| 165 |
.gr-button-primary{ padding: 0.35rem 0.85rem !important; font-size: 0.95rem !important; }
|
| 166 |
+
|
| 167 |
+
/* Make the right-side title "Marka" slightly bigger */
|
| 168 |
+
#info_panel h2{ margin-top: 0.2rem; }
|
| 169 |
"""
|
| 170 |
|
| 171 |
# ----------------------------
|
|
|
|
| 310 |
# Display rules
|
| 311 |
# ----------------------------
|
| 312 |
HIDE_IN_ANALYSIS = {
|
| 313 |
+
("D", "subcategory", "G"), # stýrir falli
|
| 314 |
+
("D", "subcategory", "N"), # stýrir ikki falli
|
|
|
|
| 315 |
}
|
| 316 |
|
| 317 |
VOICE_ANALYSIS = {
|
|
|
|
| 538 |
lines=6,
|
| 539 |
placeholder="Skriva her ... / Type here ...",
|
| 540 |
show_label=False,
|
| 541 |
+
elem_id="input_box",
|
| 542 |
)
|
| 543 |
+
with gr.Column(scale=1, min_width=320, elem_id="info_panel"):
|
| 544 |
gr.Markdown(
|
| 545 |
+
"## Marka\n"
|
| 546 |
+
"Skriv ein setning í kassan og fá hann markaðan.\n\n"
|
| 547 |
+
f"Myndil / Model: [{MODEL_ID}]({MODEL_LINK})"
|
| 548 |
)
|
| 549 |
btn = gr.Button("Marka / Tag", variant="primary")
|
| 550 |
|
| 551 |
state = gr.State([])
|
| 552 |
|
| 553 |
+
# Results header row (always visible; table stays hidden until Tag)
|
| 554 |
with gr.Row(elem_id="results_hdr"):
|
| 555 |
+
gr.Markdown("### Úrslit / Results")
|
| 556 |
lang = gr.Radio(
|
| 557 |
choices=[("Føroyskt","fo"), ("English","en")],
|
| 558 |
value="fo",
|
| 559 |
show_label=False,
|
|
|
|
| 560 |
elem_classes=["lang_toggle"],
|
| 561 |
)
|
| 562 |
|
|
|
|
| 570 |
visible=False,
|
| 571 |
)
|
| 572 |
|
| 573 |
+
# Expanded tags: hidden until tagged
|
| 574 |
expanded_acc = gr.Accordion("Útgreinað marking / Expanded tags", open=False, visible=False)
|
| 575 |
with expanded_acc:
|
| 576 |
out_mean_df = gr.Dataframe(
|
|
|
|
| 582 |
col_count=(3, "fixed"),
|
| 583 |
)
|
| 584 |
|
| 585 |
+
# Markayvirlit: always visible
|
| 586 |
+
overview_acc = gr.Accordion("Markayvirlit / Tag Overview", open=False, visible=True)
|
| 587 |
with overview_acc:
|
| 588 |
+
overview_md = gr.Markdown(build_overview("fo"))
|
| 589 |
|
| 590 |
def on_tag(sentence, lang_choice):
|
| 591 |
rows = run_model(sentence)
|
|
|
|
| 595 |
gr.update(value=df_main, visible=True),
|
| 596 |
gr.update(value=df_mean),
|
| 597 |
gr.update(value=overview),
|
|
|
|
|
|
|
| 598 |
gr.update(visible=True), # expanded_acc
|
|
|
|
| 599 |
)
|
| 600 |
|
| 601 |
def on_lang(rows, lang_choice):
|
|
|
|
| 609 |
btn.click(
|
| 610 |
on_tag,
|
| 611 |
inputs=[inp, lang],
|
| 612 |
+
outputs=[state, out_df, out_mean_df, overview_md, expanded_acc],
|
| 613 |
queue=False,
|
| 614 |
)
|
| 615 |
|