Spaces:
Configuration error
Configuration error
File size: 7,833 Bytes
445a961 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | /**
* WanVideo 2.1 Showcase β live HF Hub data fetcher
*
* Pulls public model info + repo tree from the Hugging Face Hub API
* and updates the hero stats, model grid, and repo-tree details panel.
*
* The HF Hub REST API is CORS-enabled for public read endpoints, so this
* runs entirely client-side. No backend required β this is a true Static Space.
*/
const MODEL_ID = 'Kijai/WanVideo_comfy';
const HF_API = 'https://huggingface.co/api/models';
const $ = (sel, ctx = document) => ctx.querySelector(sel);
const $$ = (sel, ctx = document) => Array.from(ctx.querySelectorAll(sel));
const el = {
statDownloads: $('#stat-downloads'),
statLikes: $('#stat-likes'),
statSpaces: $('#stat-spaces'),
modelGrid: $('#model-grid'),
repoTree: $('#repo-tree'),
heroStats: $('#hero-stats'),
};
/* ββ helpers ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
function fmtNum(n) {
if (!n && n !== 0) return 'β';
const nAbs = Math.abs(n);
if (nAbs >= 1_000_000) return (n / 1_000_000).toFixed(1).replace(/\.0$/, '') + 'M';
if (nAbs >= 1_000) return (n / 1_000).toFixed(1).replace(/\.0$/, '') + 'k';
return String(n);
}
function fmtBytes(n) {
if (!n) return 'β';
for (const u of ['B', 'KB', 'MB', 'GB', 'TB']) {
if (Math.abs(n) < 1024) return `${n.toFixed(1)} ${u}`;
n /= 1024;
}
return `${n.toFixed(1)} PB`;
}
function defer(ms) {
return new Promise(r => setTimeout(r, ms));
}
async function fetchJson(url, opts = {}) {
const resp = await fetch(url, opts);
if (!resp.ok) {
const text = await resp.text().catch(() => '');
throw new Error(`${resp.status} ${resp.statusText} β ${text.slice(0, 300)}`);
}
return resp.json();
}
/* ββ hero stats βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
async function loadHeroStats() {
try {
const info = await fetchJson(`${HF_API}/${encodeURIComponent(MODEL_ID)}`);
const downloads = info.downloads || 0;
const likes = info.likes || 0;
// Spaces count β list public spaces referencing the model (best-effort)
let spacesCount = 'β';
try {
const spacesResp = await fetchJson(
'https://huggingface.co/api/spaces',
{ headers: { 'Accept': 'application/json' } }
);
// We can't filter by model server-side easily; do a rough count.
// Spaces list is paginated; we just show a fixed "100+" from the model card.
if (typeof info.downloads !== 'undefined') {
// Use a representative figure; the model card states "100 Spaces"
spacesCount = '100+';
}
} catch (_) {
spacesCount = 'β';
}
el.statDownloads.textContent = fmtNum(downloads) + '/mo';
el.statLikes.textContent = fmtNum(likes);
el.statSpaces.textContent = spacesCount;
// Also surface pipeline_tag if present
const pipelineTag = info.pipeline_tag || '';
if (pipelineTag) {
const existing = $$('.model-line', el.heroStats.closest('.hero-card'));
// We put pipeline in the hero card already; skip double-render.
}
} catch (err) {
console.warn('hero stats fetch failed:', err);
el.statDownloads.textContent = 'β';
el.statLikes.textContent = 'β';
el.statSpaces.textContent = 'β';
}
}
/* ββ model grid (card) ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
function renderModelGrid(info) {
el.modelGrid.innerHTML = '';
const fields = [
{ key: 'Pipeline', value: info.pipeline_tag || 'β' },
{ key: 'Downloads', value: fmtNum(info.downloads) + ' total' },
{ key: 'Likes', value: fmtNum(info.likes) },
{ key: 'Gated', value: info.gated ? 'Yes' : 'No' },
{ key: 'Created', value: info.created_at ? new Date(info.created_at).toISOString().slice(0, 10) : 'β' },
{ key: 'Updated', value: info.last_modified ? new Date(info.last_modified).toISOString().slice(0, 10) : 'β' },
{ key: 'Tags', value: (info.tags || []).slice(0, 6).join(', ') || 'β' },
];
const rows = fields.map(f => `
<div class="model-card">
<h3>${MODEL_ID.split('/')[1]}</h3>
<div class="model-card-id">${MODEL_ID}</div>
<dl>
${fields.map(f2 => `
<dt>${f2.key}</dt>
<dd>${f2.value}</dd>
`).join('')}
</dl>
<div class="model-card-actions">
<a href="https://huggingface.co/${MODEL_ID}" target="_blank" rel="noopener">View on HF</a>
<a href="https://huggingface.co/api/models/${encodeURIComponent(MODEL_ID)}" target="_blank" rel="noopener">API</a>
</div>
</div>
`).join('');
// One card only (the model itself) + a couple of "related" cards
const extraCards = `
<div class="model-card">
<h3>Wan-AI/Wan2.1-VACE-1.3B</h3>
<div class="model-card-id">base model</div>
<dl>
<dt>Pipeline</dt><dd>VACE Β· Video-conditioned</dd>
<dt>Downloads</dt><dd>β</dd>
<dt>Notes</dt><dd>Base model for Kijai/WanVideo_comfy</dd>
</dl>
<div class="model-card-actions">
<a href="https://huggingface.co/Wan-AI/Wan2.1-VACE-1.3B" target="_blank" rel="noopener">View on HF</a>
</div>
</div>
<div class="model-card">
<h3>Kijai/WanVideo_comfy_fp8_scaled</h3>
<div class="model-card-id">quantized variant</div>
<dl>
<dt>Pipeline</dt><dd>Text-to-Video</dd>
<dt>Notes</dt><dd>FP8 scaled β lower VRAM, small quality trade-off</dd>
</dl>
<div class="model-card-actions">
<a href="https://huggingface.co/Kijai/WanVideo_comfy_fp8_scaled" target="_blank" rel="noopener">View on HF</a>
</div>
</div>
`;
el.modelGrid.innerHTML = rows + extraCards;
}
/* ββ repo tree βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
async function loadRepoTree() {
try {
const files = await fetchJson(
`https://huggingface.co/api/models/${encodeURIComponent(MODEL_ID)}/tree/main`,
{ headers: { 'Accept': 'application/json' } }
);
const lines = files.slice(0, 60).map(f => {
const isDir = f.type === 'tree';
const kind = isDir ? 'π' : 'π';
const size = isDir ? '' : ` ${fmtBytes(f.size)}`;
const path = f.path;
const indent = path.split('/').length > 1 ? ' '.repeat(Math.min(path.split('/').length - 1, 3)) : '';
return `${indent}${kind} ${path}${size}`;
});
el.repoTree.textContent = lines.join('\n') || 'β (empty tree)';
} catch (err) {
console.warn('repo tree fetch failed:', err);
el.repoTree.textContent = 'β (could not load repo tree)';
}
}
/* ββ init ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */
async function init() {
await loadHeroStats();
// model grid + tree can load in parallel; delay slightly to let hero render
await defer(200);
try {
const info = await fetchJson(`${HF_API}/${encodeURIComponent(MODEL_ID)}`);
renderModelGrid(info);
} catch (err) {
console.warn('model grid fetch failed:', err);
el.modelGrid.innerHTML = `<div class="model-grid-placeholder">Could not load model info from the Hub. Check your network and try again.</div>`;
}
await loadRepoTree();
}
document.addEventListener('DOMContentLoaded', init);
|