Spaces:
Running
Running
Upload 7 files
Browse files
assets/index-9CZ-GgFL.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
import*as l from"https://ibelem.github.io/webnn-developer-preview/assets/dist_transformers/1.22.0-dev.20250325/transformers.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const e of document.querySelectorAll('link[rel="modulepreload"]'))a(e);new MutationObserver(e=>{for(const o of e)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&a(i)}).observe(document,{childList:!0,subtree:!0});function r(e){const o={};return e.integrity&&(o.integrity=e.integrity),e.referrerPolicy&&(o.referrerPolicy=e.referrerPolicy),e.crossOrigin==="use-credentials"?o.credentials="include":e.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function a(e){if(e.ep)return;e.ep=!0;const o=r(e);fetch(e.href,o)}})();const m="https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024",d=document.getElementById("status"),g=document.getElementById("upload"),s=document.getElementById("container"),p=document.getElementById("example");d.textContent="Loading model...";const f=await l.AutoModel.from_pretrained("webnn/RMBG-2",{config:{model_type:"custom"}}),h=await l.AutoProcessor.from_pretrained("webnn/RMBG-2",{config:{do_normalize:!0,do_pad:!1,do_rescale:!0,do_resize:!0,image_mean:[.5,.5,.5],feature_extractor_type:"ImageFeatureExtractor",image_std:[1,1,1],resample:2,rescale_factor:.00392156862745098,size:{width:1024,height:1024}}});d.textContent="Ready";p.addEventListener("click",n=>{n.preventDefault(),A(m)});g.addEventListener("change",function(n){const t=n.target.files[0];if(!t)return;const r=new FileReader;r.onload=a=>A(a.target.result),r.readAsDataURL(t)});async function A(n){const t=await l.RawImage.fromURL(n);s.innerHTML="",s.style.backgroundImage=`url(${n})`;const r=t.width/t.height,[a,e]=r>720/480?[720,720/r]:[480*r,480];s.style.width=`${a}px`,s.style.height=`${e}px`,d.textContent="Analysing...";const{pixel_values:o}=await h(t),{output:i}=await f({input:o}),u=await RawImage.fromTensor(i[0].mul(255).to("uint8")).resize(t.width,t.height);t.putAlpha(u);const c=document.createElement("canvas");c.width=t.width,c.height=t.height,c.getContext("2d").drawImage(t.toCanvas(),0,0),s.append(c),s.style.removeProperty("background-image"),s.style.background='url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURb+/v////5nD/3QAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAUSURBVBjTYwABQSCglEENMxgYGAAynwRB8BEAgQAAAABJRU5ErkJggg==")',d.textContent="Done!"}
|
assets/index-B-JpncJI.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
import*as f from"https://ibelem.github.io/webnn-developer-preview/assets/dist_transformers/1.22.0-dev.20250325/transformers.js";(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))a(t);new MutationObserver(t=>{for(const n of t)if(n.type==="childList")for(const s of n.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&a(s)}).observe(document,{childList:!0,subtree:!0});function r(t){const n={};return t.integrity&&(n.integrity=t.integrity),t.referrerPolicy&&(n.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?n.credentials="include":t.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function a(t){if(t.ep)return;t.ep=!0;const n=r(t);fetch(t.href,n)}})();const y="https://images.pexels.com/photos/5965592/pexels-photo-5965592.jpeg?auto=compress&cs=tinysrgb&w=1024",p=document.getElementById("status"),E=document.getElementById("device"),v=document.getElementById("upload"),c=document.getElementById("container"),N=document.getElementById("example");let g=null;const D=async()=>{if(g)return g;const o="huggingface.co",e="hf-mirror.com",r="/webml/models-moved/resolve/main/01.onnx",a=async s=>{const l=new AbortController,i=setTimeout(()=>l.abort(),2e3);try{const d=await fetch(`https://${s}${r}`,{method:"HEAD",signal:l.signal,cache:"no-store"});return clearTimeout(i),d.ok}catch(d){return console.log(`Error reaching ${s}:`,d),clearTimeout(i),!1}};return await a(o)?(g=o,o):await a(e)?(console.log(`Hugging Face main domain unreachable. Switching to mirror: ${e}`),g=e,e):(g=o,o)};p.textContent="Loading model...";function I(o,e){const r="webnn-gpu",a="fp16",t=["webnn-gpu","webnn-cpu","webnn-npu"],n=["fp16","fp32","int8"],s=(o||r).toLowerCase(),l=e&&n.includes(e.toLowerCase())?e.toLowerCase():t.includes(s)?a:"fp16",b=t.includes(s)?{freeDimensionOverrides:{height:1024,width:1024},logSeverityLevel:0,model_type:"custom"}:{logSeverityLevel:0,model_type:"custom"};return{device:s,dtype:l,sessionOptions:b}}const h=new URLSearchParams(window.location.search);let{device:m,dtype:R,sessionOptions:_}=I(h.get("device"),h.get("dtype")),u="WebNN GPU";switch(m){case"webgpu":u="WebGPU";break;case"webnn-gpu":u="WebNN GPU";break;case"webnn-cpu":u="WebNN CPU";break;case"webnn-npu":u="WebNN NPU";break;default:u="WebNN GPU"}E.textContent=u;["webgpu","webnn-gpu","webnn-cpu","webnn-npu"].includes(m)||(p.textContent=`Unsupported device ${m}. Falling back to WebNN GPU.`,m="webnn-gpu");let A=await D();A!=="huggingface.co"&&(console.log(`Using alternative Hugging Face mirror: ${A}`),f.env.remoteHost=`https://${A}`);const U=await f.AutoModel.from_pretrained("briaai/RMBG-1.4",{device:m,dtype:R,session_options:_}),x=await f.AutoProcessor.from_pretrained("briaai/RMBG-1.4",{config:{do_normalize:!0,do_pad:!1,do_rescale:!0,do_resize:!0,image_mean:[.5,.5,.5],feature_extractor_type:"ImageFeatureExtractor",image_std:[1,1,1],resample:2,rescale_factor:.00392156862745098,size:{width:1024,height:1024}}});p.textContent="Ready";N.addEventListener("click",o=>{o.preventDefault(),w(y)});v.addEventListener("change",function(o){const e=o.target.files[0];if(!e)return;const r=new FileReader;r.onload=a=>w(a.target.result),r.readAsDataURL(e)});async function w(o){const e=await f.RawImage.fromURL(o);c.innerHTML="",c.style.backgroundImage=`url(${o})`;const r=e.width/e.height,[a,t]=r>720/480?[720,720/r]:[480*r,480];c.style.width=`${a}px`,c.style.height=`${t}px`,p.textContent="Analysing...";const{pixel_values:n}=await x(e),{output:s}=await U({input:n}),l=await RawImage.fromTensor(s[0].mul(255).to("uint8")).resize(e.width,e.height);e.putAlpha(l);const i=document.createElement("canvas");i.width=e.width,i.height=e.height,i.getContext("2d").drawImage(e.toCanvas(),0,0),c.append(i),c.style.removeProperty("background-image"),c.style.background='url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAGUExURb+/v////5nD/3QAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAUSURBVBjTYwABQSCglEENMxgYGAAynwRB8BEAgQAAAABJRU5ErkJggg==")',p.textContent="Done!"}
|
assets/index-BqalD_uN.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
assets/index-C8PCQI1E.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
assets/index-PZ58GEkw.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*{box-sizing:border-box;padding:0;margin:0;font-family:sans-serif}html,body{height:100%}body{padding:16px 32px}body,#container,#upload-button{display:flex;flex-direction:column;justify-content:center;align-items:center}h1,h4{text-align:center}h4{margin-top:.5rem}#container{position:relative;width:720px;height:480px;max-width:100%;max-height:100%;border:2px dashed #d1d5db;border-radius:.75rem;overflow:hidden;margin-top:1rem;background-size:100% 100%;background-position:center;background-repeat:no-repeat}#upload-button{gap:.4rem;font-size:18px;cursor:pointer}#upload{display:none}svg{pointer-events:none}#example{font-size:14px;text-decoration:underline;cursor:pointer}#example:hover{color:#2563eb}canvas{position:absolute;width:100%;height:100%}#status{min-height:16px;margin:8px 0}
|
assets/index-PenTddJ7.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*{box-sizing:border-box;padding:0;margin:0;font-family:sans-serif}html,body{height:100%}body{padding:16px 32px}body,#container,#upload-button{display:flex;flex-direction:column;justify-content:center;align-items:center}h1,h4{text-align:center}h4{margin-top:.5rem;font-weight:200}#container{position:relative;width:720px;height:480px;max-width:100%;max-height:100%;border:2px dashed #d1d5db;border-radius:.75rem;overflow:hidden;margin-top:1rem;background-size:100% 100%;background-position:center;background-repeat:no-repeat}.device-links{margin-top:1rem;font-size:14px;text-align:center}#upload-button{gap:.4rem;font-size:18px;cursor:pointer}#upload{display:none}svg{pointer-events:none}#example{font-size:14px;text-decoration:underline;cursor:pointer}#example:hover{color:#2563eb}canvas{position:absolute;width:100%;height:100%}#status{min-height:16px;margin:8px 0}
|
assets/ort-wasm-simd-threaded.jsep-B0T3yYHD.wasm
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c46655e8a94afc45338d4cb2b840475f88e5012d524509916e505079c00bfa39
|
| 3 |
+
size 21596019
|