Spaces:
Running
Running
| import{r as ze}from"./index-CMkL1IIy.js";import{r as Ye}from"./index-CiOmdJeW.js";import{c as je}from"./client-CiuGHKKk.js";import{b as Ve}from"./triposplat-DC9N7LT1.js";import{qualifyGaussianSceneStructure as We,qualifyGaussianViewer as Ke}from"./e2eLabQualification-DVSyfqAB.js";import{SplatPreview as Qe}from"./SplatPreview-D3bCUQ8P.js";import"./contracts-HrWOi_yP.js";import"./preload-helper-BXl3LOEh.js";const H={vaeNoise:4096*128,latentNoise:1*8192*16,cameraNoise:5},$={steps:4,guidanceScale:3,shift:3,seed:42},Xe=[4,20],Je=17,Ze=32,z=9e4,et=5e3,se=20,Y={position:[1.5,1.5,1.5],target:[0,0,0],up:[0,1,0]};function w(e){const t=document.querySelector(e);if(t===null)throw new Error(`Required E2E lab element '${e}' was not found.`);return t}const tt=w("#model-base"),O=w("#cache"),nt=w("#prepared-image"),ot=w("#vae-noise"),at=w("#flow-fixture"),T=w("#run"),F=w("#cancel"),E=w('[data-testid="e2e-status"]'),j=w('[data-testid="e2e-error"]'),Q=w('[data-testid="e2e-result"]'),Ee=w("#e2e-preview-root"),re=w('[data-testid="e2e-viewer-status"]'),Z=je.createRoot(Ee),f=st();let R,U,C,k,q,ie=0,ce=0,V=!1,Se=!1;const S=[];window.__TRIPOSPLAT_E2E_HISTORY__=S;function st(){const e=document.createElement("section");e.id="e2e-generation-controls",e.setAttribute("aria-label","Generation comparison controls"),e.style.display="grid",e.style.gap="12px",e.style.margin="16px 0",e.style.padding="16px",e.style.border="1px solid currentColor",e.style.borderRadius="8px";const t=document.createElement("h2");t.textContent="Generation comparison",t.style.margin="0",t.style.fontSize="1rem",e.appendChild(t);const n=document.createElement("div");n.style.display="grid",n.style.gridTemplateColumns="repeat(auto-fit, minmax(140px, 1fr))",n.style.gap="12px";const o=B(n,"Sampling steps","e2e-steps",$.steps,4,20,1),a=B(n,"Guidance scale","e2e-guidance-scale",$.guidanceScale,0,30,.1),r=B(n,"Shift","e2e-shift",$.shift,0,30,.1),p=B(n,"Seed","e2e-seed",$.seed,0,2147483647,1);e.appendChild(n);const s=document.createElement("div");s.style.display="flex",s.style.flexWrap="wrap",s.style.gap="8px";const c=document.createElement("span");c.textContent="Step presets:",s.appendChild(c);for(const P of Xe){const b=document.createElement("button");b.type="button",b.textContent=String(P),b.dataset.stepsPreset=String(P),b.addEventListener("click",()=>{o.value=String(P)}),s.appendChild(b)}e.appendChild(s);const i=document.createElement("div");i.style.display="flex",i.style.flexWrap="wrap",i.style.gap="8px";const d=document.createElement("button");d.type="button",d.textContent="Download current PLY",d.disabled=!0;const u=document.createElement("button");u.type="button",u.textContent="Download current .splat",u.disabled=!0;const m=document.createElement("button");m.type="button",m.textContent="Clear comparison history",i.append(d,u,m),e.appendChild(i);const g=document.createElement("div");g.dataset.testid="e2e-storage-status",g.textContent="Storage status has not been measured.",e.appendChild(g);const h=document.createElement("div");h.dataset.testid="e2e-image-status",h.textContent="Prepared image has not been inspected.",e.appendChild(h);const l=document.createElement("div");l.style.overflowX="auto";const v=document.createElement("table");v.style.width="100%",v.style.borderCollapse="collapse",v.dataset.testid="e2e-run-history";const L=document.createElement("thead");L.innerHTML=` | |
| <tr> | |
| <th>Run</th> | |
| <th>Result</th> | |
| <th>Steps</th> | |
| <th>Guidance</th> | |
| <th>Shift</th> | |
| <th>Seed</th> | |
| <th>Gaussians</th> | |
| <th>Generate</th> | |
| <th>Total</th> | |
| <th>PLY hash</th> | |
| <th>.splat hash</th> | |
| </tr> | |
| `;const x=document.createElement("tbody");return v.append(L,x),l.appendChild(v),e.appendChild(l),(T.parentElement??T).insertAdjacentElement("afterend",e),d.addEventListener("click",()=>{k!==void 0&&ge(k,me("ply"))}),u.addEventListener("click",()=>{q!==void 0&&ge(q,me("splat"))}),m.addEventListener("click",()=>{S.splice(0,S.length),window.__TRIPOSPLAT_E2E_HISTORY__=S,ee(x)}),{stepsInput:o,guidanceInput:a,shiftInput:r,seedInput:p,downloadPlyButton:d,downloadSplatButton:u,clearHistoryButton:m,storageStatus:g,imageStatus:h,historyBody:x}}function B(e,t,n,o,a,r,p){const s=document.createElement("label");s.htmlFor=n,s.style.display="grid",s.style.gap="4px";const c=document.createElement("span");c.textContent=t;const i=document.createElement("input");return i.id=n,i.type="number",i.value=String(o),i.min=String(a),i.max=String(r),i.step=String(p),s.append(c,i),e.appendChild(s),i}function de(){return{userAgent:navigator.userAgent,crossOriginIsolated:self.crossOriginIsolated,webgpu:"gpu"in navigator}}function le(e){return e.replace(/\/+$/,"")}function N(e,t){const n=e.value.trim();if(n.length===0)throw new Error(`${t} must not be empty.`);return n}function X(e,t,n,o){const a=Number(e.value);if(!Number.isFinite(a))throw new Error(`${t} must be a finite number.`);if(a<n||a>o)throw new Error(`${t} must be between ${n} and ${o}.`);return a}function xe(e,t,n,o){const a=X(e,t,n,o);if(!Number.isInteger(a))throw new Error(`${t} must be an integer.`);return a}function rt(e){const t=xe(e,"Sampling steps",4,20);if(t!==4&&t!==20)throw new Error("Sampling steps must use the supported 4-step or 20-step schedule.");return t}function be(){return{steps:rt(f.stepsInput),guidanceScale:X(f.guidanceInput,"Guidance scale",0,30),shift:X(f.shiftInput,"Shift",0,30),seed:xe(f.seedInput,"Seed",0,2147483647)}}function it(){const e=O.value;if(e==="none"||e==="opfs"||e==="cache-api")return e;throw new Error(`Unsupported cache selection '${e}'.`)}function ct(){if(navigator.storage!==void 0&&typeof navigator.storage.getDirectory=="function"){O.value="opfs";return}if("caches"in window){O.value="cache-api";return}O.value="none"}async function dt(e){if(e!=="opfs"||navigator.storage===void 0){f.storageStatus.textContent=`Cache backend: ${e}. OPFS persistence was not requested.`;return}const t={persistenceRequested:!1};return typeof navigator.storage.persisted=="function"&&(t.persisted=await navigator.storage.persisted().catch(()=>!1)),t.persisted!==!0&&typeof navigator.storage.persist=="function"&&(t.persistenceRequested=!0,t.persisted=await navigator.storage.persist().catch(()=>!1)),await Ce(t),Le(t),t}async function Ce(e){if(navigator.storage===void 0||typeof navigator.storage.estimate!="function")return;const t=await navigator.storage.estimate().catch(()=>{});t?.usage!==void 0&&(e.usageBytes=t.usage),t?.quota!==void 0&&(e.quotaBytes=t.quota)}function Le(e){const t=e.persisted===!0?"persistent":e.persisted===!1?"not guaranteed persistent":"persistence unknown",n=e.usageBytes===void 0?"usage unknown":`${J(e.usageBytes)} used`,o=e.quotaBytes===void 0?"quota unknown":`${J(e.quotaBytes)} quota`;f.storageStatus.textContent=`OPFS cache: ${t}; ${n}; ${o}.`}async function Pe(e,t){if(e.length===0)throw new Error("Attempted to fetch an empty URL.");const n=await fetch(e,{signal:t,cache:"no-cache"});if(!n.ok)throw new Error(`Could not fetch ${e}: HTTP ${n.status} ${n.statusText}.`);return n}async function W(e,t,n){const a=await(await Pe(e,n)).arrayBuffer(),r=t*Float32Array.BYTES_PER_ELEMENT;if(a.byteLength!==r)throw new Error(`${e} has ${a.byteLength.toLocaleString()} bytes; expected ${r.toLocaleString()} bytes (${t.toLocaleString()} Float32 values).`);return new Float32Array(a)}async function lt(e,t){if(e.size===0)throw new Error(`Prepared image fixture '${t}' is empty.`);if(e.type.length>0&&!e.type.startsWith("image/"))throw new Error(`Prepared image fixture '${t}' has unexpected MIME type '${e.type}'.`);const n=await createImageBitmap(e);try{if(n.width===0||n.height===0)throw new Error(`Prepared image fixture '${t}' decoded with zero dimensions.`);const o=document.createElement("canvas");o.width=n.width,o.height=n.height;const a=o.getContext("2d",{willReadFrequently:!0});if(a===null)throw new Error("Could not create a 2D canvas context to inspect the prepared image.");a.drawImage(n,0,0);const r=a.getImageData(0,0,n.width,n.height).data;let p=!1;for(let c=3;c<r.length;c+=4)if(r[c]!==255){p=!0;break}const s={mimeType:e.type||"unknown",byteLength:e.size,width:n.width,height:n.height,hasAlpha:p};return f.imageStatus.textContent=`Prepared image: ${s.width}×${s.height}, ${s.mimeType}, ${J(s.byteLength)}, ${s.hasAlpha?"contains transparency":"fully opaque"}.`,s}finally{n.close()}}async function pe(e){const t=await crypto.subtle.digest("SHA-256",await e.arrayBuffer());return Array.from(new Uint8Array(t),n=>n.toString(16).padStart(2,"0")).join("")}function J(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MiB`:`${(e/(1024*1024*1024)).toFixed(2)} GiB`}function ue(e){return e<1e3?`${e.toFixed(0)} ms`:`${(e/1e3).toFixed(2)} s`}function fe(e){return e.slice(0,12)}function me(e){const t=be();return["triposplat",`${t.steps}steps`,`g${t.guidanceScale}`,`shift${t.shift}`,`seed${t.seed}`].join("-")+`.${e}`}function ge(e,t){const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.style.display="none",document.body.appendChild(o),o.click(),o.remove(),window.setTimeout(()=>{URL.revokeObjectURL(n)},0)}function he(e,t){k=e,q=t,f.downloadPlyButton.disabled=e===void 0,f.downloadSplatButton.disabled=t===void 0}function we(e){f.stepsInput.disabled=e,f.guidanceInput.disabled=e,f.shiftInput.disabled=e,f.seedInput.disabled=e;for(const t of document.querySelectorAll("[data-steps-preset]"))t.disabled=e;f.clearHistoryButton.disabled=e}function _(e,t){re.dataset.viewerState=e,re.textContent=t}function Ie(){Se||Ye.flushSync(()=>{Z.render(null)}),C!==void 0&&(URL.revokeObjectURL(C),C=void 0)}function Ae(){Ie(),_("waiting","Viewer is waiting for an exported PLY.")}function K(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted.","AbortError")}function pt(){const e=Ee.querySelector("canvas");return{present:e!==null,width:e?.width??0,height:e?.height??0,clientWidth:e?.clientWidth??0,clientHeight:e?.clientHeight??0}}async function ut(e,t){if(t.aborted)throw K(t);Ae(),C=URL.createObjectURL(e),ie+=1;const n=C,o=ie,a=performance.now(),r=await new Promise((p,s)=>{let c=!1,i;const d=()=>{window.clearTimeout(h),t.removeEventListener("abort",g),i!==void 0&&(cancelAnimationFrame(i),i=void 0)},u=(l,v,L=!1)=>{if(c)return;c=!0,d(),_(l,v);const x=()=>{if(i=void 0,t.aborted){s(K(t));return}p({status:l,message:v,loadMs:performance.now()-a,timeoutMs:z,canvas:pt()})};L?i=requestAnimationFrame(x):x()},m=l=>{c||(_(l.state,l.message),l.state==="ready"?u("ready",l.message,!0):l.state==="failed"&&u("failed",l.message))},g=()=>{c||(c=!0,d(),_("failed","Viewer load aborted."),s(K(t)))},h=window.setTimeout(()=>{u("failed",`Preview failed: viewer did not reach ready or failed within ${z} ms.`)},z);t.addEventListener("abort",g,{once:!0});try{Z.render(ze.createElement(Qe,{plyUrl:n,generationKey:o,bgColor:"#000000",fov:45,autoRotate:!1,maxScreenSize:1024,initialCameraPosition:Y.position,initialCameraTarget:Y.target,initialCameraUp:Y.up,splatPosition:[0,0,0],splatRotation:[0,0,0],splatFlip:[!1,!1,!1],onViewerStateChange:m}))}catch(l){u("failed",`Preview failed: ${l instanceof Error?l.message:String(l)}`)}});return Ke(r)}async function ft(e,t,n,o,a){const r=await e.slice(0,4096).text(),p=`end_header | |
| `,s=r.indexOf(p),c=s>=0?s+p.length:-1,i=c>=0?new TextEncoder().encode(r.slice(0,c)).byteLength:0,d=i+n*Je*Float32Array.BYTES_PER_ELEMENT,u=n*Ze,m={byteLength:e.size,sha256:o,headerBytes:i,expectedByteLength:d,binaryLittleEndian:r.startsWith(`ply | |
| format binary_little_endian 1.0 | |
| `),vertexCountMatches:r.includes(`element vertex ${n} | |
| `),byteLengthMatches:i>0&&e.size===d},g={byteLength:t.size,sha256:a,expectedByteLength:u,byteLengthMatches:t.size===u};return{passed:m.binaryLittleEndian&&m.vertexCountMatches&&m.byteLengthMatches&&g.byteLengthMatches,ply:m,splat:g}}function mt(e){const t=[];let n="";const o=(a,r)=>{const p=r.progress===void 0?"":Math.floor(r.progress*20),s=r,c=r,i=[a,r.stage,c.graph??"",s.invocation??"",s.step??"",p].join(":"),d={phase:a,elapsedMs:performance.now()-e,stage:r.stage,message:r.message};r.progress!==void 0&&(d.progress=r.progress),r.loadedBytes!==void 0&&(d.loadedBytes=r.loadedBytes),r.totalBytes!==void 0&&(d.totalBytes=r.totalBytes),c.graph!==void 0&&(d.graph=c.graph),s.step!==void 0&&(d.step=s.step),s.totalSteps!==void 0&&(d.totalSteps=s.totalSteps),s.invocation!==void 0&&(d.invocation=s.invocation),s.totalInvocations!==void 0&&(d.totalInvocations=s.totalInvocations),i===n&&t.length>0?t[t.length-1]=d:t.length<et&&t.push(d),n=i,E.textContent=r.message};return{records:t,load:a=>o("load",a),generate:a=>o("generate",a)}}function ye(e){if(window.__TRIPOSPLAT_E2E_RESULT__=e,Q.textContent=JSON.stringify(e,null,2),Q.hidden=!1,e.completed){e.passed?E.textContent=`PASS: the browser-local pipeline produced ${e.gaussianCount.toLocaleString()} finite Gaussians using ${e.generation.steps} steps, valid-size exports, and a ready Gaussian viewer canvas.`:E.textContent="FAIL: end-to-end execution completed, but a scene, export, or viewer sanity check failed.";return}E.textContent=`E2E run did not complete: ${e.error.message}`}function Re(e,t=0){const n=e instanceof Error?e:new Error(String(e)),o=n,a={name:o.name,message:o.message};return o.stack!==void 0&&(a.stack=o.stack),typeof o.code=="string"&&(a.code=o.code),typeof o.stage=="string"&&(a.stage=o.stage),o.diagnostics!==void 0&&(a.diagnostics=o.diagnostics),o.cause!==void 0&&t<6&&(a.cause=Re(o.cause,t+1)),a}async function ve(e){return e===void 0||await e.dispose(),!0}function gt(e){ce+=1,S.unshift({runNumber:ce,timestamp:new Date().toISOString(),passed:e.passed,steps:e.generation.steps,guidanceScale:e.generation.guidanceScale,shift:e.generation.shift,seed:e.generation.seed,gaussianCount:e.gaussianCount,fixtureFetchMs:e.timingsMs.fixtureFetch,loadMs:e.timingsMs.load,generateMs:e.timingsMs.generate,totalMs:e.timingsMs.total,plyBytes:e.exports.ply.byteLength,splatBytes:e.exports.splat.byteLength,plySha256:e.exports.ply.sha256,splatSha256:e.exports.splat.sha256}),S.length>se&&(S.length=se),window.__TRIPOSPLAT_E2E_HISTORY__=S,ee(f.historyBody)}function ee(e){e.replaceChildren();for(const t of S){const n=document.createElement("tr");y(n,String(t.runNumber)),y(n,t.passed?"PASS":"FAIL"),y(n,String(t.steps)),y(n,String(t.guidanceScale)),y(n,String(t.shift)),y(n,String(t.seed)),y(n,t.gaussianCount.toLocaleString()),y(n,ue(t.generateMs)),y(n,ue(t.totalMs)),y(n,fe(t.plySha256),t.plySha256),y(n,fe(t.splatSha256),t.splatSha256),e.appendChild(n)}}function y(e,t,n){const o=document.createElement("td");o.textContent=t,o.style.padding="6px",o.style.borderTop="1px solid currentColor",n!==void 0&&(o.title=n),e.appendChild(o)}async function ht(){if(V)return;V=!0,T.disabled=!0,F.disabled=!1,j.hidden=!0,Q.hidden=!0,delete window.__TRIPOSPLAT_E2E_RESULT__,we(!0),he(void 0,void 0),Ae();const e=performance.now(),t=new AbortController;R=t;const n=mt(e);let o,a,r=!1,p=!1;try{if(!("gpu"in navigator))throw new Error("WebGPU is unavailable in this browser.");const s=be(),c=le(N(tt,"Model base URL")),i=N(nt,"Prepared image URL"),d=N(ot,"VAE noise URL"),u=le(N(at,"Flow fixture directory")),m=`${u}/latent.f32`,g=`${u}/camera.f32`,h=it();E.textContent=h==="opfs"?"Preparing persistent OPFS model cache…":`Preparing ${h} model cache…`;const l=await dt(h),v=performance.now();E.textContent="Fetching prepared image and deterministic noise fixtures…";const[L,x,te,P]=await Promise.all([Pe(i,t.signal),W(d,H.vaeNoise,t.signal),W(m,H.latentNoise,t.signal),W(g,H.cameraNoise,t.signal)]),b=await L.blob(),_e=await lt(b,i),Te=performance.now()-v;o=new Ve({modelBaseUrl:c,executionProviders:["webgpu"],cache:h,logLevel:"info",wasmPaths:{mjs:"/ort/ort-wasm-simd-threaded.asyncify.mjs",wasm:"/ort/ort-wasm-simd-threaded.asyncify.wasm"}}),U=o;const Me=performance.now();await o.load({signal:t.signal,onProgress:n.load});const $e=performance.now()-Me,Be=performance.now();a=await o.generate(b,{steps:s.steps,guidanceScale:s.guidanceScale,shift:s.shift,seed:s.seed,inputIsPrepared:!0,vaeNoise:x,latentNoise:te,cameraNoise:P,signal:t.signal,onProgress:n.generate});const Ne=performance.now()-Be,ne=a.count,oe=We(a);E.textContent="Encoding and hashing binary PLY…";const Oe=performance.now(),M=await a.exportPLY(),Ue=await pe(M),Fe=performance.now()-Oe;E.textContent="Encoding and hashing browser .splat…";const ke=performance.now(),D=await a.exportSplat(),qe=await pe(D),De=performance.now()-ke,ae=await ft(M,D,ne,Ue,qe);he(M,D),E.textContent="Loading the exported PLY in the browser Gaussian viewer…";const G=await ut(M,t.signal),Ge=a.metadata.generationSettings,I=o.manifest,He=o.capabilities.configuredGraphs;a.dispose(),r=a.isDisposed,p=await ve(o),U=void 0,o=void 0,l!==void 0&&(await Ce(l),Le(l));const A={passed:oe.passed&&ae.passed&&G.passed,completed:!0,qualificationScope:"end-to-end-execution-structure-export-and-viewer-sanity",numericalParityClaimed:!1,model:{baseUrl:c,configuredGraphs:He,cache:h},fixtures:{preparedImage:i,preparedImageMetadata:_e,vaeNoise:d,latentNoise:m,cameraNoise:g,explicitDeterministicNoise:!0},generation:s,scene:oe,gaussianCount:ne,exports:ae,viewer:G,timingsMs:{fixtureFetch:Te,load:$e,generate:Ne,plyExportAndHash:Fe,splatExportAndHash:De,viewerLoad:G.loadMs,total:performance.now()-e},pipelineMeasuredTimingsMs:Ge.measuredTimingsMs,progress:n.records,lifecycle:{sceneDisposed:r,modelDisposed:p},storage:l,environment:de()};I!==void 0&&(A.model.manifestVersion=I.version,A.model.modelRevision=I.modelRevision,I.estimatedModelBytes!==void 0&&(A.model.declaredModelBytes=I.estimatedModelBytes)),gt(A),ye(A)}catch(s){a!==void 0&&!a.isDisposed&&(a.dispose(),r=a.isDisposed),o!==void 0&&(p=await ve(o).catch(()=>!1)),U=void 0;const c=s instanceof Error?s:new Error(String(s));Ie(),_("failed","Viewer unavailable because the E2E run stopped: "+c.message);const d={passed:!1,completed:!1,qualificationScope:"end-to-end-execution-structure-export-and-viewer-sanity",numericalParityClaimed:!1,error:Re(c),progress:n.records,timingsMs:{total:performance.now()-e},environment:de()};j.textContent=`${c.name}: ${c.message}`,j.hidden=!1,ye(d)}finally{R===t&&(R=void 0),V=!1,T.disabled=!1,F.disabled=!0,we(!1)}}ct();ee(f.historyBody);T.addEventListener("click",()=>{ht()});F.addEventListener("click",()=>{F.disabled=!0,E.textContent="Cancelling after the active ONNX invocation returns…",R?.abort(new DOMException("Cancelled from the E2E lab.","AbortError"))});document.documentElement.dataset.e2eBootstrap="ready";window.addEventListener("beforeunload",()=>{Se=!0,R?.abort(new DOMException("E2E lab page is closing.","AbortError")),U?.dispose(),Z.unmount(),C!==void 0&&(URL.revokeObjectURL(C),C=void 0),k=void 0,q=void 0}); | |