Jonna Marie Matthiesen Claude Opus 4.6 (1M context) commited on
Commit Β·
5969585
1
Parent(s): b96722d
Extract embed SVG generator into embed.js and add version tracking
Browse filesMove the embed-in-model-card feature (SVG generation, modal, upload
workflow) from app.js into a standalone embed.js module. Remove HF
token auto-upload logic, keeping only the manual Download & Open HF
workflow. Add data-commit metadata to generated SVGs for staleness
detection. Use variant-aware filenames so Llama-3.2-1B and 3B get
distinct SVGs. Right-align metric buttons in chart header.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
app.js
CHANGED
|
@@ -508,6 +508,9 @@ function buildChart(filtered) {
|
|
| 508 |
|
| 509 |
chartHeader.appendChild(headerLeft);
|
| 510 |
|
|
|
|
|
|
|
|
|
|
| 511 |
// Only show metric buttons for metrics that have non-zero data
|
| 512 |
const chartVisibleMetrics = config.metrics.filter(m =>
|
| 513 |
gRows.some(r => r[m.column] !== null && r[m.column] !== 0)
|
|
@@ -518,9 +521,18 @@ function buildChart(filtered) {
|
|
| 518 |
chartVisibleMetrics.map(m => ({ value: m.column, label: m.short || m.column })),
|
| 519 |
filters.metric
|
| 520 |
);
|
| 521 |
-
|
| 522 |
}
|
| 523 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
section.appendChild(chartHeader);
|
| 525 |
|
| 526 |
scenarioList.forEach(scenario => {
|
|
@@ -901,6 +913,15 @@ async function buildAccuracyTable() {
|
|
| 901 |
section.appendChild(card);
|
| 902 |
}
|
| 903 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 904 |
// βββ Render βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 905 |
|
| 906 |
function render() {
|
|
|
|
| 508 |
|
| 509 |
chartHeader.appendChild(headerLeft);
|
| 510 |
|
| 511 |
+
const headerRight = document.createElement("div");
|
| 512 |
+
headerRight.className = "chart-header-right";
|
| 513 |
+
|
| 514 |
// Only show metric buttons for metrics that have non-zero data
|
| 515 |
const chartVisibleMetrics = config.metrics.filter(m =>
|
| 516 |
gRows.some(r => r[m.column] !== null && r[m.column] !== 0)
|
|
|
|
| 521 |
chartVisibleMetrics.map(m => ({ value: m.column, label: m.short || m.column })),
|
| 522 |
filters.metric
|
| 523 |
);
|
| 524 |
+
headerRight.appendChild(metricGroup);
|
| 525 |
}
|
| 526 |
|
| 527 |
+
// Embed button
|
| 528 |
+
const embedBtn = document.createElement("button");
|
| 529 |
+
embedBtn.className = "embed-btn";
|
| 530 |
+
embedBtn.innerHTML = '<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg> Embed';
|
| 531 |
+
embedBtn.addEventListener("click", () => embed.showEmbedModal());
|
| 532 |
+
headerRight.appendChild(embedBtn);
|
| 533 |
+
|
| 534 |
+
chartHeader.appendChild(headerRight);
|
| 535 |
+
|
| 536 |
section.appendChild(chartHeader);
|
| 537 |
|
| 538 |
scenarioList.forEach(scenario => {
|
|
|
|
| 913 |
section.appendChild(card);
|
| 914 |
}
|
| 915 |
|
| 916 |
+
// βββ Embed SVG module ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 917 |
+
|
| 918 |
+
const embed = initEmbed({
|
| 919 |
+
config, filters, activeFamilyKey, getActiveModelSet,
|
| 920 |
+
getData: () => DATA, MODEL_COL, FAMILY_COL, GROUP_BY, CHART_CFG,
|
| 921 |
+
MODEL_COLORS, MODEL_SHORT, isOOMRow, isExternalModel,
|
| 922 |
+
sortModels, parseModelSize,
|
| 923 |
+
});
|
| 924 |
+
|
| 925 |
// βββ Render βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 926 |
|
| 927 |
function render() {
|
embed.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// βββ Embed SVG Generator βββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 2 |
+
//
|
| 3 |
+
// Extracted module. Call initEmbed(deps) from the main app once globals are
|
| 4 |
+
// ready. Returns { showEmbedModal }.
|
| 5 |
+
|
| 6 |
+
// eslint-disable-next-line no-unused-vars
|
| 7 |
+
function initEmbed(deps) {
|
| 8 |
+
|
| 9 |
+
const {
|
| 10 |
+
config, filters, activeFamilyKey, getActiveModelSet,
|
| 11 |
+
getData, MODEL_COL, FAMILY_COL, GROUP_BY, CHART_CFG,
|
| 12 |
+
MODEL_COLORS, MODEL_SHORT, isOOMRow, isExternalModel,
|
| 13 |
+
sortModels, parseModelSize,
|
| 14 |
+
} = deps;
|
| 15 |
+
|
| 16 |
+
let embedModal = null;
|
| 17 |
+
let cachedCommitHash = null;
|
| 18 |
+
|
| 19 |
+
const HF_DOCS_REPO = "embedl/documentation-images";
|
| 20 |
+
const HF_SVG_FOLDER = "Edge-Inference-Benchmarks";
|
| 21 |
+
const HF_SPACES_REPO = "embedl/Edge-Inference-Benchmarks";
|
| 22 |
+
const HF_SPACES_URL = "https://huggingface.co/spaces/" + HF_SPACES_REPO;
|
| 23 |
+
|
| 24 |
+
async function loadCommitHash() {
|
| 25 |
+
if (cachedCommitHash) return cachedCommitHash;
|
| 26 |
+
try {
|
| 27 |
+
const resp = await fetch("https://huggingface.co/api/spaces/" + HF_SPACES_REPO);
|
| 28 |
+
if (resp.ok) {
|
| 29 |
+
const data = await resp.json();
|
| 30 |
+
cachedCommitHash = data.sha ? data.sha.substring(0, 7) : null;
|
| 31 |
+
}
|
| 32 |
+
} catch {}
|
| 33 |
+
return cachedCommitHash;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
function embedFamilyKey() {
|
| 37 |
+
return filters.variant || activeFamilyKey();
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
function embedFileName() {
|
| 41 |
+
return embedFamilyKey() + "__" + filters[GROUP_BY] + ".svg";
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
function getEmbedChartData() {
|
| 45 |
+
const familyCfg = config.model_families?.[activeFamilyKey()] || {};
|
| 46 |
+
const chartCfg = familyCfg.chart || CHART_CFG;
|
| 47 |
+
const scenarios = chartCfg.scenarios || [];
|
| 48 |
+
const metricCol = filters.metric;
|
| 49 |
+
const metricCfg = config.metrics.find(m => m.column === metricCol) || {};
|
| 50 |
+
const groupFilterCfg = config.filters.find(f => f.column === GROUP_BY);
|
| 51 |
+
const groupVal = filters[GROUP_BY];
|
| 52 |
+
|
| 53 |
+
if (groupVal === "all") return null;
|
| 54 |
+
|
| 55 |
+
const groupLabel = groupFilterCfg?.value_labels?.[groupVal] || String(groupVal);
|
| 56 |
+
const familyModels = getActiveModelSet();
|
| 57 |
+
const filtered = getData().filter(r => {
|
| 58 |
+
if (!familyModels.has(r[MODEL_COL])) return false;
|
| 59 |
+
for (const f of config.filters) {
|
| 60 |
+
const fv = filters[f.column];
|
| 61 |
+
if (fv === "all" || fv === "" || fv === undefined) continue;
|
| 62 |
+
if (String(r[f.column]) !== String(fv)) return false;
|
| 63 |
+
}
|
| 64 |
+
return true;
|
| 65 |
+
});
|
| 66 |
+
|
| 67 |
+
const gRows = filtered.filter(r => String(r[GROUP_BY]) === String(groupVal));
|
| 68 |
+
if (!gRows.length) return null;
|
| 69 |
+
|
| 70 |
+
const uniqueModels = new Set(gRows.map(r => r[MODEL_COL]));
|
| 71 |
+
if (uniqueModels.size <= 1) return null;
|
| 72 |
+
|
| 73 |
+
const scenarioList = scenarios.length ? scenarios : [{ label: "", match: {} }];
|
| 74 |
+
|
| 75 |
+
// Find first scenario that produces data (mirrors buildChart logic)
|
| 76 |
+
let scenario = null;
|
| 77 |
+
let picked = [];
|
| 78 |
+
for (const sc of scenarioList) {
|
| 79 |
+
const matchRows = gRows.filter(r =>
|
| 80 |
+
Object.entries(sc.match || {}).every(([col, val]) =>
|
| 81 |
+
String(r[col]) === String(val)
|
| 82 |
+
)
|
| 83 |
+
);
|
| 84 |
+
const matchedModels = new Set(matchRows.map(r => r[MODEL_COL]));
|
| 85 |
+
const oomRows = gRows.filter(r => !matchedModels.has(r[MODEL_COL]) && isOOMRow(r)
|
| 86 |
+
&& Object.entries(sc.match || {}).every(([col, val]) =>
|
| 87 |
+
r[col] === null || r[col] === "" || r[col] === "OOM" || String(r[col]) === String(val)
|
| 88 |
+
)
|
| 89 |
+
);
|
| 90 |
+
const allRows = matchRows.concat(oomRows);
|
| 91 |
+
const models = sortModels([...new Set(allRows.map(r => r[MODEL_COL]))]);
|
| 92 |
+
const candidates = models.map(m => allRows.find(r => r[MODEL_COL] === m)).filter(Boolean);
|
| 93 |
+
if (candidates.length) {
|
| 94 |
+
scenario = sc;
|
| 95 |
+
picked = candidates;
|
| 96 |
+
break;
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
if (!picked.length) return null;
|
| 100 |
+
|
| 101 |
+
const hib = metricCfg.higher_is_better !== false;
|
| 102 |
+
picked.sort((a, b) => {
|
| 103 |
+
const sizeA = parseModelSize(a[FAMILY_COL] || a[MODEL_COL]);
|
| 104 |
+
const sizeB = parseModelSize(b[FAMILY_COL] || b[MODEL_COL]);
|
| 105 |
+
if (sizeA !== sizeB) return sizeA - sizeB;
|
| 106 |
+
const extA = isExternalModel(a[MODEL_COL]) ? 0 : 1;
|
| 107 |
+
const extB = isExternalModel(b[MODEL_COL]) ? 0 : 1;
|
| 108 |
+
if (extA !== extB) return extA - extB;
|
| 109 |
+
const va = a[metricCol] ?? 0;
|
| 110 |
+
const vb = b[metricCol] ?? 0;
|
| 111 |
+
return hib ? va - vb : vb - va;
|
| 112 |
+
});
|
| 113 |
+
|
| 114 |
+
const rawLabels = picked.map(r => MODEL_SHORT[r[MODEL_COL]]);
|
| 115 |
+
const families = new Set(picked.map(r => r[FAMILY_COL]));
|
| 116 |
+
const needPrefix = families.size > 1;
|
| 117 |
+
const labels = rawLabels.map((lbl, i) => {
|
| 118 |
+
if (needPrefix) {
|
| 119 |
+
const fk = picked[i][FAMILY_COL] || "";
|
| 120 |
+
return lbl ? `${fk} ${lbl}` : fk;
|
| 121 |
+
}
|
| 122 |
+
return lbl;
|
| 123 |
+
});
|
| 124 |
+
|
| 125 |
+
return {
|
| 126 |
+
familyKey: embedFamilyKey(),
|
| 127 |
+
groupLabel,
|
| 128 |
+
scenarioLabel: scenario.label || "",
|
| 129 |
+
metricCol,
|
| 130 |
+
metricLabel: metricCfg.short || metricCol,
|
| 131 |
+
higherIsBetter: hib,
|
| 132 |
+
picked,
|
| 133 |
+
labels,
|
| 134 |
+
};
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
function generateEmbedSVG(version) {
|
| 138 |
+
const data = getEmbedChartData();
|
| 139 |
+
if (!data) return null;
|
| 140 |
+
|
| 141 |
+
const { familyKey, groupLabel, scenarioLabel, metricCol, metricLabel, higherIsBetter, picked, labels } = data;
|
| 142 |
+
|
| 143 |
+
const width = 800;
|
| 144 |
+
const barHeight = 32;
|
| 145 |
+
const barGap = 10;
|
| 146 |
+
const topPad = 76;
|
| 147 |
+
const bottomPad = 44;
|
| 148 |
+
const leftPad = 260;
|
| 149 |
+
const rightPad = 90;
|
| 150 |
+
const barAreaWidth = width - leftPad - rightPad;
|
| 151 |
+
const contentHeight = picked.length * (barHeight + barGap) - barGap;
|
| 152 |
+
const height = topPad + contentHeight + bottomPad;
|
| 153 |
+
|
| 154 |
+
const maxVal = Math.max(...picked.map(r => r[metricCol] ?? 0), 1);
|
| 155 |
+
|
| 156 |
+
function esc(s) {
|
| 157 |
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
let bars = "";
|
| 161 |
+
picked.forEach((r, i) => {
|
| 162 |
+
const val = r[metricCol] ?? 0;
|
| 163 |
+
const barW = maxVal > 0 ? Math.max((val / maxVal) * barAreaWidth, 0) : 0;
|
| 164 |
+
const y = topPad + i * (barHeight + barGap);
|
| 165 |
+
const cy = y + barHeight / 2 + 5;
|
| 166 |
+
const color = MODEL_COLORS[r[MODEL_COL]]?.border || "#58b1c3";
|
| 167 |
+
const label = labels[i];
|
| 168 |
+
const oom = val === 0 && isOOMRow(r);
|
| 169 |
+
const valText = oom ? "OOM" : val.toFixed(1);
|
| 170 |
+
const valColor = oom ? "#ff4d6d" : "#e8e8e8";
|
| 171 |
+
|
| 172 |
+
bars += ` <text x="${leftPad - 14}" y="${cy}" text-anchor="end" fill="${color}" font-size="13" font-weight="500" font-family="system-ui,-apple-system,sans-serif">${esc(label)}</text>\n`;
|
| 173 |
+
if (!oom && barW > 0) {
|
| 174 |
+
bars += ` <rect x="${leftPad}" y="${y}" width="${barW.toFixed(1)}" height="${barHeight}" rx="4" fill="${color}" opacity="0.7"/>\n`;
|
| 175 |
+
}
|
| 176 |
+
bars += ` <text x="${leftPad + (oom ? 0 : barW) + 10}" y="${cy}" fill="${valColor}" font-size="13" font-weight="${oom ? "600" : "400"}" font-family="system-ui,-apple-system,sans-serif">${valText}</text>\n`;
|
| 177 |
+
});
|
| 178 |
+
|
| 179 |
+
const hint = higherIsBetter ? "(higher is better)" : "(lower is better)";
|
| 180 |
+
const subtitle = [familyKey, groupLabel, scenarioLabel, metricLabel + " " + hint].filter(Boolean).join(" \u00b7 ");
|
| 181 |
+
const commitAttr = version ? ` data-commit="${esc(version)}"` : "";
|
| 182 |
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" width="${width}" height="${height}"${commitAttr}>
|
| 183 |
+
<defs>
|
| 184 |
+
<linearGradient id="topGlow" x1="0" y1="0" x2="1" y2="0">
|
| 185 |
+
<stop offset="0%" stop-color="#58b1c3" stop-opacity="0"/>
|
| 186 |
+
<stop offset="50%" stop-color="#58b1c3" stop-opacity="0.5"/>
|
| 187 |
+
<stop offset="100%" stop-color="#58b1c3" stop-opacity="0"/>
|
| 188 |
+
</linearGradient>
|
| 189 |
+
</defs>
|
| 190 |
+
<rect width="${width}" height="${height}" rx="12" fill="#0B1527"/>
|
| 191 |
+
<rect x="0" y="0" width="${width}" height="${height}" rx="12" fill="none" stroke="#58b1c3" stroke-opacity="0.15"/>
|
| 192 |
+
<rect x="80" y="1" width="${width - 160}" height="2" rx="1" fill="url(#topGlow)"/>
|
| 193 |
+
<text x="28" y="32" fill="#e8e8e8" font-size="17" font-weight="700" font-family="system-ui,-apple-system,sans-serif">Edge Inference Benchmarks</text>
|
| 194 |
+
<text x="28" y="54" fill="#8899aa" font-size="12" font-family="system-ui,-apple-system,sans-serif">${esc(subtitle)}</text>
|
| 195 |
+
${bars} <line x1="28" y1="${height - 36}" x2="${width - 28}" y2="${height - 36}" stroke="#58b1c3" stroke-opacity="0.15"/>
|
| 196 |
+
<text x="28" y="${height - 14}" fill="#5a6a7a" font-size="11" font-family="system-ui,-apple-system,sans-serif">embedl.com</text>
|
| 197 |
+
<text x="${width - 28}" y="${height - 14}" text-anchor="end" fill="#58b1c3" font-size="11" font-family="system-ui,-apple-system,sans-serif">View Benchmarks \u2192</text>
|
| 198 |
+
</svg>`;
|
| 199 |
+
}
|
| 200 |
+
|
| 201 |
+
function createEmbedModal() {
|
| 202 |
+
const overlay = document.createElement("div");
|
| 203 |
+
overlay.className = "embed-overlay";
|
| 204 |
+
overlay.innerHTML = `
|
| 205 |
+
<div class="embed-modal">
|
| 206 |
+
<div class="embed-modal-header">
|
| 207 |
+
<h3>Embed in Model Card</h3>
|
| 208 |
+
<button class="embed-close" aria-label="Close">×</button>
|
| 209 |
+
</div>
|
| 210 |
+
<div class="embed-preview" id="embed-preview"></div>
|
| 211 |
+
<div class="embed-status-bar">
|
| 212 |
+
<span class="embed-status" id="embed-status"></span>
|
| 213 |
+
</div>
|
| 214 |
+
<div class="embed-actions">
|
| 215 |
+
<button class="btn embed-action-btn" id="embed-copy">Copy Embed Code</button>
|
| 216 |
+
<button class="btn embed-action-btn embed-secondary" id="embed-upload-manual">Download SVG & Open HF</button>
|
| 217 |
+
</div>
|
| 218 |
+
<div class="embed-code-section">
|
| 219 |
+
<label>Paste this into your HuggingFace model card README.md:</label>
|
| 220 |
+
<textarea class="embed-code" id="embed-code" readonly rows="6"></textarea>
|
| 221 |
+
</div>
|
| 222 |
+
</div>
|
| 223 |
+
`;
|
| 224 |
+
|
| 225 |
+
overlay.querySelector(".embed-close").addEventListener("click", () => overlay.classList.remove("visible"));
|
| 226 |
+
overlay.addEventListener("click", e => { if (e.target === overlay) overlay.classList.remove("visible"); });
|
| 227 |
+
|
| 228 |
+
overlay.querySelector("#embed-upload-manual").addEventListener("click", () => {
|
| 229 |
+
const svg = generateEmbedSVG(cachedCommitHash);
|
| 230 |
+
if (!svg) return;
|
| 231 |
+
const fileName = embedFileName();
|
| 232 |
+
const blob = new Blob([svg], { type: "image/svg+xml" });
|
| 233 |
+
const url = URL.createObjectURL(blob);
|
| 234 |
+
const a = document.createElement("a");
|
| 235 |
+
a.href = url;
|
| 236 |
+
a.download = fileName;
|
| 237 |
+
a.click();
|
| 238 |
+
URL.revokeObjectURL(url);
|
| 239 |
+
const commitMsg = "Update " + fileName + " (" + (cachedCommitHash || "latest") + ")";
|
| 240 |
+
window.open("https://huggingface.co/datasets/" + HF_DOCS_REPO + "/upload/main/" + HF_SVG_FOLDER + "?commit_message=" + encodeURIComponent(commitMsg), "_blank");
|
| 241 |
+
});
|
| 242 |
+
|
| 243 |
+
overlay.querySelector("#embed-copy").addEventListener("click", () => {
|
| 244 |
+
const textarea = overlay.querySelector("#embed-code");
|
| 245 |
+
navigator.clipboard.writeText(textarea.value);
|
| 246 |
+
const btn = overlay.querySelector("#embed-copy");
|
| 247 |
+
const orig = btn.textContent;
|
| 248 |
+
btn.textContent = "Copied!";
|
| 249 |
+
setTimeout(() => { btn.textContent = orig; }, 2000);
|
| 250 |
+
});
|
| 251 |
+
|
| 252 |
+
document.body.appendChild(overlay);
|
| 253 |
+
return overlay;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
function setEmbedStatus(cls, html) {
|
| 257 |
+
const el = embedModal.querySelector("#embed-status");
|
| 258 |
+
el.className = "embed-status " + cls;
|
| 259 |
+
el.innerHTML = html;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
function showUploadUI(show) {
|
| 263 |
+
embedModal.querySelector("#embed-upload-manual").style.display = show ? "" : "none";
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
async function runEmbedUpload() {
|
| 267 |
+
const version = cachedCommitHash;
|
| 268 |
+
const fileName = embedFileName();
|
| 269 |
+
const svgPath = HF_SVG_FOLDER + "/" + fileName;
|
| 270 |
+
const svgUrl = "https://huggingface.co/datasets/" + HF_DOCS_REPO + "/resolve/main/" + svgPath;
|
| 271 |
+
|
| 272 |
+
setEmbedStatus("checking", "Checking\u2026");
|
| 273 |
+
showUploadUI(false);
|
| 274 |
+
|
| 275 |
+
let remoteCommit = null;
|
| 276 |
+
let exists = false;
|
| 277 |
+
try {
|
| 278 |
+
const resp = await fetch(svgUrl, { cache: "no-store" });
|
| 279 |
+
if (resp.ok) {
|
| 280 |
+
exists = true;
|
| 281 |
+
const text = await resp.text();
|
| 282 |
+
const m = text.match(/data-commit="([^"]+)"/);
|
| 283 |
+
if (m) remoteCommit = m[1];
|
| 284 |
+
}
|
| 285 |
+
} catch {}
|
| 286 |
+
|
| 287 |
+
if (exists && version && remoteCommit === version) {
|
| 288 |
+
setEmbedStatus("up-to-date", "");
|
| 289 |
+
return;
|
| 290 |
+
}
|
| 291 |
+
|
| 292 |
+
if (exists) {
|
| 293 |
+
setEmbedStatus("needs-token", "SVG outdated \u2014 use Download SVG & Open HF below to update");
|
| 294 |
+
} else {
|
| 295 |
+
setEmbedStatus("needs-token", "SVG not yet uploaded \u2014 use Download SVG & Open HF below to upload manually");
|
| 296 |
+
}
|
| 297 |
+
showUploadUI(true);
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
async function showEmbedModal() {
|
| 301 |
+
if (!embedModal) embedModal = createEmbedModal();
|
| 302 |
+
|
| 303 |
+
const version = await loadCommitHash();
|
| 304 |
+
const svg = generateEmbedSVG(version);
|
| 305 |
+
if (!svg) return;
|
| 306 |
+
|
| 307 |
+
embedModal.querySelector("#embed-preview").innerHTML = svg;
|
| 308 |
+
|
| 309 |
+
const famKey = embedFamilyKey();
|
| 310 |
+
const fileName = embedFileName();
|
| 311 |
+
const svgUrl = "https://huggingface.co/datasets/" + HF_DOCS_REPO + "/resolve/main/" + HF_SVG_FOLDER + "/" + fileName;
|
| 312 |
+
|
| 313 |
+
const embedCode = '<a href="' + HF_SPACES_URL + '" target="_blank" rel="noopener">\n <img\n src="' + svgUrl + '"\n alt="Edge Inference Benchmarks for ' + famKey + '"\n width="100%"\n />\n</a>';
|
| 314 |
+
|
| 315 |
+
embedModal.querySelector("#embed-code").value = embedCode;
|
| 316 |
+
embedModal.classList.add("visible");
|
| 317 |
+
|
| 318 |
+
runEmbedUpload();
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
return { showEmbedModal };
|
| 322 |
+
|
| 323 |
+
} // end initEmbed
|
index.html
CHANGED
|
@@ -94,6 +94,7 @@
|
|
| 94 |
</footer>
|
| 95 |
|
| 96 |
<script src="demo/demo.js"></script>
|
|
|
|
| 97 |
<script src="app.js"></script>
|
| 98 |
</body>
|
| 99 |
</html>
|
|
|
|
| 94 |
</footer>
|
| 95 |
|
| 96 |
<script src="demo/demo.js"></script>
|
| 97 |
+
<script src="embed.js"></script>
|
| 98 |
<script src="app.js"></script>
|
| 99 |
</body>
|
| 100 |
</html>
|
style.css
CHANGED
|
@@ -202,6 +202,13 @@
|
|
| 202 |
gap: var(--space-md);
|
| 203 |
}
|
| 204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
.chart-header .filter-group {
|
| 206 |
margin: 0;
|
| 207 |
}
|
|
@@ -505,6 +512,267 @@ tbody tr.row-group-break td {
|
|
| 505 |
color: var(--teal);
|
| 506 |
}
|
| 507 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
/* ββ Responsive ββββββββββββββββββββββββββββββββββββββββ */
|
| 509 |
@media (max-width: 900px) {
|
| 510 |
.page {
|
|
|
|
| 202 |
gap: var(--space-md);
|
| 203 |
}
|
| 204 |
|
| 205 |
+
.chart-header-right {
|
| 206 |
+
display: flex;
|
| 207 |
+
align-items: center;
|
| 208 |
+
gap: var(--space-md);
|
| 209 |
+
margin-left: auto;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
.chart-header .filter-group {
|
| 213 |
margin: 0;
|
| 214 |
}
|
|
|
|
| 512 |
color: var(--teal);
|
| 513 |
}
|
| 514 |
|
| 515 |
+
/* ββ Embed ββββββββββββββββββββββββββββββββββββββββββββ */
|
| 516 |
+
.embed-btn {
|
| 517 |
+
display: inline-flex;
|
| 518 |
+
align-items: center;
|
| 519 |
+
gap: var(--space-sm);
|
| 520 |
+
border: 1px solid var(--border);
|
| 521 |
+
border-radius: 6px;
|
| 522 |
+
padding: var(--space-sm) var(--space-md);
|
| 523 |
+
font-size: var(--text-sm);
|
| 524 |
+
color: var(--text-muted);
|
| 525 |
+
background: transparent;
|
| 526 |
+
cursor: pointer;
|
| 527 |
+
transition: all 0.15s;
|
| 528 |
+
margin-left: auto;
|
| 529 |
+
white-space: nowrap;
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
.embed-btn:hover {
|
| 533 |
+
color: var(--teal);
|
| 534 |
+
border-color: var(--btn-active-border);
|
| 535 |
+
background: var(--btn-active-bg);
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
.embed-overlay {
|
| 539 |
+
position: fixed;
|
| 540 |
+
inset: 0;
|
| 541 |
+
z-index: 1000;
|
| 542 |
+
background: rgba(0, 0, 0, 0.7);
|
| 543 |
+
display: flex;
|
| 544 |
+
align-items: center;
|
| 545 |
+
justify-content: center;
|
| 546 |
+
opacity: 0;
|
| 547 |
+
pointer-events: none;
|
| 548 |
+
transition: opacity 0.2s;
|
| 549 |
+
backdrop-filter: blur(4px);
|
| 550 |
+
}
|
| 551 |
+
|
| 552 |
+
.embed-overlay.visible {
|
| 553 |
+
opacity: 1;
|
| 554 |
+
pointer-events: auto;
|
| 555 |
+
}
|
| 556 |
+
|
| 557 |
+
.embed-modal {
|
| 558 |
+
background: #0e1a2e;
|
| 559 |
+
border: 1px solid rgba(88, 177, 195, 0.2);
|
| 560 |
+
border-radius: 12px;
|
| 561 |
+
width: 90%;
|
| 562 |
+
max-width: 720px;
|
| 563 |
+
max-height: 90vh;
|
| 564 |
+
overflow-y: auto;
|
| 565 |
+
padding: var(--space-xl);
|
| 566 |
+
scrollbar-color: var(--text-dim) var(--border);
|
| 567 |
+
scrollbar-width: thin;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
.embed-modal::-webkit-scrollbar {
|
| 571 |
+
width: 8px;
|
| 572 |
+
}
|
| 573 |
+
|
| 574 |
+
.embed-modal::-webkit-scrollbar-track {
|
| 575 |
+
background: var(--border);
|
| 576 |
+
border-radius: 4px;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
.embed-modal::-webkit-scrollbar-thumb {
|
| 580 |
+
background: var(--text-dim);
|
| 581 |
+
border-radius: 4px;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
.embed-modal::-webkit-scrollbar-thumb:hover {
|
| 585 |
+
background: var(--text-muted);
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
.embed-modal-header {
|
| 589 |
+
display: flex;
|
| 590 |
+
align-items: center;
|
| 591 |
+
justify-content: space-between;
|
| 592 |
+
margin-bottom: var(--space-lg);
|
| 593 |
+
}
|
| 594 |
+
|
| 595 |
+
.embed-modal-header h3 {
|
| 596 |
+
font-size: var(--text-lg);
|
| 597 |
+
font-weight: 600;
|
| 598 |
+
color: var(--text);
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
.embed-close {
|
| 602 |
+
background: none;
|
| 603 |
+
border: none;
|
| 604 |
+
color: var(--text-dim);
|
| 605 |
+
font-size: 1.5rem;
|
| 606 |
+
cursor: pointer;
|
| 607 |
+
padding: var(--space-sm);
|
| 608 |
+
line-height: 1;
|
| 609 |
+
transition: color 0.15s;
|
| 610 |
+
}
|
| 611 |
+
|
| 612 |
+
.embed-close:hover {
|
| 613 |
+
color: var(--text);
|
| 614 |
+
}
|
| 615 |
+
|
| 616 |
+
.embed-preview {
|
| 617 |
+
background: #0B1527;
|
| 618 |
+
border-radius: 8px;
|
| 619 |
+
padding: var(--space-sm);
|
| 620 |
+
margin-bottom: var(--space-lg);
|
| 621 |
+
overflow: hidden;
|
| 622 |
+
}
|
| 623 |
+
|
| 624 |
+
.embed-preview svg {
|
| 625 |
+
width: 100%;
|
| 626 |
+
height: auto;
|
| 627 |
+
display: block;
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
.embed-status-bar {
|
| 631 |
+
margin-bottom: var(--space-md);
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
.embed-status {
|
| 635 |
+
font-size: var(--text-sm);
|
| 636 |
+
font-weight: 500;
|
| 637 |
+
}
|
| 638 |
+
|
| 639 |
+
.embed-status.checking {
|
| 640 |
+
color: var(--text-dim);
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
.embed-status.checking::before {
|
| 644 |
+
content: "\25CB ";
|
| 645 |
+
}
|
| 646 |
+
|
| 647 |
+
.embed-status.up-to-date {
|
| 648 |
+
display: none;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
.embed-status.uploading {
|
| 652 |
+
color: var(--teal);
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
.embed-status.uploading::before {
|
| 656 |
+
content: "\21BB ";
|
| 657 |
+
}
|
| 658 |
+
|
| 659 |
+
.embed-status.uploaded {
|
| 660 |
+
color: var(--green);
|
| 661 |
+
}
|
| 662 |
+
|
| 663 |
+
.embed-status.uploaded::before {
|
| 664 |
+
content: "\2713 ";
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
.embed-status.needs-token {
|
| 668 |
+
color: #ffd166;
|
| 669 |
+
}
|
| 670 |
+
|
| 671 |
+
.embed-status.needs-token::before {
|
| 672 |
+
content: "\26A0 ";
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
.embed-status a {
|
| 676 |
+
color: var(--teal);
|
| 677 |
+
text-decoration: none;
|
| 678 |
+
font-weight: 600;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
.embed-status a:hover {
|
| 682 |
+
text-decoration: underline;
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
.embed-status.error {
|
| 686 |
+
color: var(--red);
|
| 687 |
+
word-break: break-word;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
.embed-status.error::before {
|
| 691 |
+
content: "\2717 ";
|
| 692 |
+
}
|
| 693 |
+
|
| 694 |
+
.embed-actions {
|
| 695 |
+
display: flex;
|
| 696 |
+
gap: var(--space-md);
|
| 697 |
+
margin-bottom: var(--space-lg);
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
.embed-action-btn {
|
| 701 |
+
border-radius: 6px !important;
|
| 702 |
+
padding: var(--space-sm) var(--space-md);
|
| 703 |
+
font-size: var(--text-md);
|
| 704 |
+
cursor: pointer;
|
| 705 |
+
transition: all 0.15s;
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
.embed-action-btn:first-child {
|
| 709 |
+
background: var(--btn-active-bg);
|
| 710 |
+
border-color: var(--btn-active-border);
|
| 711 |
+
color: var(--teal);
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
.embed-action-btn:first-child:hover {
|
| 715 |
+
background: rgba(88, 177, 195, 0.2);
|
| 716 |
+
}
|
| 717 |
+
|
| 718 |
+
.embed-secondary {
|
| 719 |
+
opacity: 0.7;
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
.embed-secondary:hover {
|
| 723 |
+
opacity: 1;
|
| 724 |
+
}
|
| 725 |
+
|
| 726 |
+
.embed-code-section {
|
| 727 |
+
margin-bottom: var(--space-sm);
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
.embed-code-section label {
|
| 731 |
+
display: block;
|
| 732 |
+
font-size: var(--text-sm);
|
| 733 |
+
color: var(--text-dim);
|
| 734 |
+
margin-bottom: var(--space-sm);
|
| 735 |
+
}
|
| 736 |
+
|
| 737 |
+
.embed-code {
|
| 738 |
+
width: 100%;
|
| 739 |
+
background: rgba(0, 0, 0, 0.3);
|
| 740 |
+
border: 1px solid var(--border);
|
| 741 |
+
border-radius: 6px;
|
| 742 |
+
color: var(--teal);
|
| 743 |
+
font-family: "SF Mono", "Fira Code", "Consolas", monospace;
|
| 744 |
+
font-size: var(--text-sm);
|
| 745 |
+
padding: var(--space-md);
|
| 746 |
+
resize: vertical;
|
| 747 |
+
line-height: 1.5;
|
| 748 |
+
scrollbar-color: var(--text-dim) var(--border);
|
| 749 |
+
scrollbar-width: thin;
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
.embed-code::-webkit-scrollbar {
|
| 753 |
+
width: 8px;
|
| 754 |
+
height: 8px;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
.embed-code::-webkit-scrollbar-track {
|
| 758 |
+
background: var(--border);
|
| 759 |
+
border-radius: 4px;
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
.embed-code::-webkit-scrollbar-thumb {
|
| 763 |
+
background: var(--text-dim);
|
| 764 |
+
border-radius: 4px;
|
| 765 |
+
}
|
| 766 |
+
|
| 767 |
+
.embed-code::-webkit-scrollbar-thumb:hover {
|
| 768 |
+
background: var(--text-muted);
|
| 769 |
+
}
|
| 770 |
+
|
| 771 |
+
.embed-code:focus {
|
| 772 |
+
outline: none;
|
| 773 |
+
border-color: var(--btn-active-border);
|
| 774 |
+
}
|
| 775 |
+
|
| 776 |
/* ββ Responsive ββββββββββββββββββββββββββββββββββββββββ */
|
| 777 |
@media (max-width: 900px) {
|
| 778 |
.page {
|