Spaces:
Sleeping
Sleeping
annotation app code-9475426df1e7+git-b0c0495-dirty
Browse files
app.py
CHANGED
|
@@ -40,11 +40,9 @@ CSS = """
|
|
| 40 |
.ann-card-source .ann-text { max-height: 45vh; }
|
| 41 |
.ann-vertical { gap: 2rem !important; } /* clear space between stacked cards */
|
| 42 |
.ann-vertical .ann-card:not(.ann-card-source) .ann-text { max-height: none; } /* stacked texts grow to full length */
|
| 43 |
-
/* the questions
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
#overgen [data-testid="block-info"] { font-size: 1.25rem !important; font-weight: 700 !important;
|
| 47 |
-
color: var(--body-text-color) !important; line-height: 1.4; }
|
| 48 |
/* instructions panel: its own tinted background and a coloured header bar, so it stands apart from the task */
|
| 49 |
#guide { background: #eef4fb !important; border: 2px solid #2f6db5 !important; border-radius: 10px !important; }
|
| 50 |
#guide > button.label-wrap { background: #2f6db5; color: #fff; font-weight: 700; font-size: 1.05rem;
|
|
@@ -89,6 +87,11 @@ def _card(title: str, text: str, source: bool = False) -> str:
|
|
| 89 |
f'<div class="ann-text">{body}</div></div>')
|
| 90 |
|
| 91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
def _err(msg: str | None) -> str:
|
| 93 |
return f'<div class="ann-error">{html.escape(msg)}</div>' if msg else ""
|
| 94 |
|
|
@@ -177,10 +180,15 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 177 |
for L in C.LETTERS:
|
| 178 |
with gr.Column():
|
| 179 |
s1_texts.append(gr.HTML("", elem_id=f"s1_text_{L}"))
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
s1_err = gr.HTML("", elem_id="s1_err")
|
| 185 |
s1_btn = gr.Button("Submit and go to the next document" if task == "simplicity" else
|
| 186 |
"Submit and continue (answers cannot be changed afterwards)", variant="primary",
|
|
@@ -196,9 +204,15 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 196 |
for L in C.LETTERS:
|
| 197 |
with gr.Column():
|
| 198 |
s2_texts.append(gr.HTML("", elem_id=f"s2_text_{L}"))
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
gr.Markdown("There may well be no error: leave a question unticked if none of the texts applies.")
|
| 203 |
s2_err = gr.HTML("", elem_id="s2_err")
|
| 204 |
s2_btn = gr.Button("Submit and go to the next document", variant="primary", elem_id="s2_btn")
|
|
@@ -212,7 +226,7 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 212 |
|
| 213 |
groups = {"start": g_start, "consent": g_consent, "s1": g_s1, "s2": g_s2, "done": g_done}
|
| 214 |
ALL = [state, *groups.values(), start_err, consent_err, s1_progress, *s1_texts, easiest, hardest, gap_bm,
|
| 215 |
-
gap_mw, s1_err, s2_progress, s2_source, *s2_texts, omits, contradicts, overgen, s2_err, done_md]
|
| 216 |
|
| 217 |
def show(screen: str) -> dict:
|
| 218 |
return {g: gr.update(visible=(k == screen)) for k, g in groups.items()}
|
|
@@ -237,7 +251,8 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 237 |
s2_source: _card("Source", view["source"], source=True),
|
| 238 |
**{t: _card(f"Text {L}", view["texts"][L]) for t, L in zip(s2_texts, C.LETTERS)},
|
| 239 |
omits: gr.update(value=[]), contradicts: gr.update(value=[]),
|
| 240 |
-
overgen: gr.update(value=[], visible=st["cohort"] == "expert")
|
|
|
|
| 241 |
|
| 242 |
def save(st, s2_answers, err_box, submitted_key) -> dict:
|
| 243 |
"""Write this document's line, push it, and move on (or show the error on the current screen)."""
|
|
@@ -268,7 +283,8 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 268 |
return {**out, **show("s1"), state: st, s1_progress: progress(st),
|
| 269 |
**{t: _card(f"Text {L}", view["texts"][L]) for t, L in zip(s1_texts, C.LETTERS)},
|
| 270 |
easiest: gr.update(value=None), hardest: gr.update(value=None),
|
| 271 |
-
gap_bm: gr.update(value=None, visible=False), gap_mw: gr.update(value=None, visible=False)
|
|
|
|
| 272 |
|
| 273 |
def pull(norm):
|
| 274 |
if on_login:
|
|
@@ -330,14 +346,17 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 330 |
|
| 331 |
def on_rank(e, h):
|
| 332 |
"""Show the two gap questions, naming the actual letters, once easiest and hardest are set."""
|
| 333 |
-
hide = {gap_bm: gr.update(value=None, visible=False), gap_mw: gr.update(value=None, visible=False)
|
|
|
|
| 334 |
if e not in C.LETTERS or h not in C.LETTERS:
|
| 335 |
return {**hide, s1_err: ""}
|
| 336 |
if e == h:
|
| 337 |
return {**hide, s1_err: _err("The easiest and the hardest text must be different.")}
|
| 338 |
m = C.middle_of(e, h)
|
| 339 |
return {gap_bm: gr.update(label=C.gap_question(e, m), value=None, visible=True),
|
| 340 |
-
gap_mw: gr.update(label=C.gap_question(m, h), value=None, visible=True),
|
|
|
|
|
|
|
| 341 |
|
| 342 |
def on_s1(e, h, g1, g2, st):
|
| 343 |
if not st or st["screen"] != "s1":
|
|
@@ -359,8 +378,8 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 359 |
code_btn.click(on_code, [code_in, key_in, state], ALL, **EVENT)
|
| 360 |
new_btn.click(on_new, [code_in, key_in, state], ALL, **EVENT)
|
| 361 |
consent_btn.click(on_consent, [consent_cb, state], ALL, **EVENT)
|
| 362 |
-
easiest.change(on_rank, [easiest, hardest], [gap_bm, gap_mw, s1_err], **EVENT)
|
| 363 |
-
hardest.change(on_rank, [easiest, hardest], [gap_bm, gap_mw, s1_err], **EVENT)
|
| 364 |
s1_btn.click(on_s1, [easiest, hardest, gap_bm, gap_mw, state], ALL, **EVENT)
|
| 365 |
s2_btn.click(on_s2, [omits, contradicts, overgen, state], ALL, **EVENT)
|
| 366 |
# On a Space, gradio's page adds a Hugging Face header (Space name, owner avatar, likes) that also loads Google
|
|
|
|
| 40 |
.ann-card-source .ann-text { max-height: 45vh; }
|
| 41 |
.ann-vertical { gap: 2rem !important; } /* clear space between stacked cards */
|
| 42 |
.ann-vertical .ann-card:not(.ann-card-source) .ann-text { max-height: none; } /* stacked texts grow to full length */
|
| 43 |
+
/* the questions: large, normal weight, only the key words bold (written in Markdown) */
|
| 44 |
+
.ann-qtext p { font-size: 1.25rem !important; font-weight: 400 !important; line-height: 1.45; margin: 0.9rem 0 0.2rem; }
|
| 45 |
+
.ann-qtext strong { font-weight: 700; }
|
|
|
|
|
|
|
| 46 |
/* instructions panel: its own tinted background and a coloured header bar, so it stands apart from the task */
|
| 47 |
#guide { background: #eef4fb !important; border: 2px solid #2f6db5 !important; border-radius: 10px !important; }
|
| 48 |
#guide > button.label-wrap { background: #2f6db5; color: #fff; font-weight: 700; font-size: 1.05rem;
|
|
|
|
| 87 |
f'<div class="ann-text">{body}</div></div>')
|
| 88 |
|
| 89 |
|
| 90 |
+
def qmd(text: str, eid: str, visible: bool = True):
|
| 91 |
+
"""A question line: normal weight, large, with only its key words in bold (Markdown)."""
|
| 92 |
+
return gr.Markdown(text, elem_id=eid, elem_classes=["ann-qtext"], visible=visible)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
def _err(msg: str | None) -> str:
|
| 96 |
return f'<div class="ann-error">{html.escape(msg)}</div>' if msg else ""
|
| 97 |
|
|
|
|
| 180 |
for L in C.LETTERS:
|
| 181 |
with gr.Column():
|
| 182 |
s1_texts.append(gr.HTML("", elem_id=f"s1_text_{L}"))
|
| 183 |
+
# each question is a Markdown line (only its key words in bold) above an unlabeled answer component
|
| 184 |
+
qmd("Which of these did you find **easiest to follow**?", "q_easiest")
|
| 185 |
+
easiest = gr.Radio(list(C.LETTERS), label=C.Q_EASIEST, show_label=False, value=None, elem_id="easiest")
|
| 186 |
+
qmd("Which did you find **hardest to follow**?", "q_hardest")
|
| 187 |
+
hardest = gr.Radio(list(C.LETTERS), label=C.Q_HARDEST, show_label=False, value=None, elem_id="hardest")
|
| 188 |
+
gap_bm_q = qmd("", "q_gap_bm", visible=False)
|
| 189 |
+
gap_bm = gr.Radio(list(C.GAPS), label="", show_label=False, value=None, visible=False, elem_id="gap_bm")
|
| 190 |
+
gap_mw_q = qmd("", "q_gap_mw", visible=False)
|
| 191 |
+
gap_mw = gr.Radio(list(C.GAPS), label="", show_label=False, value=None, visible=False, elem_id="gap_mw")
|
| 192 |
s1_err = gr.HTML("", elem_id="s1_err")
|
| 193 |
s1_btn = gr.Button("Submit and go to the next document" if task == "simplicity" else
|
| 194 |
"Submit and continue (answers cannot be changed afterwards)", variant="primary",
|
|
|
|
| 204 |
for L in C.LETTERS:
|
| 205 |
with gr.Column():
|
| 206 |
s2_texts.append(gr.HTML("", elem_id=f"s2_text_{L}"))
|
| 207 |
+
qmd("Does the simplification **leave out important information** from the source?", "q_omits")
|
| 208 |
+
omits = gr.CheckboxGroup(list(C.LETTERS), label=C.Q_OMITS, show_label=False, value=[], elem_id="omits")
|
| 209 |
+
qmd("Does the simplification **contradict the source**?", "q_contradicts")
|
| 210 |
+
contradicts = gr.CheckboxGroup(list(C.LETTERS), label=C.Q_CONTRADICTS, show_label=False, value=[],
|
| 211 |
+
elem_id="contradicts")
|
| 212 |
+
overgen_q = qmd("Does the simplification **state a finding more broadly than the source supports**? For "
|
| 213 |
+
"example dropping who it applies to, or under what conditions.", "q_overgen", visible=False)
|
| 214 |
+
overgen = gr.CheckboxGroup(list(C.LETTERS), label=C.Q_OVERGENERALISES, show_label=False, value=[],
|
| 215 |
+
visible=False, elem_id="overgen")
|
| 216 |
gr.Markdown("There may well be no error: leave a question unticked if none of the texts applies.")
|
| 217 |
s2_err = gr.HTML("", elem_id="s2_err")
|
| 218 |
s2_btn = gr.Button("Submit and go to the next document", variant="primary", elem_id="s2_btn")
|
|
|
|
| 226 |
|
| 227 |
groups = {"start": g_start, "consent": g_consent, "s1": g_s1, "s2": g_s2, "done": g_done}
|
| 228 |
ALL = [state, *groups.values(), start_err, consent_err, s1_progress, *s1_texts, easiest, hardest, gap_bm,
|
| 229 |
+
gap_mw, gap_bm_q, gap_mw_q, overgen_q, s1_err, s2_progress, s2_source, *s2_texts, omits, contradicts, overgen, s2_err, done_md]
|
| 230 |
|
| 231 |
def show(screen: str) -> dict:
|
| 232 |
return {g: gr.update(visible=(k == screen)) for k, g in groups.items()}
|
|
|
|
| 251 |
s2_source: _card("Source", view["source"], source=True),
|
| 252 |
**{t: _card(f"Text {L}", view["texts"][L]) for t, L in zip(s2_texts, C.LETTERS)},
|
| 253 |
omits: gr.update(value=[]), contradicts: gr.update(value=[]),
|
| 254 |
+
overgen: gr.update(value=[], visible=st["cohort"] == "expert"),
|
| 255 |
+
overgen_q: gr.update(visible=st["cohort"] == "expert")}
|
| 256 |
|
| 257 |
def save(st, s2_answers, err_box, submitted_key) -> dict:
|
| 258 |
"""Write this document's line, push it, and move on (or show the error on the current screen)."""
|
|
|
|
| 283 |
return {**out, **show("s1"), state: st, s1_progress: progress(st),
|
| 284 |
**{t: _card(f"Text {L}", view["texts"][L]) for t, L in zip(s1_texts, C.LETTERS)},
|
| 285 |
easiest: gr.update(value=None), hardest: gr.update(value=None),
|
| 286 |
+
gap_bm: gr.update(value=None, visible=False), gap_mw: gr.update(value=None, visible=False),
|
| 287 |
+
gap_bm_q: gr.update(visible=False), gap_mw_q: gr.update(visible=False)}
|
| 288 |
|
| 289 |
def pull(norm):
|
| 290 |
if on_login:
|
|
|
|
| 346 |
|
| 347 |
def on_rank(e, h):
|
| 348 |
"""Show the two gap questions, naming the actual letters, once easiest and hardest are set."""
|
| 349 |
+
hide = {gap_bm: gr.update(value=None, visible=False), gap_mw: gr.update(value=None, visible=False),
|
| 350 |
+
gap_bm_q: gr.update(visible=False), gap_mw_q: gr.update(visible=False)}
|
| 351 |
if e not in C.LETTERS or h not in C.LETTERS:
|
| 352 |
return {**hide, s1_err: ""}
|
| 353 |
if e == h:
|
| 354 |
return {**hide, s1_err: _err("The easiest and the hardest text must be different.")}
|
| 355 |
m = C.middle_of(e, h)
|
| 356 |
return {gap_bm: gr.update(label=C.gap_question(e, m), value=None, visible=True),
|
| 357 |
+
gap_mw: gr.update(label=C.gap_question(m, h), value=None, visible=True),
|
| 358 |
+
gap_bm_q: gr.update(value=f"**How much easier** is {e} than {m}?", visible=True),
|
| 359 |
+
gap_mw_q: gr.update(value=f"**How much easier** is {m} than {h}?", visible=True), s1_err: ""}
|
| 360 |
|
| 361 |
def on_s1(e, h, g1, g2, st):
|
| 362 |
if not st or st["screen"] != "s1":
|
|
|
|
| 378 |
code_btn.click(on_code, [code_in, key_in, state], ALL, **EVENT)
|
| 379 |
new_btn.click(on_new, [code_in, key_in, state], ALL, **EVENT)
|
| 380 |
consent_btn.click(on_consent, [consent_cb, state], ALL, **EVENT)
|
| 381 |
+
easiest.change(on_rank, [easiest, hardest], [gap_bm, gap_mw, gap_bm_q, gap_mw_q, s1_err], **EVENT)
|
| 382 |
+
hardest.change(on_rank, [easiest, hardest], [gap_bm, gap_mw, gap_bm_q, gap_mw_q, s1_err], **EVENT)
|
| 383 |
s1_btn.click(on_s1, [easiest, hardest, gap_bm, gap_mw, state], ALL, **EVENT)
|
| 384 |
s2_btn.click(on_s2, [omits, contradicts, overgen, state], ALL, **EVENT)
|
| 385 |
# On a Space, gradio's page adds a Hugging Face header (Space name, owner avatar, likes) that also loads Google
|