PAN2-Demo / index.html
Fast66908's picture
Upload folder using huggingface_hub
77f368b verified
Raw History Blame Contribute Delete
28.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PAN 2 · ComfyUI Demo &amp; Explorer</title>
<style>
:root{
--ink:#1c1e26; --muted:#666b7a; --line:#e6e8ef; --bg:#f7f8fb; --card:#fff;
--yellow:#ffd21e; --indigo:#5b4bd6; --indigo-dark:#4031ac; --green:#0f9d6e;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.6 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif}
a{color:var(--indigo-dark);text-decoration:none}
a:hover{text-decoration:underline}
header{background:#fff;border-bottom:1px solid var(--line);position:sticky;top:0;z-index:20}
.nav{max-width:1120px;margin:auto;padding:12px 22px;display:flex;align-items:center;gap:18px;flex-wrap:wrap}
.brand{font-weight:800;font-size:18px;letter-spacing:-.4px}
.brand b{background:var(--yellow);padding:2px 7px;border-radius:6px;margin-right:6px}
.nav nav{display:flex;gap:16px;margin-left:auto;flex-wrap:wrap;font-size:14px}
.wrap{max-width:1120px;margin:auto;padding:34px 22px 70px}
.hero{display:grid;grid-template-columns:1.05fr .95fr;gap:34px;align-items:center}
.pill{display:inline-block;background:#f0eeff;color:var(--indigo-dark);font-size:12px;font-weight:700;padding:5px 11px;border-radius:99px;letter-spacing:.3px}
h1{font-size:clamp(32px,5vw,52px);line-height:1.08;margin:16px 0 12px;letter-spacing:-1.8px}
h1 em{font-style:normal;color:var(--indigo)}
h2{font-size:26px;letter-spacing:-.7px;margin:0 0 6px}
h3{font-size:17px;margin:0 0 8px}
.lede{color:var(--muted);font-size:17px;margin:0 0 18px}
.badges{display:flex;gap:8px;flex-wrap:wrap;margin-bottom:20px}
.badge{border:1px solid var(--line);background:#fff;border-radius:8px;padding:5px 10px;font-size:12px;font-weight:600}
.btn,button{font:inherit;cursor:pointer;border:0;border-radius:9px;padding:10px 16px;font-weight:700}
.btn{display:inline-flex;align-items:center;gap:8px;background:var(--indigo);color:#fff}
.btn:hover{background:var(--indigo-dark);text-decoration:none}
.btn.secondary{background:#fff;color:var(--ink);border:1px solid var(--line)}
.btn.secondary:hover{background:#f1f2f7}
.media{background:#0d0f16;border-radius:16px;padding:10px;box-shadow:0 18px 40px rgba(20,20,40,.18)}
.media video{width:100%;display:block;border-radius:10px;background:#000}
.media .cap{color:#a8adbe;font-size:12px;padding:9px 4px 2px;display:flex;justify-content:space-between;gap:10px;flex-wrap:wrap}
section{margin-top:56px}
.sec-head{margin-bottom:20px}
.sec-head p{color:var(--muted);margin:4px 0 0;max-width:760px}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:20px}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:18px}
.tabs{display:flex;gap:6px;border-bottom:1px solid var(--line);margin-bottom:18px;flex-wrap:wrap}
.tab{background:none;border:0;border-bottom:3px solid transparent;border-radius:0;padding:9px 13px;color:var(--muted);font-weight:700}
.tab.active{color:var(--indigo-dark);border-bottom-color:var(--indigo)}
.pane{display:none}.pane.active{display:block}
label{display:block;font-size:12px;font-weight:800;text-transform:uppercase;letter-spacing:.5px;color:var(--muted);margin:12px 0 5px}
input,select,textarea{width:100%;padding:9px 11px;border:1px solid #d8dbe6;border-radius:9px;background:#fff;color:var(--ink);font:inherit}
input:focus,select:focus,textarea:focus{outline:2px solid #cfc8ff;border-color:var(--indigo)}
textarea{resize:vertical;min-height:70px}
.row{display:grid;grid-template-columns:repeat(2,1fr);gap:12px}
.row3{display:grid;grid-template-columns:repeat(3,1fr);gap:12px}
pre{background:#131722;color:#e6e9f5;border-radius:11px;padding:15px;overflow:auto;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;margin:10px 0 0;max-height:430px}
.k{color:#9ad4ff}.s{color:#b5e6a0}.n{color:#ffd28a}
.toolbar{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px;align-items:center}
.hint{font-size:12.5px;color:var(--muted);margin-top:8px}
.timeline{position:relative;padding-left:18px;margin-top:14px}
.timeline:before{content:"";position:absolute;left:4px;top:6px;bottom:6px;width:2px;background:#e1ddff}
.ev{position:relative;margin-bottom:12px;background:#fafaff;border:1px solid var(--line);border-radius:10px;padding:11px 13px}
.ev:before{content:"";position:absolute;left:-18px;top:17px;width:10px;height:10px;border-radius:50%;background:var(--indigo);border:2px solid #fff;box-shadow:0 0 0 2px #ded9ff}
.time{font:700 11px/1 ui-monospace,Menlo,monospace;color:var(--indigo-dark);letter-spacing:.4px}
.ev p{margin:6px 0 0;font-size:14px}
.tag{display:inline-block;background:#eef7f2;color:var(--green);border-radius:6px;padding:2px 7px;font-size:11px;font-weight:700;margin-top:7px}
.steps{counter-reset:s;display:grid;gap:12px}
.step{counter-increment:s;display:flex;gap:13px;align-items:flex-start}
.step:before{content:counter(s);flex:0 0 26px;height:26px;border-radius:50%;background:var(--yellow);display:grid;place-items:center;font-weight:800;font-size:13px}
.step p{margin:2px 0;color:var(--muted)}
.flow{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:16px 0}
.flow span{background:#fff;border:1px solid var(--line);border-radius:9px;padding:8px 12px;font-weight:700;font-size:13px}
.flow i{color:var(--muted);font-style:normal}
.files{font:12.5px/1.7 ui-monospace,Menlo,monospace;background:#fafaff;border:1px solid var(--line);border-radius:10px;padding:12px 14px;white-space:pre-wrap}
.note{border-left:4px solid var(--yellow);background:#fffdf2;padding:11px 14px;border-radius:0 9px 9px 0;font-size:13.5px;margin-top:14px}
footer{border-top:1px solid var(--line);background:#fff;padding:24px 22px;color:var(--muted);font-size:13px}
footer .wrap{padding:0}
@media(max-width:820px){.hero,.grid2{grid-template-columns:1fr}.row3{grid-template-columns:1fr}}
</style>
</head>
<body>
<header>
<div class="nav">
<div class="brand"><b>🌍</b>PAN 2 <span style="color:#999;font-weight:500">/ Comfy-Org</span></div>
<nav>
<a href="#preview">Preview</a><a href="#captions">Captions</a><a href="#compose">Compose</a>
<a href="#comfyui">ComfyUI</a><a href="#how">How it works</a>
</nav>
</div>
</header>
<div class="wrap">
<div class="hero" id="preview">
<div>
<span class="pill">GENERAL-PURPOSE WORLD MODEL</span>
<h1>Simulate what happens <em>next.</em></h1>
<p class="lede">PAN 2 takes an observation and an action in text — optionally a first frame — and renders the predicted outcome as video. This explorer is built around the repackaged ComfyUI checkpoints in <a href="https://huggingface.co/Comfy-Org/PAN2">Comfy-Org/PAN2</a>.</p>
<div class="badges">
<span class="badge">29B-parameter MMDiT</span><span class="badge">704×1248 · 24 fps</span>
<span class="badge">up to 20 s</span><span class="badge">T2V + I2V</span><span class="badge">Apache 2.0</span>
</div>
<div class="toolbar">
<a class="btn" href="#captions">Explore captions ↓</a>
<a class="btn secondary" href="https://huggingface.co/Comfy-Org/PAN2">Model repo ↗</a>
<a class="btn secondary" href="https://github.com/ifm-ai/PAN2">GitHub ↗</a>
</div>
</div>
<div class="media">
<video id="demoVideo" controls loop playsinline preload="none"
poster="https://huggingface.co/IFM/PAN2/resolve/main/assets/video_preview.gif">
<source src="https://huggingface.co/IFM/PAN2/resolve/main/assets/video.mp4" type="video/mp4">
</video>
<div class="cap"><span>Official PAN 2 sample · click play to stream (~80 MB)</span>
<a href="https://huggingface.co/IFM/PAN2/resolve/main/assets/video.mp4">Open original ↗</a></div>
</div>
</div>
<section id="captions">
<div class="sec-head">
<h2>1 · Think in world-state captions</h2>
<p>PAN 2's diffusion backbone is conditioned on <strong>structured, time-grounded descriptions</strong> — not raw prompts. Pick an example to see how a simple request becomes timed events, actions bound to actors and camera motion.</p>
</div>
<div class="card">
<div class="tabs" id="exampleTabs">
<button class="tab active" data-ex="fox">🦊 Red fox in snow</button>
<button class="tab" data-ex="mug">☕ Mug spilling</button>
</div>
<div class="grid2">
<div>
<label>Original request</label>
<div id="origRequest" class="files"></div>
<label>Structured caption (JSON)</label>
<pre id="captionJson"></pre>
<div class="toolbar">
<button class="btn secondary" id="copyCaption">Copy JSON</button>
<button class="btn secondary" id="downloadCaption">Download .json</button>
<span class="hint" id="tokenHint"></span>
</div>
</div>
<div>
<label>Event timeline · 0–5 s</label>
<div class="timeline" id="timeline"></div>
<div class="note">💡 Want to turn your own free-text idea into a caption like this? Use the <a href="https://github.com/ifm-ai/PAN2/blob/main/inference/pan-prompt-rewriter/SKILL.md">PAN 2 conceptual reasoner skill</a> or <code>inference/prompts_rewritter.py</code>. Captions are token-limited: soft cap 1,480, hard cap 1,536.</div>
</div>
</div>
</div>
</section>
<section id="compose">
<div class="sec-head">
<h2>2 · Compose a caption</h2>
<p>A lightweight template builder for the caption schema — fill in the fields, then copy the result into your ComfyUI text-encoder node or a PAN 2 generation script. This is a template, not the LLM-based reasoner.</p>
</div>
<div class="card">
<div class="row3">
<div><label>Subject</label><input id="cSubject" value="A ceramic mug"></div>
<div><label>Attributes</label><input id="cAttrs" value="Glossy white ceramic mug filled with dark coffee"></div>
<div><label>Setting / initial frame</label><input id="cScene" value="An oak kitchen table with soft morning window light"></div>
</div>
<div class="row3">
<div><label>Action</label><input id="cAction" value="tips over and spills coffee across the table"></div>
<div><label>Camera</label><select id="cCamera"><option>static</option><option>track_right</option><option>track_left</option><option>push_in</option><option>pull_out</option><option>pan_right</option><option>handheld</option></select></div>
<div><label>Duration (seconds)</label><input id="cDuration" type="number" min="1" max="20" step="0.5" value="5"></div>
</div>
<div class="row">
<div><label>Lighting &amp; style</label><input id="cStyle" value="Photorealistic close-up, soft natural window light, shallow depth of field"></div>
<div><label>Video quality</label><input id="cQuality" value="Sharp ceramic and wood detail, realistic liquid flow and reflections"></div>
</div>
<div class="toolbar"><button class="btn" id="buildCaption">Build caption JSON</button><button class="btn secondary" id="copyBuilt">Copy</button></div>
<pre id="builtJson"></pre>
</div>
</section>
<section id="comfyui">
<div class="sec-head">
<h2>3 · ComfyUI checkpoint builder</h2>
<p><code>Comfy-Org/PAN2</code> repackages the same weights as single-file checkpoints for ComfyUI. Choose a precision profile to get the exact folder tree, download commands and a starter API-format workflow.</p>
</div>
<div class="card">
<div class="row3">
<div><label>Diffusion model</label><select id="fUnét"></select></div>
<div><label>Text encoder</label><select id="fClip"></select></div>
<div><label>VAE</label><select id="fVae"><option>wan2.2_vae.safetensors</option></select></div>
</div>
<div class="row3">
<div><label>Width</label><input id="fWidth" type="number" value="832" step="16"></div>
<div><label>Height</label><input id="fHeight" type="number" value="480" step="16"></div>
<div><label>Frames (4n+1)</label><input id="fFrames" type="number" value="121" step="4"></div>
</div>
<div class="row3">
<div><label>Denoising steps</label><input id="fSteps" type="number" value="50"></div>
<div><label>Guidance scale</label><input id="fGuidance" type="number" value="2.5" step="0.1"></div>
<div><label>Seed</label><input id="fSeed" type="number" value="123"></div>
</div>
<div class="tabs" style="margin-top:18px">
<button class="tab active" data-out="files">Folder tree</button>
<button class="tab" data-out="downloads">Download commands</button>
<button class="tab" data-out="workflow">Workflow JSON</button>
</div>
<div class="pane active" data-pane="files"><div class="files" id="outFiles"></div></div>
<div class="pane" data-pane="downloads"><pre id="outDownloads"></pre></div>
<div class="pane" data-pane="workflow"><pre id="outWorkflow"></pre></div>
<div class="toolbar">
<button class="btn secondary" id="copyOut">Copy current</button>
<button class="btn secondary" id="downloadWorkflow">Download workflow JSON</button>
<span class="hint">Workflow is a starting scaffold using standard ComfyUI nodes; custom PAN 2 node packs may differ.</span>
</div>
</div>
</section>
<section id="how">
<div class="sec-head"><h2>4 · How PAN 2 works</h2>
<p>PAN 2 follows Generative Latent Prediction (<a href="https://arxiv.org/abs/2507.05169">Critique of World Models</a>): a language model plans <em>what</em> happens, a diffusion model renders <em>how</em> it looks.</p></div>
<div class="card">
<div class="flow"><span>Observation + action</span><i>→</i><span>Conceptual reasoner</span><i>→</i><span>Structured caption</span><i>→</i><span>29B MMDiT</span><i>→</i><span>Wan 2.2 VAE</span><i>→</i><span>Video</span></div>
<div class="steps">
<div class="step"><div><h3>Conceptual reasoning</h3><p>An instruction-tuned LLM rewrites a free-text request into a time-grounded world-state caption with events, actors and camera motion.</p></div></div>
<div class="step"><div><h3>Perceptual prediction</h3><p>A frozen Qwen3.5-9B text encoder conditions a 29B-parameter MMDiT trained from scratch on hundreds of millions of annotated videos. It predicts video latents at 704×1248.</p></div></div>
<div class="step"><div><h3>Decoding &amp; safety</h3><p>The Wan 2.2 VAE decodes latents into frames. The authors recommend the separate <code>pan2-guardrail</code> (Qwen3Guard-Gen-4B on requests, Q16 on generated frames).</p></div></div>
</div>
<div class="note">⚠️ PAN 2 predicts possible outcomes — it does not record real events. Don't use its outputs as evidence, for deepfakes, or for safety-critical decisions. Disclose AI-generated video where it could mislead.</div>
</div>
</section>
</div>
<footer><div class="wrap">
Demo explorer by <strong>Fast66908</strong> · Model by <a href="https://huggingface.co/IFM/PAN2">Institute of Foundation Models, MBZUAI</a> · ComfyUI repackaging by <a href="https://huggingface.co/Comfy-Org/PAN2">Comfy-Org</a> · Apache 2.0<br>
Video generation needs GPU hardware; this Space is a free Static explorer. A Gradio/ZeroGPU generation app is prepared for eligible hosts.
</div></footer>
<script>
const EXAMPLES = {
fox: {
request: "A red fox trots through fresh snow in a pine forest at dawn, powder lifting from its paws as the camera tracks alongside.",
caption: {
video_style:"Photorealistic wildlife cinematography in one uninterrupted continuous shot.",
lighting:"Low golden dawn sunlight from the left through the pines, long blue shadows across the snow, warm rim light on the fox's fur and sparkling backlit snow powder.",
perspective_view:"Low eye-level side view from about two meters away, the camera tracking right at the fox's pace, keeping it in profile near the center of the frame.",
subjects_lifecycle:[{subject_id:"<|Subject1|>",display_name:"Red fox",subject_attribute:"Adult red fox with a thick russet winter coat, white chest and muzzle, black legs and ear backs, and a full bushy tail with a white tip."}],
init_frame_visual_description:"A red fox stands in profile facing right in deep, fresh, untracked snow in a pine forest at dawn, one front paw lifted mid-step. Snow-laden pine trunks rise behind it at varied depths, the nearer ones softly out of focus. The low sun from the left casts long shadows across the smooth snow and lights the edge of the fox's fur. A faint trail of paw prints leads back from the fox toward the left edge of the frame.",
events:[
{event_index:0,time_range_sec:"0 to 2.5",event_description:"The fox sets off at a steady trot to the right, its paws sinking into the soft snow and kicking up small bursts of powder that glitter in the low sunlight. The camera tracks alongside at the same speed, so the fox stays near the center while the pine trunks slide past behind it.",camera_motion:[{time_range_sec:"0 to 2.5",camera_motion:["track_right"]}],contained_actions:[{time_range_sec:"0 to 2.5",action:"<|Subject1|> trots rightward through the deep snow, lifting each paw high and throwing up small sprays of powder."}]},
{event_index:1,time_range_sec:"2.5 to 5",event_description:"The fox keeps trotting, turns its head briefly toward the camera with ears pricked, then looks ahead again. A fresh line of paw prints stretches behind it and drifting powder settles in the sunbeams as the camera continues to track right beside it.",camera_motion:[{time_range_sec:"2.5 to 5",camera_motion:["track_right"]}],contained_actions:[{time_range_sec:"2.5 to 3.6",action:"<|Subject1|> glances toward the camera with ears pricked while continuing to trot."},{time_range_sec:"3.6 to 5",action:"<|Subject1|> faces forward again and trots on, its tail streaming level behind it."}]}
],
quality:{video_quality:"Sharp fur detail and crisp snow texture, with natural motion blur on the flying powder.",text_logos_overlays:null,artifacts:null}
}
},
mug: {
request: "A ceramic mug tips over on a wooden kitchen table and spills coffee across the surface and over the edge.",
caption: {
video_style:"Photorealistic domestic close-up in one uninterrupted continuous shot.",
lighting:"Soft morning daylight from a window on the left, gentle highlights on the glazed mug and the wet coffee surface, warm wood tones and soft shadows to the right.",
perspective_view:"Locked-off three-quarter view from slightly above table height, about one meter away, framing the mug and the table edge on the right.",
subjects_lifecycle:[{subject_id:"<|Subject1|>",display_name:"Ceramic coffee mug",subject_attribute:"Glossy white ceramic mug with a round handle, filled nearly to the rim with dark black coffee."}],
init_frame_visual_description:"A white ceramic mug of black coffee stands upright near the right edge of a warm oak kitchen table, already tilted slightly as it begins to lose balance. The table's front edge runs across the lower right of the frame, with the tiled kitchen floor softly out of focus below it. The table surface is clean and dry, its wood grain running left to right. Window light from the left catches the rim of the mug and the coffee's dark surface.",
events:[
{event_index:0,time_range_sec:"0 to 1.2",event_description:"The mug tips over onto its side with a small clatter, and coffee surges out of its mouth onto the wooden tabletop in a dark wave.",camera_motion:[{time_range_sec:"0 to 1.2",camera_motion:["static"]}],contained_actions:[{time_range_sec:"0 to 0.7",action:"<|Subject1|> tilts past its balance point and falls onto its side on the table."},{time_range_sec:"0.5 to 1.2",action:"<|Subject1|> spills its coffee out across the tabletop in a sudden dark wave."}]},
{event_index:1,time_range_sec:"1.2 to 5",event_description:"The puddle spreads across the wood in a widening glossy sheet and reaches the table's front edge. Coffee begins to drip over the edge in thin streams and drops that fall toward the floor, while the empty mug lies still on its side.",camera_motion:[{time_range_sec:"1.2 to 5",camera_motion:["static"]}],contained_actions:[{time_range_sec:"1.2 to 5",action:"<|Subject1|> lies still on its side as the last coffee trickles from its rim."}]}
],
quality:{video_quality:"Crisp ceramic and wood detail with realistic liquid flow and reflections.",text_logos_overlays:null,artifacts:null}
}
}
};
const FILES = {
unet:{ "pan2_bf16.safetensors":"diffusion_models/pan2_bf16.safetensors","pan2_int8_convrot.safetensors":"diffusion_models/pan2_int8_convrot.safetensors" },
clip:{ "qwen3.5_9b_bf16.safetensors":"text_encoders/qwen3.5_9b_bf16.safetensors","qwen3.5_9b_int8_convrot.safetensors":"text_encoders/qwen3.5_9b_int8_convrot.safetensors" },
vae:{ "wan2.2_vae.safetensors":"vae/wan2.2_vae.safetensors" }
};
const $ = s => document.querySelector(s);
const $$ = s => [...document.querySelectorAll(s)];
let currentExample = 'fox', currentBuilt = '';
function esc(s){return String(s).replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]))}
function highlight(obj){
const raw = typeof obj === 'string' ? obj : JSON.stringify(obj,null,2);
return esc(raw).replace(/(&quot;.*?&quot;)(\s*:)?/g,(m,str,colon)=>
`<span class="k">${str}</span>${colon?':':''}`)
.replace(/:\s*(&quot;.*?&quot;)/g, (m,str)=> ': <span class="s">'+str+'</span>')
.replace(/:\s*(-?\d+(?:\.\d+)?|true|false|null)/g,(m,n)=>': <span class="n">'+n+'</span>');
}
function showExample(key){
currentExample = key;
const ex = EXAMPLES[key];
$('#origRequest').textContent = ex.request;
$('#captionJson').innerHTML = highlight(ex.caption);
$('#tokenHint').textContent = '~'+Math.ceil(JSON.stringify(ex.caption).length/3.5)+' est. tokens';
$('#timeline').innerHTML = ex.caption.events.map(e=>{
const acts = e.contained_actions.map(a=>`<p>▸ ${esc(a.action.replace(/<\|Subject1\|>/g,'the subject'))} <span class="time">${esc(a.time_range_sec)}</span></p>`).join('');
const cams = e.camera_motion.flatMap(c=>c.camera_motion).join(', ');
return `<div class="ev"><div class="time">${esc(e.time_range_sec)}</div><p>${esc(e.event_description)}</p>${acts}<span class="tag">Camera: ${esc(cams)}</span></div>`;
}).join('');
}
$('#exampleTabs').addEventListener('click',e=>{
const b=e.target.closest('.tab'); if(!b)return;
$$('#exampleTabs .tab').forEach(t=>t.classList.toggle('active',t===b)); showExample(b.dataset.ex);
});
function download(name,text,type='application/json'){
const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([text],{type}));
a.download=name; a.click(); setTimeout(()=>URL.revokeObjectURL(a.href),1000);
}
async function copy(text){
try{ await navigator.clipboard.writeText(text); }
catch(e){ const t=document.createElement('textarea');t.value=text;document.body.appendChild(t);t.select();document.execCommand('copy');t.remove(); }
}
$('#copyCaption').onclick=()=>copy(JSON.stringify(EXAMPLES[currentExample].caption,null,2));
$('#downloadCaption').onclick=()=>download('pan2-'+currentExample+'-caption.json',JSON.stringify(EXAMPLES[currentExample].caption,null,2));
showExample('fox');
$('#buildCaption').onclick=()=>{
const subject=$('#cSubject').value.trim(), attrs=$('#cAttrs').value.trim(), scene=$('#cScene').value.trim();
const action=$('#cAction').value.trim(), cam=$('#cCamera').value, dur=Math.max(1,Math.min(20,+$('#cDuration').value||5));
const half=+(dur/2).toFixed(1);
const cap={
video_style:$('#cStyle').value.trim(),
lighting:"Natural lighting appropriate to the scene, with clear readable detail.",
perspective_view:"Single continuous shot with a "+cam.replace(/_/g,' ')+" camera movement.",
subjects_lifecycle:[{subject_id:"<|Subject1|>",display_name:subject,subject_attribute:attrs}],
init_frame_visual_description:scene+" The scene is shown in one continuous shot at the start of the clip.",
events:[
{event_index:0,time_range_sec:`0 to ${half}`,event_description:`${subject} ${action}.`,camera_motion:[{time_range_sec:`0 to ${half}`,camera_motion:[cam]}],contained_actions:[{time_range_sec:`0 to ${half}`,action:`<|Subject1|> ${action}.`}]},
{event_index:1,time_range_sec:`${half} to ${dur}`,event_description:`The action continues and its consequences become visible while the ${cam.replace(/_/g,' ')} camera keeps the subject in view.`,camera_motion:[{time_range_sec:`${half} to ${dur}`,camera_motion:[cam]}],contained_actions:[{time_range_sec:`${half} to ${dur}`,action:`<|Subject1|> continues: ${action}.`}]}
],
quality:{video_quality:$('#cQuality').value.trim(),text_logos_overlays:null,artifacts:null}
};
currentBuilt=JSON.stringify(cap,null,2);
$('#builtJson').innerHTML=highlight(currentBuilt);
};
$('#copyBuilt').onclick=()=>{ if(!currentBuilt)return copy(''); copy(currentBuilt); };
$('#buildCaption').click();
(function initBuilder(){
for(const [sel,map] of [['#fUnét',FILES.unet],['#fClip',FILES.clip]]){
const el=$(sel); el.innerHTML=Object.keys(map).map(k=>`<option>${k}</option>`).join('');
}
function num(id){return Math.max(0,+$('#'+id).value||0)}
function state(){
return {
unet:FILES.unet[$('#fUnét').value], clip:FILES.clip[$('#fClip').value], vae:FILES.vae[$('#fVae').value],
w:num('fWidth'),h:num('fHeight'),f:num('fFrames'),s:num('fSteps'),g:+$('#fGuidance').value||2.5,seed:num('fSeed')
};
}
function tree(s){
return `ComfyUI/\n└── models/\n ├── diffusion_models/\n │ └── ${s.unet}\n ├── text_encoders/\n │ └── ${s.clip}\n └── vae/\n └── ${s.vae}`;
}
function downloads(s){
return [
'# From https://huggingface.co/Comfy-Org/PAN2',
`hf download Comfy-Org/PAN2 ${s.unet} --local-dir ComfyUI/models/diffusion_models`,
`hf download Comfy-Org/PAN2 ${s.clip} --local-dir ComfyUI/models/text_encoders`,
`hf download Comfy-Org/PAN2 ${s.vae} --local-dir ComfyUI/models/vae`,
'',
'# Or download the whole repo (~large — make sure you have disk space)',
'hf download Comfy-Org/PAN2 --local-dir ./Comfy-Org-PAN2'
].join('\n');
}
function workflow(s){
const wf={
"1":{"class_type":"UNETLoader","inputs":{"unet_name":s.unet,"weight_dtype":"default"}},
"2":{"class_type":"CLIPLoader","inputs":{"clip_name":s.clip,"type":"wan"}},
"3":{"class_type":"VAELoader","inputs":{"vae_name":s.vae}},
"4":{"class_type":"CLIPTextEncode","inputs":{"text":"Paste a PAN 2 structured caption JSON here (see section 1).","clip":["2",0]}},
"5":{"class_type":"CLIPTextEncode","inputs":{"text":"","clip":["2",0]}},
"6":{"class_type":"EmptyLatentImage","inputs":{"width":s.w,"height":s.h,"batch_size":s.f}},
"7":{"class_type":"KSampler","inputs":{"seed":s.seed,"steps":s.s,"cfg":s.g,"sampler_name":"euler","scheduler":"simple","positive":["4",0],"negative":["5",0],"latent_image":["6",0],"denoise":1}},
"8":{"class_type":"VAEDecode","inputs":{"samples":["7",0],"vae":["3",0]}},
"9":{"class_type":"SaveAnimatedWEBP","inputs":{"images":["8",0],"filename_prefix":"PAN2","fps":24,"lossless":false,"quality":90,"method":"default"}}
};
return JSON.stringify(wf,null,2);
}
function refresh(){
const s=state();
$('#outFiles').textContent=tree(s);
$('#outDownloads').textContent=downloads(s);
$('#outWorkflow').textContent=highlight(workflow(s));
window._wf=workflow(s);
}
$$('#comfyui input, #comfyui select').forEach(el=>el.addEventListener('input',refresh));
$$('#comfyui [data-out]').forEach(b=>b.addEventListener('click',()=>{
$$('#comfyui [data-out]').forEach(t=>t.classList.toggle('active',t===b));
$$('#comfyui [data-pane]').forEach(p=>p.classList.toggle('active',p.dataset.pane===b.dataset.out));
}));
$('#copyOut').onclick=()=>{
const active=$('#comfyui [data-out].active').dataset.out;
copy(active==='files'?tree(state()):active==='downloads'?downloads(state()):workflow(state()));
};
$('#downloadWorkflow').onclick=()=>download('pan2-comfyui-workflow.json',workflow(state()));
refresh();
})();
</script>
</body>
</html>