Spaces:
Sleeping
Sleeping
Load case preview before annotator selection
Browse files- app.py +35 -3
- styles.css +26 -0
app.py
CHANGED
|
@@ -57,6 +57,28 @@ def proposal_rows(case: dict[str, Any]) -> list[list[Any]]:
|
|
| 57 |
return rows
|
| 58 |
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
def extracted_rows(case: dict[str, Any]) -> list[list[str]]:
|
| 61 |
parent_id = case["proposal"]["parent"]["row_id"]
|
| 62 |
child_ids = {child["row_id"] for child in case["proposal"]["children"]}
|
|
@@ -119,7 +141,7 @@ def restore_values(case: dict[str, Any], annotation: dict[str, Any] | None) -> t
|
|
| 119 |
|
| 120 |
def case_view(
|
| 121 |
index: int,
|
| 122 |
-
annotator_key: str,
|
| 123 |
document: dict[str, Any],
|
| 124 |
status: str = "Ready",
|
| 125 |
) -> tuple[Any, ...]:
|
|
@@ -134,12 +156,14 @@ def case_view(
|
|
| 134 |
f"### Case {index + 1} of {len(BUNDLE.cases)}"
|
| 135 |
f"\n`{case['audit_id']}` | {case['relation_size']} relation terms | {reviewed}"
|
| 136 |
)
|
|
|
|
| 137 |
return (
|
| 138 |
index,
|
| 139 |
-
progress_html(
|
| 140 |
f"**{status}**",
|
| 141 |
case_title,
|
| 142 |
export_image(case),
|
|
|
|
| 143 |
proposal_rows(case),
|
| 144 |
extracted_rows(case),
|
| 145 |
decision,
|
|
@@ -159,6 +183,7 @@ def locked_view(message: str) -> tuple[Any, ...]:
|
|
| 159 |
f"**{message}**",
|
| 160 |
"### Select an annotator",
|
| 161 |
None,
|
|
|
|
| 162 |
[],
|
| 163 |
[],
|
| 164 |
None,
|
|
@@ -172,7 +197,12 @@ def locked_view(message: str) -> tuple[Any, ...]:
|
|
| 172 |
|
| 173 |
|
| 174 |
def load_initial() -> tuple[Any, ...]:
|
| 175 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
|
| 178 |
def load_annotator(annotator_selection: str | None) -> tuple[Any, ...]:
|
|
@@ -299,6 +329,7 @@ def build_app() -> gr.Blocks:
|
|
| 299 |
height="min(58vh, 680px)",
|
| 300 |
elem_id="statement-image",
|
| 301 |
)
|
|
|
|
| 302 |
|
| 303 |
with gr.Row(equal_height=False, elem_id="workbench"):
|
| 304 |
with gr.Column(scale=6, min_width=420):
|
|
@@ -372,6 +403,7 @@ def build_app() -> gr.Blocks:
|
|
| 372 |
status,
|
| 373 |
case_title,
|
| 374 |
image,
|
|
|
|
| 375 |
candidate,
|
| 376 |
all_rows,
|
| 377 |
decision,
|
|
|
|
| 57 |
return rows
|
| 58 |
|
| 59 |
|
| 60 |
+
def formula_html(case: dict[str, Any]) -> str:
|
| 61 |
+
proposal = case["proposal"]
|
| 62 |
+
parent = html.escape(str(proposal["parent"]["label"]))
|
| 63 |
+
terms: list[str] = []
|
| 64 |
+
for child in proposal["children"]:
|
| 65 |
+
weight = float(child["weight"])
|
| 66 |
+
magnitude = abs(weight)
|
| 67 |
+
coefficient = "" if magnitude == 1 else f"{magnitude:g} x "
|
| 68 |
+
label = html.escape(str(child["label"]))
|
| 69 |
+
term = f"{coefficient}{label}"
|
| 70 |
+
if not terms:
|
| 71 |
+
terms.append(f"- {term}" if weight < 0 else term)
|
| 72 |
+
else:
|
| 73 |
+
terms.append(f" - {term}" if weight < 0 else f" + {term}")
|
| 74 |
+
return (
|
| 75 |
+
'<div class="formula-shell">'
|
| 76 |
+
'<div class="formula-label">Proposed formula</div>'
|
| 77 |
+
f'<div class="formula-expression"><strong>{parent}</strong> = {"".join(terms)}</div>'
|
| 78 |
+
"</div>"
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
def extracted_rows(case: dict[str, Any]) -> list[list[str]]:
|
| 83 |
parent_id = case["proposal"]["parent"]["row_id"]
|
| 84 |
child_ids = {child["row_id"] for child in case["proposal"]["children"]}
|
|
|
|
| 141 |
|
| 142 |
def case_view(
|
| 143 |
index: int,
|
| 144 |
+
annotator_key: str | None,
|
| 145 |
document: dict[str, Any],
|
| 146 |
status: str = "Ready",
|
| 147 |
) -> tuple[Any, ...]:
|
|
|
|
| 156 |
f"### Case {index + 1} of {len(BUNDLE.cases)}"
|
| 157 |
f"\n`{case['audit_id']}` | {case['relation_size']} relation terms | {reviewed}"
|
| 158 |
)
|
| 159 |
+
annotator_label = ANNOTATOR_LABELS.get(annotator_key) if annotator_key else None
|
| 160 |
return (
|
| 161 |
index,
|
| 162 |
+
progress_html(annotator_label, document),
|
| 163 |
f"**{status}**",
|
| 164 |
case_title,
|
| 165 |
export_image(case),
|
| 166 |
+
formula_html(case),
|
| 167 |
proposal_rows(case),
|
| 168 |
extracted_rows(case),
|
| 169 |
decision,
|
|
|
|
| 183 |
f"**{message}**",
|
| 184 |
"### Select an annotator",
|
| 185 |
None,
|
| 186 |
+
"",
|
| 187 |
[],
|
| 188 |
[],
|
| 189 |
None,
|
|
|
|
| 197 |
|
| 198 |
|
| 199 |
def load_initial() -> tuple[Any, ...]:
|
| 200 |
+
return case_view(
|
| 201 |
+
0,
|
| 202 |
+
None,
|
| 203 |
+
{"annotations": {}},
|
| 204 |
+
"Preview loaded; select Annotator 1 or Annotator 2 before saving",
|
| 205 |
+
)
|
| 206 |
|
| 207 |
|
| 208 |
def load_annotator(annotator_selection: str | None) -> tuple[Any, ...]:
|
|
|
|
| 329 |
height="min(58vh, 680px)",
|
| 330 |
elem_id="statement-image",
|
| 331 |
)
|
| 332 |
+
formula = gr.HTML(formula_html(BUNDLE.cases[0]), elem_id="formula-display")
|
| 333 |
|
| 334 |
with gr.Row(equal_height=False, elem_id="workbench"):
|
| 335 |
with gr.Column(scale=6, min_width=420):
|
|
|
|
| 403 |
status,
|
| 404 |
case_title,
|
| 405 |
image,
|
| 406 |
+
formula,
|
| 407 |
candidate,
|
| 408 |
all_rows,
|
| 409 |
decision,
|
styles.css
CHANGED
|
@@ -101,6 +101,32 @@ progress {
|
|
| 101 |
object-fit: contain !important;
|
| 102 |
}
|
| 103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
#workbench {
|
| 105 |
align-items: flex-start;
|
| 106 |
gap: 16px;
|
|
|
|
| 101 |
object-fit: contain !important;
|
| 102 |
}
|
| 103 |
|
| 104 |
+
#formula-display {
|
| 105 |
+
margin-top: 10px;
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
+
.formula-shell {
|
| 109 |
+
background: var(--surface);
|
| 110 |
+
border: 1px solid var(--line);
|
| 111 |
+
border-radius: 6px;
|
| 112 |
+
padding: 12px 14px;
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
.formula-label {
|
| 116 |
+
color: var(--muted);
|
| 117 |
+
font-size: 12px;
|
| 118 |
+
font-weight: 600;
|
| 119 |
+
letter-spacing: 0;
|
| 120 |
+
margin-bottom: 5px;
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
.formula-expression {
|
| 124 |
+
color: var(--ink);
|
| 125 |
+
font-size: 15px;
|
| 126 |
+
line-height: 1.5;
|
| 127 |
+
overflow-wrap: anywhere;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
#workbench {
|
| 131 |
align-items: flex-start;
|
| 132 |
gap: 16px;
|