Spaces:
Sleeping
Sleeping
Simplify family navigation and leaderboard
Browse files
app.py
CHANGED
|
@@ -30,7 +30,6 @@ DATA_DIR = SPACE_ROOT / "data"
|
|
| 30 |
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
| 31 |
HYDRATE_STATUS = maybe_hydrate_from_dataset(DATA_DIR)
|
| 32 |
STORE = SolutionStore(DATA_DIR)
|
| 33 |
-
FAMILY_PROMPT = "Select a family..."
|
| 34 |
|
| 35 |
|
| 36 |
CSS = """
|
|
@@ -178,6 +177,31 @@ gradio-app,
|
|
| 178 |
color: #fff !important;
|
| 179 |
}
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
.section {
|
| 182 |
padding: 30px 0 8px;
|
| 183 |
}
|
|
@@ -247,14 +271,6 @@ gradio-app,
|
|
| 247 |
border-radius: var(--radius);
|
| 248 |
}
|
| 249 |
|
| 250 |
-
.family-card.inner-tri { border-top: 7px solid var(--tri); }
|
| 251 |
-
.family-card.inner-cir { border-top: 7px solid var(--cir); }
|
| 252 |
-
.family-card.inner-squ { border-top: 7px solid var(--squ); }
|
| 253 |
-
.family-card.inner-pen { border-top: 7px solid var(--pen); }
|
| 254 |
-
.family-card.inner-hex { border-top: 7px solid var(--hex); }
|
| 255 |
-
.family-card.inner-oct { border-top: 7px solid var(--oct); }
|
| 256 |
-
.family-card.inner-dom { border-top: 7px solid var(--dom); }
|
| 257 |
-
|
| 258 |
.family-card:hover,
|
| 259 |
.family-card:focus-visible {
|
| 260 |
background: #fffaf0;
|
|
@@ -328,16 +344,6 @@ gradio-app,
|
|
| 328 |
height: 154px;
|
| 329 |
}
|
| 330 |
|
| 331 |
-
.open-label {
|
| 332 |
-
display: inline-block;
|
| 333 |
-
margin-top: 10px;
|
| 334 |
-
color: var(--ink);
|
| 335 |
-
font-size: 13px;
|
| 336 |
-
font-weight: 700;
|
| 337 |
-
text-decoration: underline;
|
| 338 |
-
text-underline-offset: 2px;
|
| 339 |
-
}
|
| 340 |
-
|
| 341 |
.record-book {
|
| 342 |
padding: 10px 0 0;
|
| 343 |
}
|
|
@@ -541,13 +547,6 @@ gradio-app,
|
|
| 541 |
overflow-wrap: anywhere;
|
| 542 |
}
|
| 543 |
|
| 544 |
-
.back-link {
|
| 545 |
-
display: inline-block;
|
| 546 |
-
margin-top: 14px;
|
| 547 |
-
color: var(--ink) !important;
|
| 548 |
-
font-size: 13px;
|
| 549 |
-
}
|
| 550 |
-
|
| 551 |
.page-card {
|
| 552 |
background: var(--paper);
|
| 553 |
border: 1px solid var(--line);
|
|
@@ -1269,7 +1268,6 @@ def family_card(summary: dict[str, Any], coordinates: dict[str, dict[str, Any]])
|
|
| 1269 |
<div class="family-code">{esc(setup)}</div>
|
| 1270 |
<h3>{esc(summary["title"])}</h3>
|
| 1271 |
<span class="inner-chip {esc(cls)}">{esc(shape_phrase(item_code, plural=True))}</span>
|
| 1272 |
-
<span class="open-label">Open records</span>
|
| 1273 |
</div>
|
| 1274 |
</div>
|
| 1275 |
</a>
|
|
@@ -1323,7 +1321,6 @@ def family_page_html(setup: str | None = None) -> str:
|
|
| 1323 |
<div class="family-code">{esc(setup)}</div>
|
| 1324 |
<h2>{esc(summary["title"])}</h2>
|
| 1325 |
<p class="family-subtitle">{family_description(summary)}</p>
|
| 1326 |
-
<a class="back-link" href="./">Back to all families</a>
|
| 1327 |
</div>
|
| 1328 |
</div>
|
| 1329 |
<div class="record-grid">{cards}</div>
|
|
@@ -1334,7 +1331,13 @@ def family_page_html(setup: str | None = None) -> str:
|
|
| 1334 |
|
| 1335 |
|
| 1336 |
def top_nav() -> str:
|
| 1337 |
-
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1338 |
|
| 1339 |
|
| 1340 |
@lru_cache(maxsize=4)
|
|
@@ -1402,20 +1405,6 @@ def browse_page_for_request(request: gr.Request):
|
|
| 1402 |
return directory_html()
|
| 1403 |
|
| 1404 |
|
| 1405 |
-
def empty_family_html() -> str:
|
| 1406 |
-
return """
|
| 1407 |
-
<main class="packing-shell">
|
| 1408 |
-
<section class="section">
|
| 1409 |
-
<div class="contain">
|
| 1410 |
-
<div class="page-card">
|
| 1411 |
-
<p>Select a family to view verified coordinate renderings and record details.</p>
|
| 1412 |
-
</div>
|
| 1413 |
-
</div>
|
| 1414 |
-
</section>
|
| 1415 |
-
</main>
|
| 1416 |
-
"""
|
| 1417 |
-
|
| 1418 |
-
|
| 1419 |
def condensed_case_links(cases: list[str]) -> str:
|
| 1420 |
grouped: dict[str, list[int]] = {}
|
| 1421 |
for case in cases:
|
|
@@ -1443,6 +1432,8 @@ def leaderboard_html() -> str:
|
|
| 1443 |
coordinates = coordinate_records_by_case()
|
| 1444 |
for record in STORE.public_records(show_all=False):
|
| 1445 |
author = display_author(record)
|
|
|
|
|
|
|
| 1446 |
entry = rows.setdefault(author, {"wins": 0, "verified": 0, "orange": 0, "cases": []})
|
| 1447 |
entry["wins"] += 1
|
| 1448 |
if record.get("record_type") == "verified":
|
|
@@ -1591,16 +1582,6 @@ def submit_solution(
|
|
| 1591 |
return f"### Submission rejected\n\n- {exc}", "", json_text, directory_html(), leaderboard_html()
|
| 1592 |
|
| 1593 |
|
| 1594 |
-
def update_family_page(setup: str):
|
| 1595 |
-
if not setup or setup == FAMILY_PROMPT:
|
| 1596 |
-
return empty_family_html()
|
| 1597 |
-
return family_page_html(setup)
|
| 1598 |
-
|
| 1599 |
-
|
| 1600 |
-
def choose_family(setup: str):
|
| 1601 |
-
return family_page_html(setup), setup
|
| 1602 |
-
|
| 1603 |
-
|
| 1604 |
THEME = gr.themes.Base()
|
| 1605 |
|
| 1606 |
|
|
@@ -1615,16 +1596,6 @@ with gr.Blocks(title="Packing Benchmark") as demo:
|
|
| 1615 |
with gr.Tab("Families"):
|
| 1616 |
browse_page = gr.HTML(loading_html())
|
| 1617 |
|
| 1618 |
-
with gr.Tab("Family Records"):
|
| 1619 |
-
choices = setup_choices()
|
| 1620 |
-
family_select = gr.Dropdown(
|
| 1621 |
-
choices=[FAMILY_PROMPT, *choices],
|
| 1622 |
-
value=FAMILY_PROMPT,
|
| 1623 |
-
label="Family",
|
| 1624 |
-
elem_id="family-selector",
|
| 1625 |
-
)
|
| 1626 |
-
family_page = gr.HTML(empty_family_html())
|
| 1627 |
-
|
| 1628 |
with gr.Tab("Leaderboard"):
|
| 1629 |
leaderboard_page = gr.HTML(leaderboard_html())
|
| 1630 |
|
|
@@ -1648,7 +1619,6 @@ with gr.Blocks(title="Packing Benchmark") as demo:
|
|
| 1648 |
normalized_json = gr.Textbox(label="Normalized JSON", lines=10)
|
| 1649 |
|
| 1650 |
demo.load(browse_page_for_request, outputs=[browse_page], show_progress="hidden")
|
| 1651 |
-
family_select.change(update_family_page, inputs=[family_select], outputs=[family_page])
|
| 1652 |
verify_btn.click(verify_only, inputs=[json_code, json_file, tolerance], outputs=[report, preview, normalized_json])
|
| 1653 |
submit_btn.click(
|
| 1654 |
submit_solution,
|
|
|
|
| 30 |
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
| 31 |
HYDRATE_STATUS = maybe_hydrate_from_dataset(DATA_DIR)
|
| 32 |
STORE = SolutionStore(DATA_DIR)
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
CSS = """
|
|
|
|
| 177 |
color: #fff !important;
|
| 178 |
}
|
| 179 |
|
| 180 |
+
.page-actions {
|
| 181 |
+
padding: 12px 0 0;
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.home-button {
|
| 185 |
+
display: inline-block;
|
| 186 |
+
min-height: 32px;
|
| 187 |
+
padding: 6px 11px;
|
| 188 |
+
background: var(--paper);
|
| 189 |
+
border: 1px solid var(--line);
|
| 190 |
+
border-radius: 4px;
|
| 191 |
+
color: var(--ink) !important;
|
| 192 |
+
font-size: 14px;
|
| 193 |
+
font-weight: 700;
|
| 194 |
+
line-height: 1.25;
|
| 195 |
+
text-decoration: none !important;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
.home-button:hover,
|
| 199 |
+
.home-button:focus-visible {
|
| 200 |
+
background: #fffaf0;
|
| 201 |
+
outline: 2px solid var(--line);
|
| 202 |
+
outline-offset: 2px;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
.section {
|
| 206 |
padding: 30px 0 8px;
|
| 207 |
}
|
|
|
|
| 271 |
border-radius: var(--radius);
|
| 272 |
}
|
| 273 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
.family-card:hover,
|
| 275 |
.family-card:focus-visible {
|
| 276 |
background: #fffaf0;
|
|
|
|
| 344 |
height: 154px;
|
| 345 |
}
|
| 346 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
.record-book {
|
| 348 |
padding: 10px 0 0;
|
| 349 |
}
|
|
|
|
| 547 |
overflow-wrap: anywhere;
|
| 548 |
}
|
| 549 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
.page-card {
|
| 551 |
background: var(--paper);
|
| 552 |
border: 1px solid var(--line);
|
|
|
|
| 1268 |
<div class="family-code">{esc(setup)}</div>
|
| 1269 |
<h3>{esc(summary["title"])}</h3>
|
| 1270 |
<span class="inner-chip {esc(cls)}">{esc(shape_phrase(item_code, plural=True))}</span>
|
|
|
|
| 1271 |
</div>
|
| 1272 |
</div>
|
| 1273 |
</a>
|
|
|
|
| 1321 |
<div class="family-code">{esc(setup)}</div>
|
| 1322 |
<h2>{esc(summary["title"])}</h2>
|
| 1323 |
<p class="family-subtitle">{family_description(summary)}</p>
|
|
|
|
| 1324 |
</div>
|
| 1325 |
</div>
|
| 1326 |
<div class="record-grid">{cards}</div>
|
|
|
|
| 1331 |
|
| 1332 |
|
| 1333 |
def top_nav() -> str:
|
| 1334 |
+
return """
|
| 1335 |
+
<nav class="page-actions" aria-label="Page navigation">
|
| 1336 |
+
<div class="contain">
|
| 1337 |
+
<a class="home-button" href="./">All families</a>
|
| 1338 |
+
</div>
|
| 1339 |
+
</nav>
|
| 1340 |
+
"""
|
| 1341 |
|
| 1342 |
|
| 1343 |
@lru_cache(maxsize=4)
|
|
|
|
| 1405 |
return directory_html()
|
| 1406 |
|
| 1407 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1408 |
def condensed_case_links(cases: list[str]) -> str:
|
| 1409 |
grouped: dict[str, list[int]] = {}
|
| 1410 |
for case in cases:
|
|
|
|
| 1432 |
coordinates = coordinate_records_by_case()
|
| 1433 |
for record in STORE.public_records(show_all=False):
|
| 1434 |
author = display_author(record)
|
| 1435 |
+
if author.strip().lower() == "trivial":
|
| 1436 |
+
continue
|
| 1437 |
entry = rows.setdefault(author, {"wins": 0, "verified": 0, "orange": 0, "cases": []})
|
| 1438 |
entry["wins"] += 1
|
| 1439 |
if record.get("record_type") == "verified":
|
|
|
|
| 1582 |
return f"### Submission rejected\n\n- {exc}", "", json_text, directory_html(), leaderboard_html()
|
| 1583 |
|
| 1584 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1585 |
THEME = gr.themes.Base()
|
| 1586 |
|
| 1587 |
|
|
|
|
| 1596 |
with gr.Tab("Families"):
|
| 1597 |
browse_page = gr.HTML(loading_html())
|
| 1598 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1599 |
with gr.Tab("Leaderboard"):
|
| 1600 |
leaderboard_page = gr.HTML(leaderboard_html())
|
| 1601 |
|
|
|
|
| 1619 |
normalized_json = gr.Textbox(label="Normalized JSON", lines=10)
|
| 1620 |
|
| 1621 |
demo.load(browse_page_for_request, outputs=[browse_page], show_progress="hidden")
|
|
|
|
| 1622 |
verify_btn.click(verify_only, inputs=[json_code, json_file, tolerance], outputs=[report, preview, normalized_json])
|
| 1623 |
submit_btn.click(
|
| 1624 |
submit_solution,
|