File size: 15,130 Bytes
c0104ce
 
 
1
2
3
4
import{S as ct,i as dt,s as ft,k as l,a as V,q as v,H as ut,l as c,m as f,h as n,c as q,r as _,n as o,I as Ve,F as e,b as ce,J as de,K as ht,L as pt,A as $e,M as rt,o as mt,z as gt,N as wt,p as bt,O as et,P as qe}from"../../chunks/index-e7559696.js";const{document:Ee,window:tt}=wt;function at(h){let u,r,p,D,S,k;return{c(){u=l("div"),r=l("p"),p=v("Loading\u2026"),D=V(),S=l("p"),k=v("\u2588\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592")},l(g){u=c(g,"DIV",{});var i=f(u);r=c(i,"P",{});var E=f(r);p=_(E,"Loading\u2026"),E.forEach(n),D=q(i),S=c(i,"P",{});var I=f(S);k=_(I,"\u2588\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592"),I.forEach(n),i.forEach(n)},m(g,i){ce(g,u,i),e(u,r),e(r,p),e(u,D),e(u,S),e(S,k)},d(g){g&&n(u)}}}function nt(h){let u,r,p,D,S,k,g,i,E,I,x,T,s,A,B,P,H;return{c(){u=l("div"),r=l("div"),p=l("input"),D=V(),S=l("button"),k=v("diffuse the f rest"),i=V(),E=l("div"),I=l("label"),x=l("input"),T=v(`
						 upload img`),s=V(),A=l("p"),B=v("pro tip: upload img by dropping on the canvas"),this.h()},l(y){u=c(y,"DIV",{});var m=f(u);r=c(m,"DIV",{class:!0});var L=f(r);p=c(L,"INPUT",{type:!0,class:!0,placeholder:!0,maxlength:!0}),D=q(L),S=c(L,"BUTTON",{class:!0});var U=f(S);k=_(U,"diffuse the f rest"),U.forEach(n),L.forEach(n),i=q(m),E=c(m,"DIV",{class:!0});var z=f(E);I=c(z,"LABEL",{class:!0});var O=f(I);x=c(O,"INPUT",{accept:!0,style:!0,type:!0}),T=_(O,`
						 upload img`),O.forEach(n),s=q(z),A=c(z,"P",{class:!0});var X=f(A);B=_(X,"pro tip: upload img by dropping on the canvas"),X.forEach(n),z.forEach(n),m.forEach(n),this.h()},h(){o(p,"type","text"),o(p,"class","border-2 py-1"),o(p,"placeholder","Add prompt"),o(p,"maxlength","200"),o(S,"class","bg-blue-500 hover:bg-blue-700 text-white font-bold py-1.5 px-4"),o(r,"class",g="flex gap-x-2 mt-3 items-center justify-center "+(h[1]?"animate-pulse":"")),o(x,"accept","image/*"),bt(x,"display","none"),o(x,"type","file"),o(I,"class","inline border py-1 px-1.5 bg-slate-200 cursor-pointer"),o(A,"class","hidden desktop:inline mt-2 opacity-50"),o(E,"class","mt-4")},m(y,m){ce(y,u,m),e(u,r),e(r,p),et(p,h[0]),e(r,D),e(r,S),e(S,k),e(u,i),e(u,E),e(E,I),e(I,x),h[15](x),e(I,T),e(E,s),e(E,A),e(A,B),P||(H=[de(p,"keydown",h[11]),de(p,"input",h[14]),de(S,"click",h[7]),de(x,"change",h[8])],P=!0)},p(y,m){m[0]&1&&p.value!==y[0]&&et(p,y[0]),m[0]&2&&g!==(g="flex gap-x-2 mt-3 items-center justify-center "+(y[1]?"animate-pulse":""))&&o(r,"class",g)},d(y){y&&n(u),h[15](null),P=!1,rt(H)}}}function vt(h){let u,r,p,D,S,k,g,i,E,I,x,T,s,A,B,P,H,y,m,L,U,z,O,X,fe,Y,ee,ue,he,W,pe,G,me,ge,J,t,a,d,b,w,M,F,te,Z,we,Q,ke,ae,Ce,Se,ne,Ae,Pe,be,Le,Te,$,xe,oe,je,Be,re,Me,Ie,Ne,Fe,N=!h[2]&&at(),j=h[2]&&nt(h);return{c(){u=l("link"),r=l("script"),D=l("script"),k=l("script"),i=V(),E=l("div"),I=l("canvas"),T=V(),s=l("div"),N&&N.c(),A=V(),B=l("div"),P=V(),j&&j.c(),y=V(),m=l("article"),L=l("div"),U=l("p"),z=v("Stable Diffusion model by "),O=l("a"),X=v("CompVis"),fe=v(" and "),Y=l("a"),ee=v("Stability AI"),ue=v(" - Demo by \u{1F917} Hugging Face"),he=V(),W=l("p"),pe=v("Powered by "),G=l("a"),me=v("\u{1F917} Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch"),ge=v(". Based on "),J=l("a"),t=v("notebook by @psuraj28"),a=V(),d=l("p"),b=v("Check out "),w=l("a"),M=v("Stable Diffusion Gradio demo"),F=V(),te=l("h3"),Z=v("LICENSE"),we=V(),Q=l("p"),ke=v("The model is licensed with a "),ae=l("a"),Ce=v("CreativeML Open RAIL-M"),Se=v(" 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 "),ne=l("a"),Ae=v("read the license"),Pe=V(),be=l("h3"),Le=v("Biases and content acknowledgment"),Te=V(),$=l("p"),xe=v("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 "),oe=l("a"),je=v("LAION-5B dataset"),Be=v(", 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 "),re=l("a"),Me=v("model card"),this.h()},l(C){const R=ut('[data-svelte="svelte-bw39ln"]',Ee.head);u=c(R,"LINK",{href:!0,rel:!0}),r=c(R,"SCRIPT",{src:!0});var st=f(r);st.forEach(n),D=c(R,"SCRIPT",{src:!0});var it=f(D);it.forEach(n),k=c(R,"SCRIPT",{src:!0});var lt=f(k);lt.forEach(n),R.forEach(n),i=q(C),E=c(C,"DIV",{class:!0});var De=f(E);I=c(De,"CANVAS",{class:!0}),f(I).forEach(n),T=q(De),s=c(De,"DIV",{class:!0});var se=f(s);N&&N.l(se),A=q(se),B=c(se,"DIV",{id:!0}),f(B).forEach(n),P=q(se),j&&j.l(se),se.forEach(n),De.forEach(n),y=q(C),m=c(C,"ARTICLE",{class:!0});var K=f(m);L=c(K,"DIV",{class:!0});var ie=f(L);U=c(ie,"P",{});var le=f(U);z=_(le,"Stable Diffusion model by "),O=c(le,"A",{href:!0,rel:!0});var Oe=f(O);X=_(Oe,"CompVis"),Oe.forEach(n),fe=_(le," and "),Y=c(le,"A",{href:!0,rel:!0});var He=f(Y);ee=_(He,"Stability AI"),He.forEach(n),ue=_(le," - Demo by \u{1F917} Hugging Face"),le.forEach(n),he=q(ie),W=c(ie,"P",{});var ve=f(W);pe=_(ve,"Powered by "),G=c(ve,"A",{href:!0,rel:!0});var ze=f(G);me=_(ze,"\u{1F917} Diffusers: State-of-the-art diffusion models for image and audio generation in PyTorch"),ze.forEach(n),ge=_(ve,". Based on "),J=c(ve,"A",{href:!0,rel:!0});var We=f(J);t=_(We,"notebook by @psuraj28"),We.forEach(n),ve.forEach(n),a=q(ie),d=c(ie,"P",{});var Re=f(d);b=_(Re,"Check out "),w=c(Re,"A",{href:!0,rel:!0});var Ke=f(w);M=_(Ke,"Stable Diffusion Gradio demo"),Ke.forEach(n),Re.forEach(n),ie.forEach(n),F=q(K),te=c(K,"H3",{});var Ye=f(te);Z=_(Ye,"LICENSE"),Ye.forEach(n),we=q(K),Q=c(K,"P",{});var _e=f(Q);ke=_(_e,"The model is licensed with a "),ae=c(_e,"A",{href:!0,rel:!0});var Ge=f(ae);Ce=_(Ge,"CreativeML Open RAIL-M"),Ge.forEach(n),Se=_(_e," 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 "),ne=c(_e,"A",{href:!0,rel:!0});var Je=f(ne);Ae=_(Je,"read the license"),Je.forEach(n),_e.forEach(n),Pe=q(K),be=c(K,"H3",{});var Qe=f(be);Le=_(Qe,"Biases and content acknowledgment"),Qe.forEach(n),Te=q(K),$=c(K,"P",{});var ye=f($);xe=_(ye,"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 "),oe=c(ye,"A",{href:!0,rel:!0});var Xe=f(oe);je=_(Xe,"LAION-5B dataset"),Xe.forEach(n),Be=_(ye,", 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 "),re=c(ye,"A",{href:!0,rel:!0});var Ze=f(re);Me=_(Ze,"model card"),Ze.forEach(n),ye.forEach(n),K.forEach(n),this.h()},h(){o(u,"href","https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.css"),o(u,"rel","stylesheet"),Ve(r.src,p="https://code.jquery.com/jquery-1.12.4.min.js")||o(r,"src",p),Ve(D.src,S="https://cdnjs.cloudflare.com/ajax/libs/drawingboard.js/0.4.2/drawingboard.min.js")||o(D,"src",S),Ve(k.src,g="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.3.1/iframeResizer.contentWindow.min.js")||o(k,"src",g),o(I,"class",x="border-[1.2px] desktop:mt-[34px] "+(h[6]?"":"hidden")),o(B,"id","board-container"),o(s,"class",H="flex flex-col items-center "+(h[1]?"pointer-events-none":"")),o(E,"class","flex flex-wrap gap-x-4 gap-y-2 justify-center my-8"),o(O,"href","https://huggingface.co/CompVis"),o(O,"rel","nofollow"),o(Y,"href","https://huggingface.co/stabilityai"),o(Y,"rel","nofollow"),o(G,"href","https://github.com/huggingface/diffusers"),o(G,"rel","nofollow"),o(J,"href","https://twitter.com/psuraj28/status/1562039265126670339"),o(J,"rel","nofollow"),o(w,"href","https://huggingface.co/spaces/stabilityai/stable-diffusion"),o(w,"rel","nofollow"),o(L,"class","text-center"),o(ae,"href","https://huggingface.co/spaces/CompVis/stable-diffusion-license"),o(ae,"rel","nofollow"),o(ne,"href","https://huggingface.co/spaces/CompVis/stable-diffusion-license"),o(ne,"rel","nofollow"),o(oe,"href","https://laion.ai/blog/laion-5b/"),o(oe,"rel","nofollow"),o(re,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),o(re,"rel","nofollow"),o(m,"class",Ie="prose-sm px-4 md:px-12 lg:px-56 mb-8 "+(h[2]?"":"hidden"))},m(C,R){e(Ee.head,u),e(Ee.head,r),e(Ee.head,D),e(Ee.head,k),ce(C,i,R),ce(C,E,R),e(E,I),h[12](I),e(E,T),e(E,s),N&&N.m(s,null),e(s,A),e(s,B),h[13](B),e(s,P),j&&j.m(s,null),ce(C,y,R),ce(C,m,R),e(m,L),e(L,U),e(U,z),e(U,O),e(O,X),e(U,fe),e(U,Y),e(Y,ee),e(U,ue),e(L,he),e(L,W),e(W,pe),e(W,G),e(G,me),e(W,ge),e(W,J),e(J,t),e(L,a),e(L,d),e(d,b),e(d,w),e(w,M),e(m,F),e(m,te),e(te,Z),e(m,we),e(m,Q),e(Q,ke),e(Q,ae),e(ae,Ce),e(Q,Se),e(Q,ne),e(ne,Ae),e(m,Pe),e(m,be),e(be,Le),e(m,Te),e(m,$),e($,xe),e($,oe),e(oe,je),e($,Be),e($,re),e(re,Me),Ne||(Fe=[de(tt,"drop",ht(pt(h[9]))),de(tt,"paste",h[10])],Ne=!0)},p(C,R){R[0]&64&&x!==(x="border-[1.2px] desktop:mt-[34px] "+(C[6]?"":"hidden"))&&o(I,"class",x),C[2]?N&&(N.d(1),N=null):N||(N=at(),N.c(),N.m(s,A)),C[2]?j?j.p(C,R):(j=nt(C),j.c(),j.m(s,null)):j&&(j.d(1),j=null),R[0]&2&&H!==(H="flex flex-col items-center "+(C[1]?"pointer-events-none":""))&&o(s,"class",H),R[0]&4&&Ie!==(Ie="prose-sm px-4 md:px-12 lg:px-56 mb-8 "+(C[2]?"":"hidden"))&&o(m,"class",Ie)},i:$e,o:$e,d(C){n(u),n(r),n(D),n(k),C&&n(i),C&&n(E),h[12](null),N&&N.d(),h[13](null),j&&j.d(),C&&n(y),C&&n(m),Ne=!1,rt(Fe)}}}const Ue=500,ot=3e3;function _t(){window.createImageBitmap=async function(h){return new Promise((u,r)=>{const p=document.createElement("canvas"),D=p.getContext("2d");p.width=h.width,p.height=h.height,D.putImageData(h,0,0);const S=p.toDataURL(),k=document.createElement("img");k.addEventListener("load",()=>{u(k)}),k.src=S})}}function yt(){const h=document.querySelectorAll("a");for(const u of h)u.target="_blank"}function Et(h,u,r){let p="",D=!1,S=!1,k,g,i,E,I,x,T,s=400,A,B,P,H=!1,y=[];async function m(){if(!i)return;const t=i.createImageData(g.width,g.height),a=t.data;for(let w=0,M=a.length;w<M;w+=4)a[w]=40*Math.random()*7,a[w+1]=40*Math.random()*7,a[w+2]=40*Math.random()*7,a[w+3]=255;const d=await createImageBitmap(t),b=performance.now()-E;i.globalAlpha=Math.min(b,ot)/ot,i.drawImage(d,0,0,s,s),D&&window.requestAnimationFrame(m)}function L(t){if(!i)return;const a=performance.now()-I;i.globalAlpha=Math.min(a,Ue)/Ue,i.drawImage(t,0,0,s,s),a<Ue&&window.requestAnimationFrame(()=>L(t))}async function U(t){const a=t.toDataURL("png"),b=await(await fetch(a)).blob(),w=new File([b],"canvas shot.png",{type:"image/png"}),M=t.getContext("2d").getImageData(0,0,s,s),F=await createImageBitmap(M);return{imgFile:w,imgBitmap:F}}async function z(){if(!p)return alert("Please add prompt");if(!g||!i)return;T&&clearInterval(T),r(1,D=!0),r(6,H=!1),Y(),E=performance.now(),m();const{imgFile:t,imgBitmap:a}=await U(g),d=new FormData;d.append("prompt",p),d.append("strength","0.85"),d.append("image",t);try{const b=await fetch("https://sdb.pcuenca.net/i2i",{method:"POST",body:d}),w=JSON.parse(await b.text()),{images:M}=w;if(!M.length)return alert("All the results were flagged. Please try again with diffeerent sketch + prompt");y=await Promise.all(M.map(async te=>{const Z=new Image;return Z.src=`data:image/png;base64, ${te}`,await new Promise((we,Q)=>{Z.onload=()=>we(Z)}),Z})),y.push(a),r(6,H=!0);let F=0;I=performance.now(),L(y[F%y.length]),x=()=>{T&&clearInterval(T),I=performance.now(),F=F+1,L(y[F%y.length])},T=setInterval(()=>{F=F+1,I=performance.now(),L(y[F%y.length])},2500),S||O()}catch(b){console.error(b),alert("Error happened, queue might be full. Please try again in a bit :)")}finally{r(1,D=!1)}}function O(){const t=document.createElement("div");t.className="drawing-board-control";const a=document.createElement("button");a.innerHTML="\u23EF",a.onclick=x,t.append(a);const d=document.querySelector(".drawing-board-controls");d&&y.length>1&&(d.appendChild(t),S=!0,r(3,A.onclick=()=>{T&&clearInterval(T)},A))}function X(){const t=document.createElement("div");t.className="drawing-board-control";const a=document.createElement("button");a.innerHTML="\u{1F9F9}",a.onclick=()=>{i==null||i.clearRect(0,0,s,s),y=[],r(6,H=!1)},t.append(a);const d=document.querySelector(".drawing-board-controls");d&&d.appendChild(t)}function fe(){const t=document.createElement("div");t.className="drawing-board-control";const a=document.createElement("button");a.innerHTML="\u2B07\uFE0F",a.onclick=()=>{if(!g)return;const b=document.createElement("a"),w=Date.now()%200;b.download=`diffuse-the-rest-${w}.png`,b.href=g.toDataURL(),b.click()},t.append(a);const d=document.querySelector(".drawing-board-controls");d&&d.appendChild(t)}function Y(){const t=P.getContext("2d");r(5,P.width=g.width,P),r(5,P.height=g.height,P),t.drawImage(g,0,0)}async function ee(t){T&&clearInterval(T);const a=new Image;a.src=URL.createObjectURL(t),await new Promise((w,M)=>{a.onload=()=>w(a)});const{width:d,height:b}=a;if(d==b)i==null||i.drawImage(a,0,0,d,b,0,0,s,s);else if(d>b){const w=Math.floor(s*b/d),M=Math.floor((s-w)/2);i==null||i.drawImage(a,0,0,d,b,0,M,s,w)}else{const w=Math.floor(s*d/b),M=Math.floor((s-w)/2);i==null||i.drawImage(a,0,0,d,b,M,0,w,s)}}function ue(){var a;const t=(a=B.files)==null?void 0:a[0];t&&ee(t)}function he(t){var b;if(!((b=t.dataTransfer)!=null&&b.files))return;t.preventDefault();const d=Array.from(t.dataTransfer.files)[0];ee(d)}function W(t){if(!t.clipboardData)return;const a=Array.from(t.clipboardData.files);if(a.length===0)return;t.preventDefault();const d=a[0];ee(d)}function pe(t){t.code==="Enter"&&(t.preventDefault(),z())}mt(async()=>{typeof createImageBitmap>"u"&&_t();const{innerWidth:t}=window;s=Math.min(s,Math.floor(t*.75)),r(3,A.style.width=`${s}px`,A),r(3,A.style.height=`${s}px`,A),r(5,P.style.width=`${s}px`,P),r(5,P.style.height=`${s}px`,P),await gt(),k=new window.DrawingBoard.Board("board-container",{size:10,controls:["Color",{Size:{type:"dropdown"}},{DrawingMode:{filler:!1}}],webStorage:!1,enlargeYourContainer:!0}),r(2,g=k.canvas),i=g.getContext("2d"),r(2,g.ondragover=function(a){return a.preventDefault(),!1},g),X(),fe(),yt()});function G(t){qe[t?"unshift":"push"](()=>{P=t,r(5,P)})}function me(t){qe[t?"unshift":"push"](()=>{A=t,r(3,A)})}function ge(){p=this.value,r(0,p)}function J(t){qe[t?"unshift":"push"](()=>{B=t,r(4,B)})}return[p,D,g,A,B,P,H,z,ue,he,W,pe,G,me,ge,J]}class Dt extends ct{constructor(u){super(),dt(this,u,Et,vt,ft,{},null,[-1,-1])}}export{Dt as default};