Download budget.js from alphabell/MiniMax-Video-Budget: direct link, hf CLI and curl.
- Browser
- Download file 7.08 kB
-
https://huggingface.co/spaces/alphabell/MiniMax-Video-Budget/resolve/main/budget.js
- Command line
-
hf download hf://spaces/alphabell/MiniMax-Video-Budget/budget.js
-
curl -L -o budget.js https://huggingface.co/spaces/alphabell/MiniMax-Video-Budget/resolve/main/budget.js
7.08 kB
| ; | |
| const REVISION = '262ae6830934f3512211081b8a3f16425b93a239'; | |
| const MODEL = 'MiniMaxAI/MiniMax-M3.1-Flash'; | |
| const PATCH = 14; | |
| const MERGE = 2; | |
| const TEMPORAL = 2; | |
| const SPATIAL_UNIT = PATCH * MERGE; | |
| const DEFAULT_MAX_PIXELS = 768 * 28 * 28; | |
| const DEFAULT_MIN_PIXELS = 4 * 28 * 28; | |
| function validate(frames, height, width) { | |
| if (!Number.isSafeInteger(frames) || frames < 1 || frames > 240) return 'Enter 1 to 240 sampled frames.'; | |
| for (const [label, value] of [['height', height], ['width', width]]) { | |
| if (!Number.isSafeInteger(value) || value < 28 || value > 2016 || value % SPATIAL_UNIT !== 0) { | |
| return `Enter a processed ${label} from 28 to 2,016 in steps of 28 pixels.`; | |
| } | |
| } | |
| return ''; | |
| } | |
| function calculate(frames, height, width) { | |
| const error = validate(frames, height, width); | |
| if (error) throw new RangeError(error); | |
| const groups = Math.ceil(frames / TEMPORAL); | |
| const gridHeight = height / PATCH; | |
| const gridWidth = width / PATCH; | |
| const placeholdersPerGroup = (gridHeight * gridWidth) / (MERGE * MERGE); | |
| return { | |
| frames, height, width, groups, gridHeight, gridWidth, | |
| placeholdersPerGroup, | |
| placeholders: groups * placeholdersPerGroup, | |
| repeatedLastFrame: frames % TEMPORAL === 1, | |
| framePairs: Array.from({length: groups}, (_, index) => { | |
| const first = index * TEMPORAL + 1; | |
| const second = Math.min(first + 1, frames); | |
| return {group: index + 1, first, second, repeated: first === second, placeholders: placeholdersPerGroup}; | |
| }), | |
| outsideDefaultPixelRange: height * width < DEFAULT_MIN_PIXELS || height * width > DEFAULT_MAX_PIXELS, | |
| }; | |
| } | |
| function exportRecord(result) { | |
| return { | |
| schema_version: 1, | |
| model: MODEL, | |
| publisher_revision: REVISION, | |
| inputs: {sampled_frames: result.frames, processed_frame_height: result.height, processed_frame_width: result.width}, | |
| formula: 'ceil(sampled_frames / 2) * (processed_frame_height / 28) * (processed_frame_width / 28)', | |
| assumptions: ['Dimensions are after any resizing and are divisible by 28.', 'An odd final frame is repeated to complete the last two-frame group.', 'This counts vision placeholders only, not timestamp or wrapper tokens, total prompt tokens, memory, runtime or quality.'], | |
| result: {temporal_groups: result.groups, vision_placeholders_per_group: result.placeholdersPerGroup, total_vision_placeholders: result.placeholders, repeated_final_frame: result.repeatedLastFrame, groups: result.framePairs}, | |
| }; | |
| } | |
| if (typeof module !== 'undefined' && module.exports) module.exports = {calculate, validate, exportRecord, REVISION, MODEL}; | |
| if (typeof document !== 'undefined') { | |
| const number = new Intl.NumberFormat('en-US'); | |
| const form = document.querySelector('#budget-form'); | |
| const frameInput = document.querySelector('#frames'); | |
| const heightInput = document.querySelector('#height'); | |
| const widthInput = document.querySelector('#width'); | |
| const errorEl = document.querySelector('#error'); | |
| const resultEl = document.querySelector('#result'); | |
| const groupsEl = document.querySelector('#groups'); | |
| const exportButton = document.querySelector('#export'); | |
| const copyButton = document.querySelector('#copy'); | |
| const statusEl = document.querySelector('#status'); | |
| let current = null; | |
| function readQuery() { | |
| const query = new URLSearchParams(location.search); | |
| const parse = (name, fallback) => /^\d+$/.test(query.get(name) || '') ? Number(query.get(name)) : fallback; | |
| const frames = parse('frames', 16), height = parse('height', 672), width = parse('width', 672); | |
| if (!validate(frames, height, width)) { | |
| frameInput.value = frames; | |
| heightInput.value = height; | |
| widthInput.value = width; | |
| } | |
| } | |
| function render() { | |
| const frames = Number(frameInput.value), height = Number(heightInput.value), width = Number(widthInput.value); | |
| const error = validate(frames, height, width); | |
| errorEl.textContent = error; | |
| resultEl.hidden = Boolean(error); | |
| exportButton.disabled = Boolean(error); | |
| copyButton.disabled = Boolean(error); | |
| if (error) { current = null; return; } | |
| current = calculate(frames, height, width); | |
| document.querySelector('#total').textContent = number.format(current.placeholders); | |
| document.querySelector('#per-group').textContent = number.format(current.placeholdersPerGroup); | |
| document.querySelector('#group-count').textContent = number.format(current.groups); | |
| document.querySelector('#grid').textContent = `${current.gridHeight} × ${current.gridWidth} patches, merged 2 × 2`; | |
| document.querySelector('#padding').textContent = current.repeatedLastFrame | |
| ? `Frame ${frames} is repeated in the last group to complete a pair.` | |
| : 'No frame is repeated.'; | |
| document.querySelector('#range-warning').hidden = !current.outsideDefaultPixelRange; | |
| const visible = current.framePairs.length <= 12 | |
| ? current.framePairs | |
| : [...current.framePairs.slice(0, 11), current.framePairs.at(-1)]; | |
| groupsEl.replaceChildren(...visible.map(pair => { | |
| const card = document.createElement('li'); | |
| card.className = 'group-card'; | |
| if (pair.repeated) card.classList.add('repeated'); | |
| card.innerHTML = `<span class="group-index">Group ${pair.group}</span><strong>${pair.first} <span aria-hidden="true">+</span> ${pair.second}</strong><small>${pair.repeated ? 'Final frame repeated' : 'Two sampled frames'}</small>`; | |
| return card; | |
| })); | |
| document.querySelector('#group-overflow').textContent = current.framePairs.length > 12 | |
| ? `Showing the first 11 and final group of ${current.groups}. The JSON export includes every group.` | |
| : `Showing all ${current.groups} groups.`; | |
| const url = new URL(location.href); | |
| url.searchParams.set('frames', String(frames)); | |
| url.searchParams.set('height', String(height)); | |
| url.searchParams.set('width', String(width)); | |
| history.replaceState(null, '', url); | |
| } | |
| readQuery(); | |
| form.addEventListener('input', render); | |
| form.addEventListener('submit', event => event.preventDefault()); | |
| document.querySelectorAll('[data-preset]').forEach(button => button.addEventListener('click', () => { | |
| frameInput.value = button.dataset.preset; | |
| heightInput.value = 672; | |
| widthInput.value = 672; | |
| render(); | |
| frameInput.focus(); | |
| })); | |
| exportButton.addEventListener('click', () => { | |
| if (!current) return; | |
| const blob = new Blob([JSON.stringify(exportRecord(current), null, 2) + '\n'], {type: 'application/json'}); | |
| const link = document.createElement('a'); | |
| link.href = URL.createObjectURL(blob); | |
| link.download = `minimax-video-budget-${current.frames}frames.json`; | |
| link.click(); | |
| setTimeout(() => URL.revokeObjectURL(link.href), 1000); | |
| statusEl.textContent = 'JSON downloaded.'; | |
| }); | |
| copyButton.addEventListener('click', async () => { | |
| if (!current) return; | |
| try { await navigator.clipboard.writeText(location.href); statusEl.textContent = 'Share link copied.'; } | |
| catch { statusEl.textContent = 'Copy the page address to share this view.'; } | |
| }); | |
| render(); | |
| } | |