Spaces:
Running
Running
annotation app code-e4402cff9d5a+git-18562b5-dirty
Browse files
app.py
CHANGED
|
@@ -40,6 +40,12 @@ 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: 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; }
|
|
@@ -87,6 +93,12 @@ def _card(title: str, text: str, source: bool = False) -> str:
|
|
| 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)
|
|
@@ -157,9 +169,10 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 157 |
if task != "both":
|
| 158 |
gr.Markdown("Please read **Instructions and example** above before you start; you can open it again "
|
| 159 |
"at any time, on every page.")
|
| 160 |
-
gr.
|
| 161 |
-
|
| 162 |
-
|
|
|
|
| 163 |
code_in = gr.Textbox(label="Your ID", placeholder="3 to 30 letters, digits, - or _", elem_id="code_in")
|
| 164 |
with gr.Row():
|
| 165 |
new_btn = gr.Button("I'm new: start with this ID", variant="primary", elem_id="new_btn")
|
|
@@ -167,6 +180,9 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 167 |
start_err = gr.HTML("", elem_id="start_err")
|
| 168 |
|
| 169 |
with gr.Group(visible=False) as g_consent:
|
|
|
|
|
|
|
|
|
|
| 170 |
gr.Markdown(study.get(f"consent_markdown_{task}") or study["consent_markdown"]) # per-Space text
|
| 171 |
consent_cb = gr.Checkbox(label="I have read the above and agree to take part.", value=False, elem_id="consent_cb")
|
| 172 |
consent_btn = gr.Button("Continue", variant="primary", elem_id="consent_btn")
|
|
@@ -226,7 +242,7 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 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()}
|
|
@@ -304,7 +320,8 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 304 |
if C.registration(out_dir, norm, config) is None:
|
| 305 |
return {start_err: _err(f"No participant with the ID “{norm}”. Check it, or start as new.")}
|
| 306 |
st = C.new_session(norm, config, docs, out_dir, split)
|
| 307 |
-
return {**show("consent"), state: st, start_err: "", consent_err: ""
|
|
|
|
| 308 |
|
| 309 |
def on_new(code, key, st):
|
| 310 |
"""A new participant: sign the ID up (cohort from the key, next order in rotation)."""
|
|
@@ -334,11 +351,15 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 334 |
if on_saved:
|
| 335 |
on_saved(norm)
|
| 336 |
st = C.new_session(norm, config, docs, out_dir, split)
|
| 337 |
-
return {**show("consent"), state: st, start_err: "", consent_err: ""
|
|
|
|
| 338 |
|
| 339 |
-
def on_consent(agreed, st):
|
| 340 |
if not st or st["screen"] != "consent":
|
| 341 |
return {}
|
|
|
|
|
|
|
|
|
|
| 342 |
if not agreed:
|
| 343 |
return {consent_err: _err("Please tick the box to continue.")}
|
| 344 |
st["consent_at"] = C.now_iso()
|
|
@@ -377,7 +398,7 @@ def build_demo(docs, config, out_dir: str | Path, meta: dict, layout: str = "hor
|
|
| 377 |
|
| 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)
|
|
|
|
| 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 participant's ID: hard to miss */
|
| 44 |
+
.ann-idwarn { background: #fff7e0; border: 2px solid #e0a800; border-radius: 8px; padding: 0.7rem 1rem; line-height: 1.6; }
|
| 45 |
+
.ann-idbox { background: #fff7e0; border: 2px solid #e0a800; border-radius: 10px; padding: 1rem 1.2rem;
|
| 46 |
+
font-size: 1.1rem; line-height: 1.6; margin-bottom: 0.5rem; }
|
| 47 |
+
.ann-id { font-family: ui-monospace, monospace; font-size: 1.6rem; font-weight: 700; padding: 0.1rem 0.5rem;
|
| 48 |
+
background: #fff; border: 1px dashed #b38600; border-radius: 6px; margin-left: 0.3rem; }
|
| 49 |
/* the questions: large, normal weight, only the key words bold (written in Markdown) */
|
| 50 |
.ann-qtext p { font-size: 1.25rem !important; font-weight: 400 !important; line-height: 1.45; margin: 0.9rem 0 0.2rem; }
|
| 51 |
.ann-qtext strong { font-weight: 700; }
|
|
|
|
| 93 |
f'<div class="ann-text">{body}</div></div>')
|
| 94 |
|
| 95 |
|
| 96 |
+
def _id_box(code: str) -> str:
|
| 97 |
+
return ('<div class="ann-idbox">Your ID is <span class="ann-id">' + html.escape(code) + '</span>'
|
| 98 |
+
'<div>Write it down or take a screenshot <b>now</b>. You need it to come back to where you stopped, '
|
| 99 |
+
'and nobody can recover it for you.</div></div>')
|
| 100 |
+
|
| 101 |
+
|
| 102 |
def qmd(text: str, eid: str, visible: bool = True):
|
| 103 |
"""A question line: normal weight, large, with only its key words in bold (Markdown)."""
|
| 104 |
return gr.Markdown(text, elem_id=eid, elem_classes=["ann-qtext"], visible=visible)
|
|
|
|
| 169 |
if task != "both":
|
| 170 |
gr.Markdown("Please read **Instructions and example** above before you start; you can open it again "
|
| 171 |
"at any time, on every page.")
|
| 172 |
+
gr.HTML('<div class="ann-idwarn"><b>First time?</b> Choose an ID (not your name). '
|
| 173 |
+
'<b>Write it down now, somewhere you will find it again</b> (on paper, in your phone, in a note): '
|
| 174 |
+
'it is the <b>only</b> way to come back to where you stopped. We cannot look it up or reset it '
|
| 175 |
+
'for you.<br><b>Coming back?</b> Enter the ID you chose last time.</div>')
|
| 176 |
code_in = gr.Textbox(label="Your ID", placeholder="3 to 30 letters, digits, - or _", elem_id="code_in")
|
| 177 |
with gr.Row():
|
| 178 |
new_btn = gr.Button("I'm new: start with this ID", variant="primary", elem_id="new_btn")
|
|
|
|
| 180 |
start_err = gr.HTML("", elem_id="start_err")
|
| 181 |
|
| 182 |
with gr.Group(visible=False) as g_consent:
|
| 183 |
+
id_box = gr.HTML("", elem_id="id_box") # the participant's ID, shown big, before anything else
|
| 184 |
+
id_saved_cb = gr.Checkbox(label="I have saved my ID somewhere I will find it again.", value=False,
|
| 185 |
+
elem_id="id_saved_cb")
|
| 186 |
gr.Markdown(study.get(f"consent_markdown_{task}") or study["consent_markdown"]) # per-Space text
|
| 187 |
consent_cb = gr.Checkbox(label="I have read the above and agree to take part.", value=False, elem_id="consent_cb")
|
| 188 |
consent_btn = gr.Button("Continue", variant="primary", elem_id="consent_btn")
|
|
|
|
| 242 |
|
| 243 |
groups = {"start": g_start, "consent": g_consent, "s1": g_s1, "s2": g_s2, "done": g_done}
|
| 244 |
ALL = [state, *groups.values(), start_err, consent_err, s1_progress, *s1_texts, easiest, hardest, gap_bm,
|
| 245 |
+
gap_mw, gap_bm_q, gap_mw_q, overgen_q, id_box, id_saved_cb, s1_err, s2_progress, s2_source, *s2_texts, omits, contradicts, overgen, s2_err, done_md]
|
| 246 |
|
| 247 |
def show(screen: str) -> dict:
|
| 248 |
return {g: gr.update(visible=(k == screen)) for k, g in groups.items()}
|
|
|
|
| 320 |
if C.registration(out_dir, norm, config) is None:
|
| 321 |
return {start_err: _err(f"No participant with the ID “{norm}”. Check it, or start as new.")}
|
| 322 |
st = C.new_session(norm, config, docs, out_dir, split)
|
| 323 |
+
return {**show("consent"), state: st, start_err: "", consent_err: "", id_box: _id_box(norm),
|
| 324 |
+
id_saved_cb: gr.update(value=False)}
|
| 325 |
|
| 326 |
def on_new(code, key, st):
|
| 327 |
"""A new participant: sign the ID up (cohort from the key, next order in rotation)."""
|
|
|
|
| 351 |
if on_saved:
|
| 352 |
on_saved(norm)
|
| 353 |
st = C.new_session(norm, config, docs, out_dir, split)
|
| 354 |
+
return {**show("consent"), state: st, start_err: "", consent_err: "", id_box: _id_box(norm),
|
| 355 |
+
id_saved_cb: gr.update(value=False)}
|
| 356 |
|
| 357 |
+
def on_consent(agreed, saved, st):
|
| 358 |
if not st or st["screen"] != "consent":
|
| 359 |
return {}
|
| 360 |
+
if not saved:
|
| 361 |
+
return {consent_err: _err("Please save your ID first, then tick the box: without it you cannot "
|
| 362 |
+
"come back to where you stopped.")}
|
| 363 |
if not agreed:
|
| 364 |
return {consent_err: _err("Please tick the box to continue.")}
|
| 365 |
st["consent_at"] = C.now_iso()
|
|
|
|
| 398 |
|
| 399 |
code_btn.click(on_code, [code_in, key_in, state], ALL, **EVENT)
|
| 400 |
new_btn.click(on_new, [code_in, key_in, state], ALL, **EVENT)
|
| 401 |
+
consent_btn.click(on_consent, [consent_cb, id_saved_cb, state], ALL, **EVENT)
|
| 402 |
easiest.change(on_rank, [easiest, hardest], [gap_bm, gap_mw, gap_bm_q, gap_mw_q, s1_err], **EVENT)
|
| 403 |
hardest.change(on_rank, [easiest, hardest], [gap_bm, gap_mw, gap_bm_q, gap_mw_q, s1_err], **EVENT)
|
| 404 |
s1_btn.click(on_s1, [easiest, hardest, gap_bm, gap_mw, state], ALL, **EVENT)
|