import{S as pt,i as ut,s as mt,e as l,k as u,w as Y,t as n,M as ct,c as r,d as t,m,a as f,x as z,h as s,b as p,N as gt,G as i,g as a,y as F,L as ht,q as O,o as V,B as R,v as dt}from"../../chunks/vendor-hf-doc-builder.js";import{I as bt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as we}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as _t}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function wt(He){let d,W,b,_,H,P,ye,J,ve,X,k,Z,A,$e,ee,w,Pe,I,ke,Ee,te,c,De,S,xe,je,E,qe,Te,ie,g,Ce,N,Ae,Ie,D,Se,Ne,oe,x,ae,y,Le,L,Me,Ge,ne,j,se,v,Ue,K,Be,Ye,le,q,re,$,ze,T,Q,Fe,Oe,fe,M,Ve,pe,C,ue,G,Re,me,h,Je,ce;return P=new bt({}),k=new _t({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/conditional_image_generation.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/conditional_image_generation.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/conditional_image_generation.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/conditional_image_generation.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/conditional_image_generation.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/conditional_image_generation.ipynb"}]}}),x=new we({props:{code:`from diffusers import DiffusionPipeline

generator = DiffusionPipeline.from_pretrained("CompVis/ldm-text2im-large-256")`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>generator = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/ldm-text2im-large-256&quot;</span>)`}}),j=new we({props:{code:'generator.to("cuda")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>generator.to(<span class="hljs-string">&quot;cuda&quot;</span>)'}}),q=new we({props:{code:'image = generator("An image of a squirrel in Picasso style").images[0]',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>image = generator(<span class="hljs-string">&quot;An image of a squirrel in Picasso style&quot;</span>).images[<span class="hljs-number">0</span>]'}}),C=new we({props:{code:'image.save("image_of_squirrel_painting.png")',highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;image_of_squirrel_painting.png&quot;</span>)'}}),{c(){d=l("meta"),W=u(),b=l("h1"),_=l("a"),H=l("span"),Y(P.$$.fragment),ye=u(),J=l("span"),ve=n("Conditional image generation"),X=u(),Y(k.$$.fragment),Z=u(),A=l("p"),$e=n("Conditional image generation allows you to generate images from a text prompt. The text is converted into embeddings which are used to condition the model to generate an image from noise."),ee=u(),w=l("p"),Pe=n("The "),I=l("a"),ke=n("DiffusionPipeline"),Ee=n(" is the easiest way to use a pre-trained diffusion system for inference."),te=u(),c=l("p"),De=n("Start by creating an instance of "),S=l("a"),xe=n("DiffusionPipeline"),je=n(" and specify which pipeline "),E=l("a"),qe=n("checkpoint"),Te=n(" you would like to download."),ie=u(),g=l("p"),Ce=n("In this guide, you\u2019ll use "),N=l("a"),Ae=n("DiffusionPipeline"),Ie=n(" for text-to-image generation with "),D=l("a"),Se=n("Latent Diffusion"),Ne=n(":"),oe=u(),Y(x.$$.fragment),ae=u(),y=l("p"),Le=n("The "),L=l("a"),Me=n("DiffusionPipeline"),Ge=n(` downloads and caches all modeling, tokenization, and scheduling components.
Because the model consists of roughly 1.4 billion parameters, we strongly recommend running it on a GPU.
You can move the generator object to a GPU, just like you would in PyTorch:`),ne=u(),Y(j.$$.fragment),se=u(),v=l("p"),Ue=n("Now you can use the "),K=l("code"),Be=n("generator"),Ye=n(" on your text prompt:"),le=u(),Y(q.$$.fragment),re=u(),$=l("p"),ze=n("The output is by default wrapped into a "),T=l("a"),Q=l("code"),Fe=n("PIL.Image"),Oe=n(" object."),fe=u(),M=l("p"),Ve=n("You can save the image by calling:"),pe=u(),Y(C.$$.fragment),ue=u(),G=l("p"),Re=n("Try out the Spaces below, and feel free to play around with the guidance scale parameter to see how it affects the image quality!"),me=u(),h=l("iframe"),this.h()},l(e){const o=ct('[data-svelte="svelte-1phssyn"]',document.head);d=r(o,"META",{name:!0,content:!0}),o.forEach(t),W=m(e),b=r(e,"H1",{class:!0});var ge=f(b);_=r(ge,"A",{id:!0,class:!0,href:!0});var Ke=f(_);H=r(Ke,"SPAN",{});var Qe=f(H);z(P.$$.fragment,Qe),Qe.forEach(t),Ke.forEach(t),ye=m(ge),J=r(ge,"SPAN",{});var We=f(J);ve=s(We,"Conditional image generation"),We.forEach(t),ge.forEach(t),X=m(e),z(k.$$.fragment,e),Z=m(e),A=r(e,"P",{});var Xe=f(A);$e=s(Xe,"Conditional image generation allows you to generate images from a text prompt. The text is converted into embeddings which are used to condition the model to generate an image from noise."),Xe.forEach(t),ee=m(e),w=r(e,"P",{});var he=f(w);Pe=s(he,"The "),I=r(he,"A",{href:!0});var Ze=f(I);ke=s(Ze,"DiffusionPipeline"),Ze.forEach(t),Ee=s(he," is the easiest way to use a pre-trained diffusion system for inference."),he.forEach(t),te=m(e),c=r(e,"P",{});var U=f(c);De=s(U,"Start by creating an instance of "),S=r(U,"A",{href:!0});var et=f(S);xe=s(et,"DiffusionPipeline"),et.forEach(t),je=s(U," and specify which pipeline "),E=r(U,"A",{href:!0,rel:!0});var tt=f(E);qe=s(tt,"checkpoint"),tt.forEach(t),Te=s(U," you would like to download."),U.forEach(t),ie=m(e),g=r(e,"P",{});var B=f(g);Ce=s(B,"In this guide, you\u2019ll use "),N=r(B,"A",{href:!0});var it=f(N);Ae=s(it,"DiffusionPipeline"),it.forEach(t),Ie=s(B," for text-to-image generation with "),D=r(B,"A",{href:!0,rel:!0});var ot=f(D);Se=s(ot,"Latent Diffusion"),ot.forEach(t),Ne=s(B,":"),B.forEach(t),oe=m(e),z(x.$$.fragment,e),ae=m(e),y=r(e,"P",{});var de=f(y);Le=s(de,"The "),L=r(de,"A",{href:!0});var at=f(L);Me=s(at,"DiffusionPipeline"),at.forEach(t),Ge=s(de,` downloads and caches all modeling, tokenization, and scheduling components.
Because the model consists of roughly 1.4 billion parameters, we strongly recommend running it on a GPU.
You can move the generator object to a GPU, just like you would in PyTorch:`),de.forEach(t),ne=m(e),z(j.$$.fragment,e),se=m(e),v=r(e,"P",{});var be=f(v);Ue=s(be,"Now you can use the "),K=r(be,"CODE",{});var nt=f(K);Be=s(nt,"generator"),nt.forEach(t),Ye=s(be," on your text prompt:"),be.forEach(t),le=m(e),z(q.$$.fragment,e),re=m(e),$=r(e,"P",{});var _e=f($);ze=s(_e,"The output is by default wrapped into a "),T=r(_e,"A",{href:!0,rel:!0});var st=f(T);Q=r(st,"CODE",{});var lt=f(Q);Fe=s(lt,"PIL.Image"),lt.forEach(t),st.forEach(t),Oe=s(_e," object."),_e.forEach(t),fe=m(e),M=r(e,"P",{});var rt=f(M);Ve=s(rt,"You can save the image by calling:"),rt.forEach(t),pe=m(e),z(C.$$.fragment,e),ue=m(e),G=r(e,"P",{});var ft=f(G);Re=s(ft,"Try out the Spaces below, and feel free to play around with the guidance scale parameter to see how it affects the image quality!"),ft.forEach(t),me=m(e),h=r(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),f(h).forEach(t),this.h()},h(){p(d,"name","hf:doc:metadata"),p(d,"content",JSON.stringify(yt)),p(_,"id","conditional-image-generation"),p(_,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),p(_,"href","#conditional-image-generation"),p(b,"class","relative group"),p(I,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(S,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(E,"href","https://huggingface.co/models?library=diffusers&sort=downloads"),p(E,"rel","nofollow"),p(N,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(D,"href","https://huggingface.co/CompVis/ldm-text2im-large-256"),p(D,"rel","nofollow"),p(L,"href","/docs/diffusers/v0.16.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(T,"href","https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=image#the-image-class"),p(T,"rel","nofollow"),gt(h.src,Je="https://stabilityai-stable-diffusion.hf.space")||p(h,"src",Je),p(h,"frameborder","0"),p(h,"width","850"),p(h,"height","500")},m(e,o){i(document.head,d),a(e,W,o),a(e,b,o),i(b,_),i(_,H),F(P,H,null),i(b,ye),i(b,J),i(J,ve),a(e,X,o),F(k,e,o),a(e,Z,o),a(e,A,o),i(A,$e),a(e,ee,o),a(e,w,o),i(w,Pe),i(w,I),i(I,ke),i(w,Ee),a(e,te,o),a(e,c,o),i(c,De),i(c,S),i(S,xe),i(c,je),i(c,E),i(E,qe),i(c,Te),a(e,ie,o),a(e,g,o),i(g,Ce),i(g,N),i(N,Ae),i(g,Ie),i(g,D),i(D,Se),i(g,Ne),a(e,oe,o),F(x,e,o),a(e,ae,o),a(e,y,o),i(y,Le),i(y,L),i(L,Me),i(y,Ge),a(e,ne,o),F(j,e,o),a(e,se,o),a(e,v,o),i(v,Ue),i(v,K),i(K,Be),i(v,Ye),a(e,le,o),F(q,e,o),a(e,re,o),a(e,$,o),i($,ze),i($,T),i(T,Q),i(Q,Fe),i($,Oe),a(e,fe,o),a(e,M,o),i(M,Ve),a(e,pe,o),F(C,e,o),a(e,ue,o),a(e,G,o),i(G,Re),a(e,me,o),a(e,h,o),ce=!0},p:ht,i(e){ce||(O(P.$$.fragment,e),O(k.$$.fragment,e),O(x.$$.fragment,e),O(j.$$.fragment,e),O(q.$$.fragment,e),O(C.$$.fragment,e),ce=!0)},o(e){V(P.$$.fragment,e),V(k.$$.fragment,e),V(x.$$.fragment,e),V(j.$$.fragment,e),V(q.$$.fragment,e),V(C.$$.fragment,e),ce=!1},d(e){t(d),e&&t(W),e&&t(b),R(P),e&&t(X),R(k,e),e&&t(Z),e&&t(A),e&&t(ee),e&&t(w),e&&t(te),e&&t(c),e&&t(ie),e&&t(g),e&&t(oe),R(x,e),e&&t(ae),e&&t(y),e&&t(ne),R(j,e),e&&t(se),e&&t(v),e&&t(le),R(q,e),e&&t(re),e&&t($),e&&t(fe),e&&t(M),e&&t(pe),R(C,e),e&&t(ue),e&&t(G),e&&t(me),e&&t(h)}}}const yt={local:"conditional-image-generation",title:"Conditional image generation"};function vt(He){return dt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Dt extends pt{constructor(d){super();ut(this,d,vt,wt,mt,{})}}export{Dt as default,yt as metadata};
