Spaces:
Sleeping
Sleeping
Make family preview cards navigate to family pages
Browse files
app.py
CHANGED
|
@@ -261,6 +261,16 @@ gradio-app,
|
|
| 261 |
height: 154px;
|
| 262 |
}
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
.record-book {
|
| 265 |
padding: 10px 0 0;
|
| 266 |
}
|
|
@@ -555,14 +565,6 @@ gradio-app,
|
|
| 555 |
background: var(--green-strong) !important;
|
| 556 |
}
|
| 557 |
|
| 558 |
-
.family-button-shell button {
|
| 559 |
-
min-height: 46px !important;
|
| 560 |
-
justify-content: flex-start !important;
|
| 561 |
-
text-align: left !important;
|
| 562 |
-
white-space: normal !important;
|
| 563 |
-
margin-bottom: 12px !important;
|
| 564 |
-
}
|
| 565 |
-
|
| 566 |
.preview-card {
|
| 567 |
max-width: 420px;
|
| 568 |
background: var(--paper);
|
|
@@ -1136,30 +1138,21 @@ def family_preview(setup: str, coordinates: dict[str, dict[str, Any]]) -> str:
|
|
| 1136 |
def family_card(summary: dict[str, Any], coordinates: dict[str, dict[str, Any]]) -> str:
|
| 1137 |
setup = str(summary["setup"])
|
| 1138 |
return f"""
|
| 1139 |
-
<
|
| 1140 |
{family_preview(setup, coordinates)}
|
| 1141 |
<div class="family-card-top">
|
| 1142 |
<div>
|
| 1143 |
<div class="family-code">{esc(setup)}</div>
|
| 1144 |
<h3>{esc(summary["title"])}</h3>
|
|
|
|
| 1145 |
</div>
|
| 1146 |
</div>
|
| 1147 |
-
</
|
| 1148 |
"""
|
| 1149 |
|
| 1150 |
|
| 1151 |
def front_family_card_html(setup: str, coordinates: dict[str, dict[str, Any]]) -> str:
|
| 1152 |
-
return
|
| 1153 |
-
<div class="family-card front-family-card">
|
| 1154 |
-
{family_preview(setup, coordinates)}
|
| 1155 |
-
<div class="family-card-top">
|
| 1156 |
-
<div>
|
| 1157 |
-
<div class="family-code">{esc(setup)}</div>
|
| 1158 |
-
<h3>{esc(setup_title(setup))}</h3>
|
| 1159 |
-
</div>
|
| 1160 |
-
</div>
|
| 1161 |
-
</div>
|
| 1162 |
-
"""
|
| 1163 |
|
| 1164 |
|
| 1165 |
def family_page_html(setup: str | None = None) -> str:
|
|
@@ -1180,6 +1173,7 @@ def family_page_html(setup: str | None = None) -> str:
|
|
| 1180 |
<div class="family-code">{esc(setup)}</div>
|
| 1181 |
<h2>{esc(summary["title"])}</h2>
|
| 1182 |
<p class="family-subtitle">{family_description(summary)}</p>
|
|
|
|
| 1183 |
</div>
|
| 1184 |
</div>
|
| 1185 |
<div class="record-grid">{cards}</div>
|
|
@@ -1193,7 +1187,7 @@ def top_nav() -> str:
|
|
| 1193 |
return """
|
| 1194 |
<nav class="top-nav">
|
| 1195 |
<div class="contain top-nav-inner">
|
| 1196 |
-
<a href="
|
| 1197 |
<div class="nav-links">
|
| 1198 |
<a href="https://erich-friedman.github.io/packing/" target="_blank" rel="noopener noreferrer">Friedman</a>
|
| 1199 |
</div>
|
|
@@ -1204,6 +1198,9 @@ def top_nav() -> str:
|
|
| 1204 |
|
| 1205 |
def directory_html() -> str:
|
| 1206 |
choices = setup_choices()
|
|
|
|
|
|
|
|
|
|
| 1207 |
return f"""
|
| 1208 |
<main class="packing-shell" id="top">
|
| 1209 |
<section class="hero-stage">
|
|
@@ -1227,10 +1224,11 @@ def directory_html() -> str:
|
|
| 1227 |
<div>
|
| 1228 |
<h2>Choose a family</h2>
|
| 1229 |
<p class="section-note">
|
| 1230 |
-
|
| 1231 |
</p>
|
| 1232 |
</div>
|
| 1233 |
</div>
|
|
|
|
| 1234 |
</div>
|
| 1235 |
</section>
|
| 1236 |
</main>
|
|
@@ -1241,6 +1239,17 @@ def browse_html() -> str:
|
|
| 1241 |
return directory_html()
|
| 1242 |
|
| 1243 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1244 |
def empty_family_html() -> str:
|
| 1245 |
return """
|
| 1246 |
<main class="packing-shell">
|
|
@@ -1423,25 +1432,6 @@ with gr.Blocks(title="Packing Benchmark") as demo:
|
|
| 1423 |
with gr.Tabs():
|
| 1424 |
with gr.Tab("Families"):
|
| 1425 |
browse_page = gr.HTML(directory_html())
|
| 1426 |
-
home_family_select = gr.Dropdown(
|
| 1427 |
-
choices=[FAMILY_PROMPT, *setup_choices()],
|
| 1428 |
-
value=FAMILY_PROMPT,
|
| 1429 |
-
label="Family",
|
| 1430 |
-
elem_id="home-family-selector",
|
| 1431 |
-
)
|
| 1432 |
-
gr.Markdown("### All families")
|
| 1433 |
-
family_buttons: list[tuple[str, gr.Button]] = []
|
| 1434 |
-
family_choices = setup_choices()
|
| 1435 |
-
family_coordinates = coordinate_records_by_case()
|
| 1436 |
-
with gr.Group(elem_classes=["family-button-shell"]):
|
| 1437 |
-
for row_start in range(0, len(family_choices), 3):
|
| 1438 |
-
with gr.Row():
|
| 1439 |
-
for setup in family_choices[row_start : row_start + 3]:
|
| 1440 |
-
with gr.Column(scale=1):
|
| 1441 |
-
gr.HTML(front_family_card_html(setup, family_coordinates))
|
| 1442 |
-
button = gr.Button("Open records", size="sm")
|
| 1443 |
-
family_buttons.append((setup, button))
|
| 1444 |
-
home_family_page = gr.HTML(empty_family_html())
|
| 1445 |
|
| 1446 |
with gr.Tab("Family Records"):
|
| 1447 |
choices = setup_choices()
|
|
@@ -1475,18 +1465,7 @@ with gr.Blocks(title="Packing Benchmark") as demo:
|
|
| 1475 |
preview = gr.HTML(label="Browser render")
|
| 1476 |
normalized_json = gr.Code(label="Normalized JSON", language="json", lines=10)
|
| 1477 |
|
| 1478 |
-
|
| 1479 |
-
update_family_page,
|
| 1480 |
-
inputs=[home_family_select],
|
| 1481 |
-
outputs=[home_family_page],
|
| 1482 |
-
scroll_to_output=True,
|
| 1483 |
-
)
|
| 1484 |
-
for setup, button in family_buttons:
|
| 1485 |
-
button.click(
|
| 1486 |
-
lambda setup=setup: choose_family(setup),
|
| 1487 |
-
outputs=[home_family_page, home_family_select],
|
| 1488 |
-
scroll_to_output=True,
|
| 1489 |
-
)
|
| 1490 |
family_select.change(update_family_page, inputs=[family_select], outputs=[family_page])
|
| 1491 |
verify_btn.click(verify_only, inputs=[json_code, json_file, tolerance], outputs=[report, preview, normalized_json])
|
| 1492 |
submit_btn.click(
|
|
|
|
| 261 |
height: 154px;
|
| 262 |
}
|
| 263 |
|
| 264 |
+
.open-label {
|
| 265 |
+
display: inline-block;
|
| 266 |
+
margin-top: 10px;
|
| 267 |
+
color: var(--ink);
|
| 268 |
+
font-size: 13px;
|
| 269 |
+
font-weight: 700;
|
| 270 |
+
text-decoration: underline;
|
| 271 |
+
text-underline-offset: 2px;
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
.record-book {
|
| 275 |
padding: 10px 0 0;
|
| 276 |
}
|
|
|
|
| 565 |
background: var(--green-strong) !important;
|
| 566 |
}
|
| 567 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
.preview-card {
|
| 569 |
max-width: 420px;
|
| 570 |
background: var(--paper);
|
|
|
|
| 1138 |
def family_card(summary: dict[str, Any], coordinates: dict[str, dict[str, Any]]) -> str:
|
| 1139 |
setup = str(summary["setup"])
|
| 1140 |
return f"""
|
| 1141 |
+
<a class="family-card front-family-card" href="?family={esc(setup)}" aria-label="Open {esc(summary["title"])} records">
|
| 1142 |
{family_preview(setup, coordinates)}
|
| 1143 |
<div class="family-card-top">
|
| 1144 |
<div>
|
| 1145 |
<div class="family-code">{esc(setup)}</div>
|
| 1146 |
<h3>{esc(summary["title"])}</h3>
|
| 1147 |
+
<span class="open-label">Open records</span>
|
| 1148 |
</div>
|
| 1149 |
</div>
|
| 1150 |
+
</a>
|
| 1151 |
"""
|
| 1152 |
|
| 1153 |
|
| 1154 |
def front_family_card_html(setup: str, coordinates: dict[str, dict[str, Any]]) -> str:
|
| 1155 |
+
return family_card({"setup": setup, "title": setup_title(setup)}, coordinates)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1156 |
|
| 1157 |
|
| 1158 |
def family_page_html(setup: str | None = None) -> str:
|
|
|
|
| 1173 |
<div class="family-code">{esc(setup)}</div>
|
| 1174 |
<h2>{esc(summary["title"])}</h2>
|
| 1175 |
<p class="family-subtitle">{family_description(summary)}</p>
|
| 1176 |
+
<a class="back-link" href="./">Back to all families</a>
|
| 1177 |
</div>
|
| 1178 |
</div>
|
| 1179 |
<div class="record-grid">{cards}</div>
|
|
|
|
| 1187 |
return """
|
| 1188 |
<nav class="top-nav">
|
| 1189 |
<div class="contain top-nav-inner">
|
| 1190 |
+
<a href="./" aria-label="Packing Benchmark home">Packing Benchmark</a>
|
| 1191 |
<div class="nav-links">
|
| 1192 |
<a href="https://erich-friedman.github.io/packing/" target="_blank" rel="noopener noreferrer">Friedman</a>
|
| 1193 |
</div>
|
|
|
|
| 1198 |
|
| 1199 |
def directory_html() -> str:
|
| 1200 |
choices = setup_choices()
|
| 1201 |
+
summaries = [setup_summary(setup) for setup in choices]
|
| 1202 |
+
coordinates = coordinate_records_by_case()
|
| 1203 |
+
family_cards = "".join(family_card(summary, coordinates) for summary in summaries)
|
| 1204 |
return f"""
|
| 1205 |
<main class="packing-shell" id="top">
|
| 1206 |
<section class="hero-stage">
|
|
|
|
| 1224 |
<div>
|
| 1225 |
<h2>Choose a family</h2>
|
| 1226 |
<p class="section-note">
|
| 1227 |
+
Click a preview to open that family as its own page.
|
| 1228 |
</p>
|
| 1229 |
</div>
|
| 1230 |
</div>
|
| 1231 |
+
<div class="family-grid">{family_cards}</div>
|
| 1232 |
</div>
|
| 1233 |
</section>
|
| 1234 |
</main>
|
|
|
|
| 1239 |
return directory_html()
|
| 1240 |
|
| 1241 |
|
| 1242 |
+
def browse_page_for_request(request: gr.Request):
|
| 1243 |
+
try:
|
| 1244 |
+
query = dict(request.query_params) if request else {}
|
| 1245 |
+
except Exception:
|
| 1246 |
+
query = {}
|
| 1247 |
+
setup = str(query.get("family") or "").strip()
|
| 1248 |
+
if setup in setup_choices():
|
| 1249 |
+
return family_page_html(setup)
|
| 1250 |
+
return directory_html()
|
| 1251 |
+
|
| 1252 |
+
|
| 1253 |
def empty_family_html() -> str:
|
| 1254 |
return """
|
| 1255 |
<main class="packing-shell">
|
|
|
|
| 1432 |
with gr.Tabs():
|
| 1433 |
with gr.Tab("Families"):
|
| 1434 |
browse_page = gr.HTML(directory_html())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1435 |
|
| 1436 |
with gr.Tab("Family Records"):
|
| 1437 |
choices = setup_choices()
|
|
|
|
| 1465 |
preview = gr.HTML(label="Browser render")
|
| 1466 |
normalized_json = gr.Code(label="Normalized JSON", language="json", lines=10)
|
| 1467 |
|
| 1468 |
+
demo.load(browse_page_for_request, outputs=[browse_page], show_progress="hidden")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1469 |
family_select.change(update_family_page, inputs=[family_select], outputs=[family_page])
|
| 1470 |
verify_btn.click(verify_only, inputs=[json_code, json_file, tolerance], outputs=[report, preview, normalized_json])
|
| 1471 |
submit_btn.click(
|