Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -51,6 +51,7 @@ import json
|
|
| 51 |
import logging
|
| 52 |
import math
|
| 53 |
import re
|
|
|
|
| 54 |
from dataclasses import dataclass
|
| 55 |
from pathlib import Path
|
| 56 |
from typing import Any
|
|
@@ -618,17 +619,20 @@ def render_card(method: str, spec: BenchmarkSpec) -> str:
|
|
| 618 |
else:
|
| 619 |
bench_html = f'<div class="bench muted">No reviews yet (no {esc(spec.label)} benchmark results).</div>'
|
| 620 |
|
| 621 |
-
#
|
| 622 |
-
#
|
| 623 |
-
# and
|
|
|
|
|
|
|
| 624 |
description = info["description"]
|
|
|
|
|
|
|
| 625 |
more_html = ""
|
| 626 |
-
if len(description) >
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
)
|
| 632 |
|
| 633 |
paper_url = info.get("paper_url") # .get: tolerate a data.json built before paper links were added
|
| 634 |
paper_html = (
|
|
@@ -640,7 +644,8 @@ def render_card(method: str, spec: BenchmarkSpec) -> str:
|
|
| 640 |
return f"""
|
| 641 |
<article class="card">
|
| 642 |
{banner_html(method)}
|
| 643 |
-
|
|
|
|
| 644 |
{more_html}
|
| 645 |
<div class="badges"><span class="chip category">{esc(CATEGORY_LABELS.get(category, category))}</span>{badges}</div>
|
| 646 |
<div class="quant-row">{quant_html}</div>
|
|
@@ -907,8 +912,8 @@ def build_comparison(methods: list[str]) -> str:
|
|
| 907 |
|
| 908 |
|
| 909 |
def build_receipt(methods: list[str]) -> str:
|
| 910 |
-
"""The order confirmation opened by the pay button: a floating window (
|
| 911 |
-
|
| 912 |
if methods:
|
| 913 |
rows = "".join(
|
| 914 |
f"<tr><td>{esc(method)}</td><td><s>${fantasy_price(method):.2f}</s></td>"
|
|
@@ -975,8 +980,7 @@ CSS = """
|
|
| 975 |
.explorer .monogram { width: 2.2rem; height: 2.2rem; flex-shrink: 0; border-radius: 8px; display: flex; align-items: center;
|
| 976 |
justify-content: center; color: #fff; font-weight: 800; font-size: 0.95rem;
|
| 977 |
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); }
|
| 978 |
-
.explorer .description { margin: 0; color: var(--x-muted); font-size: 0.86rem;
|
| 979 |
-
-webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
|
| 980 |
.explorer .badges, .explorer .quant-row { display: flex; flex-wrap: wrap; gap: 0.3rem; }
|
| 981 |
.explorer .badge { font-size: 0.74rem; padding: 0.12rem 0.45rem; border-radius: 999px; white-space: nowrap; }
|
| 982 |
.explorer .badge.yes { color: var(--x-yes); background: var(--x-yes-bg); }
|
|
@@ -998,20 +1002,23 @@ CSS = """
|
|
| 998 |
.explorer .cta.secondary { background: var(--x-surface-2); color: var(--x-text);
|
| 999 |
border: 1px solid var(--x-border); }
|
| 1000 |
|
| 1001 |
-
/* "
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
.explorer .
|
| 1007 |
-
.explorer .
|
| 1008 |
-
.explorer .
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
|
|
|
|
|
|
|
|
|
| 1015 |
left: 50% !important; bottom: auto !important; right: auto !important; margin: 0 !important;
|
| 1016 |
transform: translate(-50%, -50%); max-height: 85vh; overflow-y: auto; }
|
| 1017 |
.explorer .receipt-popover { min-width: min(480px, 92vw); padding: 1.6rem 2rem; border: 1px solid var(--x-border);
|
|
|
|
| 51 |
import logging
|
| 52 |
import math
|
| 53 |
import re
|
| 54 |
+
import textwrap
|
| 55 |
from dataclasses import dataclass
|
| 56 |
from pathlib import Path
|
| 57 |
from typing import Any
|
|
|
|
| 619 |
else:
|
| 620 |
bench_html = f'<div class="bench muted">No reviews yet (no {esc(spec.label)} benchmark results).</div>'
|
| 621 |
|
| 622 |
+
# Overlong descriptions are truncated and get a "Show more" toggle that expands them in place, like overlong
|
| 623 |
+
# YouTube comments: a hidden checkbox placed before the paragraph selects which of the two text spans is shown,
|
| 624 |
+
# and the toggle's text, through CSS sibling selectors (see the .more-toggle rules) -- no JS or Gradio event
|
| 625 |
+
# machinery needed. Truncating by character count server-side (instead of a CSS line clamp) keeps the toggle
|
| 626 |
+
# and the truncation in sync: the toggle exists if and only if there is hidden text to reveal.
|
| 627 |
description = info["description"]
|
| 628 |
+
desc_html = esc(description)
|
| 629 |
+
toggle_html = ""
|
| 630 |
more_html = ""
|
| 631 |
+
if len(description) > 200:
|
| 632 |
+
short = textwrap.shorten(description, width=160, placeholder=" …")
|
| 633 |
+
desc_html = f'<span class="desc-short">{esc(short)}</span><span class="desc-full">{esc(description)}</span>'
|
| 634 |
+
toggle_html = f'<input type="checkbox" id="more-{esc(method)}" class="more-toggle">'
|
| 635 |
+
more_html = f'<label for="more-{esc(method)}" class="more-link"></label>'
|
|
|
|
| 636 |
|
| 637 |
paper_url = info.get("paper_url") # .get: tolerate a data.json built before paper links were added
|
| 638 |
paper_html = (
|
|
|
|
| 644 |
return f"""
|
| 645 |
<article class="card">
|
| 646 |
{banner_html(method)}
|
| 647 |
+
{toggle_html}
|
| 648 |
+
<p class="description">{desc_html}</p>
|
| 649 |
{more_html}
|
| 650 |
<div class="badges"><span class="chip category">{esc(CATEGORY_LABELS.get(category, category))}</span>{badges}</div>
|
| 651 |
<div class="quant-row">{quant_html}</div>
|
|
|
|
| 912 |
|
| 913 |
|
| 914 |
def build_receipt(methods: list[str]) -> str:
|
| 915 |
+
"""The order confirmation opened by the pay button: a floating window (a native HTML popover, rendered in the
|
| 916 |
+
browser's top layer) showing a shop-style receipt with the crossed-out fantasy prices."""
|
| 917 |
if methods:
|
| 918 |
rows = "".join(
|
| 919 |
f"<tr><td>{esc(method)}</td><td><s>${fantasy_price(method):.2f}</s></td>"
|
|
|
|
| 980 |
.explorer .monogram { width: 2.2rem; height: 2.2rem; flex-shrink: 0; border-radius: 8px; display: flex; align-items: center;
|
| 981 |
justify-content: center; color: #fff; font-weight: 800; font-size: 0.95rem;
|
| 982 |
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); }
|
| 983 |
+
.explorer .description { margin: 0; color: var(--x-muted); font-size: 0.86rem; }
|
|
|
|
| 984 |
.explorer .badges, .explorer .quant-row { display: flex; flex-wrap: wrap; gap: 0.3rem; }
|
| 985 |
.explorer .badge { font-size: 0.74rem; padding: 0.12rem 0.45rem; border-radius: 999px; white-space: nowrap; }
|
| 986 |
.explorer .badge.yes { color: var(--x-yes); background: var(--x-yes-bg); }
|
|
|
|
| 1002 |
.explorer .cta.secondary { background: var(--x-surface-2); color: var(--x-text);
|
| 1003 |
border: 1px solid var(--x-border); }
|
| 1004 |
|
| 1005 |
+
/* The "Show more" toggle of overlong descriptions: a hidden checkbox before the description paragraph selects
|
| 1006 |
+
which of the two text spans (truncated or full) is shown, and the label's text flips between "Show more" and
|
| 1007 |
+
"Show less", like overlong YouTube comments. The checkbox is hidden via our own CSS instead of the `hidden`
|
| 1008 |
+
attribute, which does not survive Gradio's HTML handling. */
|
| 1009 |
+
.explorer .more-toggle { display: none !important; }
|
| 1010 |
+
.explorer .more-link { color: var(--x-accent); cursor: pointer; font-size: 0.8rem; }
|
| 1011 |
+
.explorer .more-link::after { content: "Show more"; }
|
| 1012 |
+
.explorer .more-toggle:checked ~ .more-link::after { content: "Show less"; }
|
| 1013 |
+
.explorer .desc-full { display: none; }
|
| 1014 |
+
.explorer .more-toggle:checked ~ .description .desc-short { display: none; }
|
| 1015 |
+
.explorer .more-toggle:checked ~ .description .desc-full { display: inline; }
|
| 1016 |
+
|
| 1017 |
+
/* The pay button's order receipt, a native popover in the browser's top layer. It is re-centered explicitly: the
|
| 1018 |
+
browser stylesheet would center it via `margin: auto`, but Gradio's styles interfere with that, leaving the
|
| 1019 |
+
popover stuck at the viewport edge. Centering via top/left/transform (with !important) depends on fewer
|
| 1020 |
+
properties and survives the interference. */
|
| 1021 |
+
.explorer .receipt-popover { position: fixed !important; top: 50% !important;
|
| 1022 |
left: 50% !important; bottom: auto !important; right: auto !important; margin: 0 !important;
|
| 1023 |
transform: translate(-50%, -50%); max-height: 85vh; overflow-y: auto; }
|
| 1024 |
.explorer .receipt-popover { min-width: min(480px, 92vw); padding: 1.6rem 2rem; border: 1px solid var(--x-border);
|