/* Human pass rates and separately identified automatic likeness scores. */ const D = window.BUFO_BENCH || {}; const $ = id => document.getElementById(id); const esc = value => String(value ?? '').replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[char])); const models = Array.isArray(D.models) ? D.models : []; const tasks = Array.isArray(D.tasks) ? D.tasks : []; const attemptTotal = 10; const ratings = new Set(['bufo', 'close', 'not_bufo']); const modelById = id => models.find(model => model.id === id); const taskFor = (model, id) => (model?.tasks || []).find(task => task.id === id); const specFor = id => tasks.find(task => task.id === id) || {}; const hasImage = task => typeof task?.img === 'string' && task.img.length > 0; const isRating = rating => ratings.has(rating); function numberField(value) { return typeof value === 'number' && Number.isFinite(value) ? value : null; } function taskPendingCount(model) { const field = numberField(model?.pending_count); if (field !== null) return field; return (model?.tasks || []).filter(task => !isRating(task.rating) && task.status !== 'recorded_failure' && task.status !== 'unattempted').length; } function taskUnattemptedCount(model) { const field = numberField(model?.unattempted_count); if (field !== null) return field; return (model?.tasks || []).filter(task => task.status === 'unattempted').length; } function taskReviewedCount(model) { const field = numberField(model?.reviewed); if (field !== null) return field; return (model?.tasks || []).filter(task => isRating(task.rating)).length; } function scoreFor(model) { const score = model?.score; return Number.isInteger(score) && score >= 0 && score <= attemptTotal ? score : null; } function attemptsVerified(model) { return model?.attempts_verified === true || model?.attempts_verified === attemptTotal; } function isRanked(model) { return scoreFor(model) !== null && attemptsVerified(model) && taskPendingCount(model) === 0 && taskUnattemptedCount(model) === 0; } function defaultModel() { return models.find(model => (model.tasks || []).some(hasImage)) || models[0]; } function rankedModels() { return models.filter(isRanked).sort((a, b) => scoreFor(b) - scoreFor(a) || String(a.id).localeCompare(String(b.id))); } function rankOf(model) { const score = scoreFor(model); return 1 + rankedModels().filter(candidate => scoreFor(candidate) > score).length; } function isTied(model) { const score = scoreFor(model); return rankedModels().some(candidate => candidate.id !== model.id && scoreFor(candidate) === score); } function scoreText(model) { const score = scoreFor(model); if (!isRanked(model) || score === null) return '—Coverage pending'; const ability = score > 0 ? 'Demonstrated' : 'No passing samples'; return `${score} / 10${score * 10}% pass rate · recognizes Bufo${ability}`; } function automaticScoreText(item, compact = false) { const score = numberField(item?.automatic_score); if (score === null) return ''; return `
Auto likeness: ${score.toFixed(1)} / 100${compact ? '' : '
Experimental · Bufo Score v1'}
${unranked.length} model${unranked.length === 1 ? '' : 's'} remain visible without a rank. Missing review is not a zero. Open a row to inspect its images.
` : ''; } function modelCostText(model) { const cost = finiteCost(model); if (cost !== null) return `${model.cost_estimated ? '≈ ' : ''}${usd(cost)} / image`; return typeof model?.cost_rate_label === 'string' && model.cost_rate_label.trim() ? model.cost_rate_label : 'not recorded'; } function modelPassCostText(model) { const cost = costPerPass(model); return cost === null ? 'not recorded' : `${model.cost_estimated ? '≈ ' : ''}${usd(cost)} / passing Bufo`; } function pageUrl(kind, params) { const url = new URL(location.href); url.search = ''; url.hash = kind; Object.entries(params).forEach(([key, value]) => { if (value !== undefined && value !== null && value !== '') url.searchParams.set(key, value); }); return url; } function setUrl(url) { history.pushState({}, '', url); } function showModel(id, update = true) { const model = modelById(id) || defaultModel(); if (!model) return; $('model-select').value = model.id; renderGallery(); if (update) { setUrl(pageUrl('gallery', { model: model.id, g_task: $('task-select').value })); $('gallery').scrollIntoView({ behavior: 'smooth', block: 'start' }); } } function renderGallery() { const model = modelById($('model-select').value) || defaultModel(); if (!model) { $('model-heading').innerHTML = 'No model run has arrived yet.
'; $('gallery-images').innerHTML = 'There are no images to inspect yet.
'; return; } const rate = isRanked(model) ? `Human pass rate: ${scoreFor(model)} / ${attemptTotal} · ${scoreFor(model) * 10}% · recognizes Bufo` : 'Human pass rate: coverage pending'; const configuration = typeof model.configuration_note === 'string' && model.configuration_note.trim() ? `${esc(model.configuration_note)}
` : ''; $('model-heading').innerHTML = `${rate}
${esc(statusText(model))}
${configuration}${esc(taskStatus(task))}
${esc(taskPrompt(task))}
No task matches that filter.
'; } function openImage(id) { const model = modelById($('model-select').value); const task = taskFor(model, id); if (!hasImage(task)) return; $('full-image').src = task.img; $('full-image').alt = taskTitle(task); $('image-caption').innerHTML = `${esc(model.name || model.id)} · ${esc(taskTitle(task))} · ${taskLabel(task)}`; $('image-dialog').showModal(); } function requestedMatch() { const query = new URL(location.href).searchParams; const a = modelById(query.get('a')); const b = modelById(query.get('b')); const task = query.get('task'); if (a && b && a !== b && hasImage(taskFor(a, task)) && hasImage(taskFor(b, task))) return { a, b, task }; return null; } function eligibleTasks() { return tasks.filter(spec => models.filter(model => hasImage(taskFor(model, spec.id))).length >= 2); } function recordKey(a, b, task) { return JSON.stringify([[a.id, b.id].sort(), task]); } let votes = {}; let storageAvailable = true; let match = null; let revealed = false; let choice = null; let lastMatch = ''; const storageKey = `bufo-picks-${D.method?.version || 'human-benchmark-v1'}`; try { const saved = JSON.parse(localStorage.getItem(storageKey) || '{}'); if (saved && typeof saved === 'object' && !Array.isArray(saved)) votes = saved; } catch { storageAvailable = false; } function updatePickCount() { $('your-picks').textContent = storageAvailable ? `${Object.keys(votes).length} vote${Object.keys(votes).length === 1 ? '' : 's'} saved in this browser` : 'Votes are not saved in this browser'; } function renderEmptyBattle() { $('battle-task').textContent = 'No image pair yet'; $('battle-options').innerHTML = 'We need two returned images for the same task before a blind matchup can begin.
'; $('battle-coverage').textContent = ''; $('tie').hidden = true; $('share-battle').hidden = true; $('next-battle').textContent = 'Try again →'; } function deal(initial = false) { const requested = initial ? requestedMatch() : null; if (requested) match = requested; else { const choices = eligibleTasks(); if (!choices.length) { match = null; renderEmptyBattle(); return; } for (let attempt = 0; attempt < 10; attempt += 1) { const task = choices[Math.floor(Math.random() * choices.length)].id; const candidates = models.filter(model => hasImage(taskFor(model, task))); const a = candidates[Math.floor(Math.random() * candidates.length)]; const remaining = candidates.filter(model => model !== a); const b = remaining[Math.floor(Math.random() * remaining.length)]; const candidate = { a, b, task }; match = candidate; if (recordKey(a, b, task) !== lastMatch || candidates.length < 3) break; } } lastMatch = recordKey(match.a, match.b, match.task); revealed = false; choice = null; renderMatch(); if (!initial) setUrl(pageUrl('battle', { a: match.a.id, b: match.b.id, task: match.task })); } function renderMatch() { if (!match) return; const a = taskFor(match.a, match.task); const b = taskFor(match.b, match.task); $('battle-task').textContent = taskTitle(a); $('battle-coverage').textContent = revealed ? 'Names and labels revealed' : 'Same prompt · names hidden'; $('battle-options').innerHTML = [a, b].map((task, index) => { const model = index ? match.b : match.a; const label = revealed ? taskLabel(task) : ''; const name = revealed ? `${esc(model.name || model.id)}` : `Pick frog ${index ? 'B' : 'A'} →`; const status = revealed ? `${esc(taskStatus(task))}` : ''; return ``; }).join(''); $('tie').hidden = revealed; $('share-battle').hidden = !revealed; $('next-battle').textContent = 'Another pair →'; $('battle-result').textContent = revealed ? choice === 'tie' ? 'A tie. Your vote stays local and does not affect the benchmark.' : `You picked ${choice === 0 ? match.a.name || match.a.id : match.b.name || match.b.id}. Your vote stays local and does not affect the benchmark.` : ''; } function pick(value) { if (!match || revealed) return; choice = value; revealed = true; votes[lastMatch] = { pick: value === 'tie' ? 'tie' : value === 0 ? match.a.id : match.b.id }; try { localStorage.setItem(storageKey, JSON.stringify(votes)); } catch { storageAvailable = false; } updatePickCount(); renderMatch(); $('next-battle').focus(); } async function share(url, text) { $('share-status').textContent = ''; $('share-fallback').hidden = true; if (typeof navigator !== 'undefined' && navigator.share) { try { await navigator.share({ title: 'Bufo Benchmark', text, url: String(url) }); $('share-status').textContent = 'Shared.'; return; } catch (error) { if (error?.name === 'AbortError') return; } } try { if (!navigator.clipboard?.writeText) throw new Error('Clipboard unavailable'); await navigator.clipboard.writeText(String(url)); $('share-status').textContent = 'Link copied. Send it to someone with frog opinions.'; } catch { $('share-fallback').hidden = false; $('share-fallback').value = String(url); $('share-fallback').focus(); $('share-fallback').select(); $('share-status').textContent = 'Copy this link to share.'; } } $('board-sort').onchange = renderBoard; $('min-score').oninput = renderBoard; $('clear-filter').onclick = () => { $('min-score').value = '0'; renderBoard(); }; $('board').onclick = $('unranked').onclick = event => { const button = event.target.closest('[data-model]'); if (button) showModel(button.dataset.model); }; $('model-select').innerHTML = models.length ? models.map(model => ``).join('') : ''; $('task-select').innerHTML = '' + tasks.map(task => ``).join(''); $('model-select').onchange = () => showModel($('model-select').value); $('task-select').onchange = () => { renderGallery(); setUrl(pageUrl('gallery', { model: $('model-select').value, g_task: $('task-select').value })); }; $('gallery-images').onclick = event => { const button = event.target.closest('[data-image]'); if (button) openImage(button.dataset.image); }; $('close-image').onclick = () => $('image-dialog').close(); $('battle-options').onclick = event => { const button = event.target.closest('[data-choice]'); if (button) pick(Number(button.dataset.choice)); }; $('tie').onclick = () => pick('tie'); $('next-battle').onclick = () => deal(); $('share-battle').onclick = () => { if (match) share(pageUrl('battle', { a: match.a.id, b: match.b.id, task: match.task }), 'Which frog looks more like Bufo? Compare this blind matchup.'); }; function readLocation() { const query = new URL(location.href).searchParams; $('model-select').value = modelById(query.get('model'))?.id || defaultModel()?.id || ''; $('task-select').value = tasks.some(task => task.id === query.get('g_task')) ? query.get('g_task') : ''; renderGallery(); deal(true); } window.addEventListener('popstate', readLocation); $('method-text').textContent = 'Every model gets ten fixed prompts. People label each returned image as Bufo, Close, or Not Bufo. The public pass rate is Bufo labels divided by ten: it measures how often this run recognizes Bufo. These human labels are the source of truth here and can help calibrate future judging.'; $('method-version').textContent = 'Human benchmark v1 · ten samples per model, a useful snapshot rather than a definitive claim about every generation · visitor votes never affect the result.'; if (D.automatic_judging) { $('method-text').textContent += ' Automatic likeness is a separate 0–100 score: ' + D.automatic_judging.description; $('method-version').textContent += ' Automatic judge: ' + D.automatic_judging.version + ' (experimental).'; } updateCoverage(); updatePickCount(); renderBoard(); readLocation();