dbirks's picture
new build
26f7def verified
raw
history blame
17.3 kB
import{S as ft,i as pt,s as ut,k as s,a as j,q as g,H as ht,l,m as i,h as n,c as B,r as w,n as a,I as qe,F as e,b as we,J as de,K as mt,L as gt,A as et,M as lt,o as wt,z as bt,N as vt,O as tt,p as at,u as _t,P as Fe}from"../../chunks/index-a207c28c.js";const{document:De,window:nt}=vt;function ot(c){let p,r,I,C,R,f;return{c(){p=s("div"),r=s("p"),I=g("Loading\u2026"),C=j(),R=s("p"),f=g("\u2588\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592")},l(H){p=l(H,"DIV",{});var D=i(p);r=l(D,"P",{});var m=i(r);I=w(m,"Loading\u2026"),m.forEach(n),C=B(D),R=l(D,"P",{});var h=i(R);f=w(h,"\u2588\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592"),h.forEach(n),D.forEach(n)},m(H,D){we(H,p,D),e(p,r),e(r,I),e(p,C),e(p,R),e(R,f)},d(H){H&&n(p)}}}function rt(c){let p,r,I,C,R,f,H,D,m,h,X,E,T,x,u,V,K,A,b,v,O,M,ne,q,oe,re,U,G,Z,$,Y,se;return{c(){p=s("div"),r=s("div"),I=s("p"),C=g("Strength:"),R=j(),f=s("span"),H=j(),D=s("div"),m=s("p"),h=g("Prompt:"),X=j(),E=s("span"),T=j(),x=s("div"),u=s("button"),V=g("diffuse \u{1FA84}"),A=j(),b=s("div"),v=s("label"),O=s("input"),M=g(`
upload img`),ne=j(),q=s("p"),oe=g("pro tip: upload img by dropping on the canvas"),re=j(),U=s("div"),G=s("p"),Z=g("Images returned: "),$=g(c[2]),this.h()},l(S){p=l(S,"DIV",{});var k=i(p);r=l(k,"DIV",{class:!0});var ee=i(r);I=l(ee,"P",{class:!0});var Q=i(I);C=w(Q,"Strength:"),Q.forEach(n),R=B(ee),f=l(ee,"SPAN",{class:!0,role:!0,contenteditable:!0,spellcheck:!0,dir:!0,maxlength:!0}),i(f).forEach(n),ee.forEach(n),H=B(k),D=l(k,"DIV",{class:!0});var te=i(D);m=l(te,"P",{class:!0});var le=i(m);h=w(le,"Prompt:"),le.forEach(n),X=B(te),E=l(te,"SPAN",{class:!0,role:!0,contenteditable:!0,style:!0,spellcheck:!0,dir:!0,maxlength:!0}),i(E).forEach(n),te.forEach(n),T=B(k),x=l(k,"DIV",{class:!0});var t=i(x);u=l(t,"BUTTON",{class:!0});var o=i(u);V=w(o,"diffuse \u{1FA84}"),o.forEach(n),t.forEach(n),A=B(k),b=l(k,"DIV",{class:!0});var d=i(b);v=l(d,"LABEL",{class:!0});var _=i(v);O=l(_,"INPUT",{accept:!0,style:!0,type:!0}),M=w(_,`
upload img`),_.forEach(n),ne=B(d),q=l(d,"P",{class:!0});var y=i(q);oe=w(y,"pro tip: upload img by dropping on the canvas"),y.forEach(n),d.forEach(n),re=B(k),U=l(k,"DIV",{});var L=i(U);G=l(L,"P",{class:!0});var N=i(G);Z=w(N,"Images returned: "),$=w(N,c[2]),N.forEach(n),L.forEach(n),k.forEach(n),this.h()},h(){a(I,"class","font-bold align-middle py-2"),a(f,"class","overflow-auto resize-y py-2 px-3 min-h-[42px] max-h-[500px] !w-[181px] whitespace-pre-wrap inline-block border border-gray-200 shadow-inner outline-none svelte-1wfa7x9"),a(f,"role","textbox"),a(f,"contenteditable",""),a(f,"spellcheck","false"),a(f,"dir","auto"),a(f,"maxlength","200"),c[1]===void 0&&tt(()=>c[16].call(f)),a(r,"class","flex gap-x-2 mt-3 items-start justify-center align-vertical"),a(m,"class","font-bold align-middle py-2"),a(E,"class","overflow-auto resize-y py-2 px-3 min-h-[42px] max-h-[500px] !w-[181px] whitespace-pre-wrap inline-block border border-gray-200 shadow-inner outline-none svelte-1wfa7x9"),a(E,"role","textbox"),a(E,"contenteditable",""),at(E,"--placeholder","'Add prompt'"),a(E,"spellcheck","false"),a(E,"dir","auto"),a(E,"maxlength","1000"),c[0]===void 0&&tt(()=>c[17].call(E)),a(D,"class","flex gap-x-2 mt-3 items-start justify-center"),a(u,"class","bg-green-700 hover:bg-green-800 text-white font-bold py-[0.555rem] px-4 rounded-xl"),a(x,"class",K="flex gap-x-2 mt-3 items-start justify-center "+(c[3]?"animate-pulse":"")),a(O,"accept","image/*"),at(O,"display","none"),a(O,"type","file"),a(v,"class","inline border py-2 px-3 bg-slate-200 cursor-pointer"),a(q,"class","hidden desktop:inline mt-2 opacity-50"),a(b,"class","mt-4"),a(G,"class","my-4")},m(S,k){we(S,p,k),e(p,r),e(r,I),e(I,C),e(r,R),e(r,f),c[1]!==void 0&&(f.textContent=c[1]),e(p,H),e(p,D),e(D,m),e(m,h),e(D,X),e(D,E),c[0]!==void 0&&(E.textContent=c[0]),e(p,T),e(p,x),e(x,u),e(u,V),e(p,A),e(p,b),e(b,v),e(v,O),c[18](O),e(v,M),e(b,ne),e(b,q),e(q,oe),e(p,re),e(p,U),e(U,G),e(G,Z),e(G,$),Y||(se=[de(f,"input",c[16]),de(f,"keydown",c[13]),de(E,"input",c[17]),de(E,"keydown",c[13]),de(u,"click",c[9]),de(O,"change",c[10])],Y=!0)},p(S,k){k[0]&2&&S[1]!==f.textContent&&(f.textContent=S[1]),k[0]&1&&S[0]!==E.textContent&&(E.textContent=S[0]),k[0]&8&&K!==(K="flex gap-x-2 mt-3 items-start justify-center "+(S[3]?"animate-pulse":""))&&a(x,"class",K),k[0]&4&&_t($,S[2])},d(S){S&&n(p),c[18](null),Y=!1,lt(se)}}}function yt(c){let p,r,I,C,R,f,H,D,m,h,X,E,T,x,u,V,K,A,b,v,O,M,ne,q,oe,re,U,G,Z,$,Y,se,S,k,ee,Q,te,le,t,o,d,_,y,L,N,be,J,ve,ie,xe,Se,fe,Pe,Ae,_e,Le,Te,ce,je,pe,Be,Me,ue,Ne,ke,Re,Oe,z=!c[4]&&ot(),F=c[4]&&rt(c);return{c(){p=s("link"),r=s("script"),C=s("script"),f=s("script"),D=j(),m=s("div"),h=s("canvas"),E=j(),T=s("div"),z&&z.c(),x=j(),u=s("div"),V=j(),F&&F.c(),A=j(),b=s("article"),v=s("div"),O=g(`Hi Rachel \u{1F44B}\u{1F642}
`),M=s("p"),ne=g("Stable Diffusion model by "),q=s("a"),oe=g("CompVis"),re=g(" and "),U=s("a"),G=g("Stability AI"),Z=g(" - Demo by \u{1F917} Hugging Face"),$=j(),Y=s("p"),se=g("Powered by "),S=s("a"),k=g("\u{1F917} Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch"),ee=g(". Based on "),Q=s("a"),te=g("notebook by @psuraj28"),le=j(),t=s("p"),o=g("Check out "),d=s("a"),_=g("Stable Diffusion Gradio demo"),y=j(),L=s("h3"),N=g("LICENSE"),be=j(),J=s("p"),ve=g("The model is licensed with a "),ie=s("a"),xe=g("CreativeML Open RAIL-M"),Se=g(" license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please "),fe=s("a"),Pe=g("read the license"),Ae=j(),_e=s("h3"),Le=g("Biases and content acknowledgment"),Te=j(),ce=s("p"),je=g("Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the "),pe=s("a"),Be=g("LAION-5B dataset"),Me=g(", which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the "),ue=s("a"),Ne=g("model card"),this.h()},l(P){const W=ht('[data-svelte="svelte-bw39ln"]',De.head);p=l(W,"LINK",{href:!0,rel:!0}),r=l(W,"SCRIPT",{src:!0});var it=i(r);it.forEach(n),C=l(W,"SCRIPT",{src:!0});var ct=i(C);ct.forEach(n),f=l(W,"SCRIPT",{src:!0});var dt=i(f);dt.forEach(n),W.forEach(n),D=B(P),m=l(P,"DIV",{class:!0});var Ce=i(m);h=l(Ce,"CANVAS",{class:!0}),i(h).forEach(n),E=B(Ce),T=l(Ce,"DIV",{class:!0});var me=i(T);z&&z.l(me),x=B(me),u=l(me,"DIV",{id:!0}),i(u).forEach(n),V=B(me),F&&F.l(me),me.forEach(n),Ce.forEach(n),A=B(P),b=l(P,"ARTICLE",{class:!0});var ae=i(b);v=l(ae,"DIV",{class:!0});var he=i(v);O=w(he,`Hi Rachel \u{1F44B}\u{1F642}
`),M=l(he,"P",{});var ge=i(M);ne=w(ge,"Stable Diffusion model by "),q=l(ge,"A",{href:!0,rel:!0});var Ue=i(q);oe=w(Ue,"CompVis"),Ue.forEach(n),re=w(ge," and "),U=l(ge,"A",{href:!0,rel:!0});var ze=i(U);G=w(ze,"Stability AI"),ze.forEach(n),Z=w(ge," - Demo by \u{1F917} Hugging Face"),ge.forEach(n),$=B(he),Y=l(he,"P",{});var ye=i(Y);se=w(ye,"Powered by "),S=l(ye,"A",{href:!0,rel:!0});var We=i(S);k=w(We,"\u{1F917} Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch"),We.forEach(n),ee=w(ye,". Based on "),Q=l(ye,"A",{href:!0,rel:!0});var Ke=i(Q);te=w(Ke,"notebook by @psuraj28"),Ke.forEach(n),ye.forEach(n),le=B(he),t=l(he,"P",{});var Ve=i(t);o=w(Ve,"Check out "),d=l(Ve,"A",{href:!0,rel:!0});var Ye=i(d);_=w(Ye,"Stable Diffusion Gradio demo"),Ye.forEach(n),Ve.forEach(n),he.forEach(n),y=B(ae),L=l(ae,"H3",{});var Ge=i(L);N=w(Ge,"LICENSE"),Ge.forEach(n),be=B(ae),J=l(ae,"P",{});var Ee=i(J);ve=w(Ee,"The model is licensed with a "),ie=l(Ee,"A",{href:!0,rel:!0});var Je=i(ie);xe=w(Je,"CreativeML Open RAIL-M"),Je.forEach(n),Se=w(Ee," license. The authors claim no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in this license. The license forbids you from sharing any content that violates any laws, produce any harm to a person, disseminate any personal information that would be meant for harm, spread misinformation and target vulnerable groups. For the full list of restrictions please "),fe=l(Ee,"A",{href:!0,rel:!0});var Qe=i(fe);Pe=w(Qe,"read the license"),Qe.forEach(n),Ee.forEach(n),Ae=B(ae),_e=l(ae,"H3",{});var Xe=i(_e);Le=w(Xe,"Biases and content acknowledgment"),Xe.forEach(n),Te=B(ae),ce=l(ae,"P",{});var Ie=i(ce);je=w(Ie,"Despite how impressive being able to turn text into image is, beware to the fact that this model may output content that reinforces or exacerbates societal biases, as well as realistic faces, pornography and violence. The model was trained on the "),pe=l(Ie,"A",{href:!0,rel:!0});var Ze=i(pe);Be=w(Ze,"LAION-5B dataset"),Ze.forEach(n),Me=w(Ie,", which scraped non-curated image-text-pairs from the internet (the exception being the removal of illegal content) and is meant for research purposes. You can read more in the "),ue=l(Ie,"A",{href:!0,rel:!0});var $e=i(ue);Ne=w($e,"model card"),$e.forEach(n),Ie.forEach(n),ae.forEach(n),this.h()},h(){a(p,"href","https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.css"),a(p,"rel","stylesheet"),qe(r.src,I="https://code.jquery.com/jquery-1.12.4.min.js")||a(r,"src",I),qe(C.src,R="https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.min.js")||a(C,"src",R),qe(f.src,H="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js")||a(f,"src",H),a(h,"class",X="border-[1.2px] desktop:mt-[34px] "+(c[8]?"":"hidden")),a(u,"id","board-container"),a(T,"class",K="flex flex-col items-center "+(c[3]?"pointer-events-none":"")),a(m,"class","flex flex-wrap gap-x-4 gap-y-2 justify-center my-8"),a(q,"href","https://huggingface.co/CompVis"),a(q,"rel","nofollow"),a(U,"href","https://huggingface.co/stabilityai"),a(U,"rel","nofollow"),a(S,"href","https://github.com/huggingface/diffusers"),a(S,"rel","nofollow"),a(Q,"href","https://twitter.com/psuraj28/status/1562039265126670339"),a(Q,"rel","nofollow"),a(d,"href","https://huggingface.co/spaces/stabilityai/stable-diffusion"),a(d,"rel","nofollow"),a(v,"class","text-center"),a(ie,"href","https://huggingface.co/spaces/CompVis/stable-diffusion-license"),a(ie,"rel","nofollow"),a(fe,"href","https://huggingface.co/spaces/CompVis/stable-diffusion-license"),a(fe,"rel","nofollow"),a(pe,"href","https://laion.ai/blog/laion-5b/"),a(pe,"rel","nofollow"),a(ue,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),a(ue,"rel","nofollow"),a(b,"class",ke="prose-sm px-4 md:px-12 lg:px-56 mb-8 "+(c[4]?"":"hidden"))},m(P,W){e(De.head,p),e(De.head,r),e(De.head,C),e(De.head,f),we(P,D,W),we(P,m,W),e(m,h),c[14](h),e(m,E),e(m,T),z&&z.m(T,null),e(T,x),e(T,u),c[15](u),e(T,V),F&&F.m(T,null),we(P,A,W),we(P,b,W),e(b,v),e(v,O),e(v,M),e(M,ne),e(M,q),e(q,oe),e(M,re),e(M,U),e(U,G),e(M,Z),e(v,$),e(v,Y),e(Y,se),e(Y,S),e(S,k),e(Y,ee),e(Y,Q),e(Q,te),e(v,le),e(v,t),e(t,o),e(t,d),e(d,_),e(b,y),e(b,L),e(L,N),e(b,be),e(b,J),e(J,ve),e(J,ie),e(ie,xe),e(J,Se),e(J,fe),e(fe,Pe),e(b,Ae),e(b,_e),e(_e,Le),e(b,Te),e(b,ce),e(ce,je),e(ce,pe),e(pe,Be),e(ce,Me),e(ce,ue),e(ue,Ne),Re||(Oe=[de(nt,"drop",mt(gt(c[11]))),de(nt,"paste",c[12])],Re=!0)},p(P,W){W[0]&256&&X!==(X="border-[1.2px] desktop:mt-[34px] "+(P[8]?"":"hidden"))&&a(h,"class",X),P[4]?z&&(z.d(1),z=null):z||(z=ot(),z.c(),z.m(T,x)),P[4]?F?F.p(P,W):(F=rt(P),F.c(),F.m(T,null)):F&&(F.d(1),F=null),W[0]&8&&K!==(K="flex flex-col items-center "+(P[3]?"pointer-events-none":""))&&a(T,"class",K),W[0]&16&&ke!==(ke="prose-sm px-4 md:px-12 lg:px-56 mb-8 "+(P[4]?"":"hidden"))&&a(b,"class",ke)},i:et,o:et,d(P){n(p),n(r),n(C),n(f),P&&n(D),P&&n(m),c[14](null),z&&z.d(),c[15](null),F&&F.d(),P&&n(A),P&&n(b),Re=!1,lt(Oe)}}}const He=500,st=3e3;function Et(){window.createImageBitmap=async function(c){return new Promise((p,r)=>{const I=document.createElement("canvas"),C=I.getContext("2d");I.width=c.width,I.height=c.height,C.putImageData(c,0,0);const R=I.toDataURL(),f=document.createElement("img");f.addEventListener("load",()=>{p(f)}),f.src=R})}}function It(){const c=document.querySelectorAll("a");for(const p of c)p.target="_blank"}function Dt(c,p,r){let I="",C="0.85",R="0",f=!1,H=!1,D,m,h,X,E,T,x,u=400,V,K,A,b=!1,v=[];async function O(){if(!h)return;const t=h.createImageData(m.width,m.height),o=t.data;for(let y=0,L=o.length;y<L;y+=4)o[y]=40*Math.random()*7,o[y+1]=40*Math.random()*7,o[y+2]=40*Math.random()*7,o[y+3]=10;const d=await createImageBitmap(t),_=performance.now()-X;h.globalAlpha=Math.min(_,st)/st,h.drawImage(d,0,0,u,u),f&&window.requestAnimationFrame(O)}function M(t){if(!h)return;const o=performance.now()-E;h.globalAlpha=Math.min(o,He)/He,h.drawImage(t,0,0,u,u),o<He&&window.requestAnimationFrame(()=>M(t))}async function ne(t){const o=t.toDataURL("png"),_=await(await fetch(o)).blob(),y=new File([_],"canvas shot.png",{type:"image/png"}),L=t.getContext("2d").getImageData(0,0,u,u),N=await createImageBitmap(L);return{imgFile:y,imgBitmap:N}}async function q(){if(!I)return alert("Please add prompt");if(!m||!h)return;x&&clearInterval(x),r(3,f=!0),r(8,b=!1),G(),X=performance.now(),O();const{imgFile:t,imgBitmap:o}=await ne(m),d=new FormData;d.append("prompt",I),d.append("strength",C),d.append("image",t);try{const _=await fetch("https://sdb.pcuenca.net/i2i",{method:"POST",body:d}),y=JSON.parse(await _.text()),{images:L}=y;if(r(2,R=L.length.toString()),!L.length)return alert("All the results were flagged. Please try again with diffeerent sketch + prompt");v=await Promise.all(L.map(async be=>{const J=new Image;return J.src=`data:image/png;base64, ${be}`,await new Promise((ve,ie)=>{J.onload=()=>ve(J)}),J})),v.push(o),r(8,b=!0);let N=0;E=performance.now(),M(v[N%v.length]),T=()=>{x&&clearInterval(x),E=performance.now(),N=N+1,M(v[N%v.length])},x=setInterval(()=>{N=N+1,E=performance.now(),M(v[N%v.length])},2500),H||oe()}catch(_){console.error(_),alert("Error happened, queue might be full. Please try again in a bit :)")}finally{r(3,f=!1)}}function oe(){const t=document.createElement("div");t.className="drawing-board-control";const o=document.createElement("button");o.innerHTML="\u23EF",o.onclick=T,t.append(o);const d=document.querySelector(".drawing-board-controls");d&&v.length>1&&(d.appendChild(t),H=!0,r(5,V.onclick=()=>{x&&clearInterval(x)},V))}function re(){const t=document.createElement("div");t.className="drawing-board-control";const o=document.createElement("button");o.innerHTML="\u{1F9F9}",o.onclick=()=>{h==null||h.clearRect(0,0,u,u),v=[],r(8,b=!1)},t.append(o);const d=document.querySelector(".drawing-board-controls");d&&d.appendChild(t)}function U(){const t=document.createElement("div");t.className="drawing-board-control";const o=document.createElement("button");o.innerHTML="\u2B07\uFE0F",o.onclick=()=>{if(!m)return;const _=document.createElement("a"),y=Date.now()%200;_.download=`diffuse-the-rest-${y}.png`,_.href=m.toDataURL(),_.click()},t.append(o);const d=document.querySelector(".drawing-board-controls");d&&d.appendChild(t)}function G(){const t=A.getContext("2d");r(7,A.width=m.width,A),r(7,A.height=m.height,A),t.drawImage(m,0,0)}async function Z(t){x&&clearInterval(x);const o=new Image;o.src=URL.createObjectURL(t),await new Promise((y,L)=>{o.onload=()=>y(o)});const{width:d,height:_}=o;if(d==_)h==null||h.drawImage(o,0,0,d,_,0,0,u,u);else if(d>_){const y=Math.floor(u*_/d),L=Math.floor((u-y)/2);h==null||h.drawImage(o,0,0,d,_,0,L,u,y)}else{const y=Math.floor(u*d/_),L=Math.floor((u-y)/2);h==null||h.drawImage(o,0,0,d,_,L,0,y,u)}}function $(){var o;const t=(o=K.files)==null?void 0:o[0];t&&Z(t)}function Y(t){var _;if(!((_=t.dataTransfer)!=null&&_.files))return;t.preventDefault();const d=Array.from(t.dataTransfer.files)[0];Z(d)}function se(t){if(!t.clipboardData)return;const o=Array.from(t.clipboardData.files);if(o.length===0)return;t.preventDefault();const d=o[0];Z(d)}function S(t){if(f)return t.preventDefault();t.code==="Enter"&&(t.preventDefault(),q())}wt(async()=>{typeof createImageBitmap>"u"&&Et();const{innerWidth:t}=window;u=Math.min(u,Math.floor(t*.75)),r(5,V.style.width=`${u}px`,V),r(5,V.style.height=`${u}px`,V),r(7,A.style.width=`${u}px`,A),r(7,A.style.height=`${u}px`,A),await bt(),D=new window.DrawingBoard.Board("board-container",{size:10,controls:["Color",{Size:{type:"dropdown"}},{DrawingMode:{filler:!1}}],webStorage:!1,enlargeYourContainer:!0}),r(4,m=D.canvas),h=m.getContext("2d"),r(4,m.ondragover=function(o){return o.preventDefault(),!1},m),re(),U(),It()});function k(t){Fe[t?"unshift":"push"](()=>{A=t,r(7,A)})}function ee(t){Fe[t?"unshift":"push"](()=>{V=t,r(5,V)})}function Q(){C=this.textContent,r(1,C)}function te(){I=this.textContent,r(0,I)}function le(t){Fe[t?"unshift":"push"](()=>{K=t,r(6,K)})}return[I,C,R,f,m,V,K,A,b,q,$,Y,se,S,k,ee,Q,te,le]}class Ct extends ft{constructor(p){super(),pt(this,p,Dt,yt,ut,{},null,[-1,-1])}}export{Ct as default};