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