import{S as mt,i as ct,s as ht,e as l,k as u,w as N,t as n,M as dt,c as r,d as t,m,a as f,x as B,h as s,b as p,N as gt,G as o,g as a,y as V,L as bt,q as F,o as R,B as L,v as yt}from"../../chunks/vendor-hf-doc-builder.js";import{I as wt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as _e}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as _t}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function vt(Qe){let g,X,b,y,Y,P,ve,Q,$e,H,E,ee,D,Pe,te,w,Ee,J,ke,Te,oe,c,je,U,Me,Ze,k,Ie,xe,ie,h,De,G,Je,Ue,T,z,Ge,qe,ae,j,ne,_,Ce,q,We,Ae,se,M,le,v,Se,O,Ne,Be,re,Z,fe,$,Ve,I,K,Fe,Re,pe,C,Le,ue,x,me,W,Ye,ce,d,ze,he;return P=new wt({}),E=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"}]}}),j=new _e({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBZ2VuZXJhdG9yJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyKQ==",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;runwayml/stable-diffusion-v1-5&quot;</span>)`}}),M=new _e({props:{code:"Z2VuZXJhdG9yLnRvKCUyMmN1ZGElMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>generator.to(<span class="hljs-string">&quot;cuda&quot;</span>)'}}),Z=new _e({props:{code:"aW1hZ2UlMjAlM0QlMjBnZW5lcmF0b3IoJTIyQW4lMjBpbWFnZSUyMG9mJTIwYSUyMHNxdWlycmVsJTIwaW4lMjBQaWNhc3NvJTIwc3R5bGUlMjIpLmltYWdlcyU1QjAlNUQ=",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>]'}}),x=new _e({props:{code:"aW1hZ2Uuc2F2ZSglMjJpbWFnZV9vZl9zcXVpcnJlbF9wYWludGluZy5wbmclMjIp",highlighted:'<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;image_of_squirrel_painting.png&quot;</span>)'}}),{c(){g=l("meta"),X=u(),b=l("h1"),y=l("a"),Y=l("span"),N(P.$$.fragment),ve=u(),Q=l("span"),$e=n("Conditional image generation"),H=u(),N(E.$$.fragment),ee=u(),D=l("p"),Pe=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."),te=u(),w=l("p"),Ee=n("The "),J=l("a"),ke=n("DiffusionPipeline"),Te=n(" is the easiest way to use a pre-trained diffusion system for inference."),oe=u(),c=l("p"),je=n("Start by creating an instance of "),U=l("a"),Me=n("DiffusionPipeline"),Ze=n(" and specify which pipeline "),k=l("a"),Ie=n("checkpoint"),xe=n(" you would like to download."),ie=u(),h=l("p"),De=n("In this guide, you\u2019ll use "),G=l("a"),Je=n("DiffusionPipeline"),Ue=n(" for text-to-image generation with "),T=l("a"),z=l("code"),Ge=n("runwayml/stable-diffusion-v1-5"),qe=n(":"),ae=u(),N(j.$$.fragment),ne=u(),_=l("p"),Ce=n("The "),q=l("a"),We=n("DiffusionPipeline"),Ae=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:`),se=u(),N(M.$$.fragment),le=u(),v=l("p"),Se=n("Now you can use the "),O=l("code"),Ne=n("generator"),Be=n(" on your text prompt:"),re=u(),N(Z.$$.fragment),fe=u(),$=l("p"),Ve=n("The output is by default wrapped into a "),I=l("a"),K=l("code"),Fe=n("PIL.Image"),Re=n(" object."),pe=u(),C=l("p"),Le=n("You can save the image by calling:"),ue=u(),N(x.$$.fragment),me=u(),W=l("p"),Ye=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!"),ce=u(),d=l("iframe"),this.h()},l(e){const i=dt('[data-svelte="svelte-1phssyn"]',document.head);g=r(i,"META",{name:!0,content:!0}),i.forEach(t),X=m(e),b=r(e,"H1",{class:!0});var de=f(b);y=r(de,"A",{id:!0,class:!0,href:!0});var Oe=f(y);Y=r(Oe,"SPAN",{});var Ke=f(Y);B(P.$$.fragment,Ke),Ke.forEach(t),Oe.forEach(t),ve=m(de),Q=r(de,"SPAN",{});var Xe=f(Q);$e=s(Xe,"Conditional image generation"),Xe.forEach(t),de.forEach(t),H=m(e),B(E.$$.fragment,e),ee=m(e),D=r(e,"P",{});var He=f(D);Pe=s(He,"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."),He.forEach(t),te=m(e),w=r(e,"P",{});var ge=f(w);Ee=s(ge,"The "),J=r(ge,"A",{href:!0});var et=f(J);ke=s(et,"DiffusionPipeline"),et.forEach(t),Te=s(ge," is the easiest way to use a pre-trained diffusion system for inference."),ge.forEach(t),oe=m(e),c=r(e,"P",{});var A=f(c);je=s(A,"Start by creating an instance of "),U=r(A,"A",{href:!0});var tt=f(U);Me=s(tt,"DiffusionPipeline"),tt.forEach(t),Ze=s(A," and specify which pipeline "),k=r(A,"A",{href:!0,rel:!0});var ot=f(k);Ie=s(ot,"checkpoint"),ot.forEach(t),xe=s(A," you would like to download."),A.forEach(t),ie=m(e),h=r(e,"P",{});var S=f(h);De=s(S,"In this guide, you\u2019ll use "),G=r(S,"A",{href:!0});var it=f(G);Je=s(it,"DiffusionPipeline"),it.forEach(t),Ue=s(S," for text-to-image generation with "),T=r(S,"A",{href:!0,rel:!0});var at=f(T);z=r(at,"CODE",{});var nt=f(z);Ge=s(nt,"runwayml/stable-diffusion-v1-5"),nt.forEach(t),at.forEach(t),qe=s(S,":"),S.forEach(t),ae=m(e),B(j.$$.fragment,e),ne=m(e),_=r(e,"P",{});var be=f(_);Ce=s(be,"The "),q=r(be,"A",{href:!0});var st=f(q);We=s(st,"DiffusionPipeline"),st.forEach(t),Ae=s(be,` 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:`),be.forEach(t),se=m(e),B(M.$$.fragment,e),le=m(e),v=r(e,"P",{});var ye=f(v);Se=s(ye,"Now you can use the "),O=r(ye,"CODE",{});var lt=f(O);Ne=s(lt,"generator"),lt.forEach(t),Be=s(ye," on your text prompt:"),ye.forEach(t),re=m(e),B(Z.$$.fragment,e),fe=m(e),$=r(e,"P",{});var we=f($);Ve=s(we,"The output is by default wrapped into a "),I=r(we,"A",{href:!0,rel:!0});var rt=f(I);K=r(rt,"CODE",{});var ft=f(K);Fe=s(ft,"PIL.Image"),ft.forEach(t),rt.forEach(t),Re=s(we," object."),we.forEach(t),pe=m(e),C=r(e,"P",{});var pt=f(C);Le=s(pt,"You can save the image by calling:"),pt.forEach(t),ue=m(e),B(x.$$.fragment,e),me=m(e),W=r(e,"P",{});var ut=f(W);Ye=s(ut,"Try out the Spaces below, and feel free to play around with the guidance scale parameter to see how it affects the image quality!"),ut.forEach(t),ce=m(e),d=r(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),f(d).forEach(t),this.h()},h(){p(g,"name","hf:doc:metadata"),p(g,"content",JSON.stringify($t)),p(y,"id","conditional-image-generation"),p(y,"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(y,"href","#conditional-image-generation"),p(b,"class","relative group"),p(J,"href","/docs/diffusers/v0.17.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(U,"href","/docs/diffusers/v0.17.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(k,"href","https://huggingface.co/models?library=diffusers&sort=downloads"),p(k,"rel","nofollow"),p(G,"href","/docs/diffusers/v0.17.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(T,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),p(T,"rel","nofollow"),p(q,"href","/docs/diffusers/v0.17.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),p(I,"href","https://pillow.readthedocs.io/en/stable/reference/Image.html?highlight=image#the-image-class"),p(I,"rel","nofollow"),gt(d.src,ze="https://stabilityai-stable-diffusion.hf.space")||p(d,"src",ze),p(d,"frameborder","0"),p(d,"width","850"),p(d,"height","500")},m(e,i){o(document.head,g),a(e,X,i),a(e,b,i),o(b,y),o(y,Y),V(P,Y,null),o(b,ve),o(b,Q),o(Q,$e),a(e,H,i),V(E,e,i),a(e,ee,i),a(e,D,i),o(D,Pe),a(e,te,i),a(e,w,i),o(w,Ee),o(w,J),o(J,ke),o(w,Te),a(e,oe,i),a(e,c,i),o(c,je),o(c,U),o(U,Me),o(c,Ze),o(c,k),o(k,Ie),o(c,xe),a(e,ie,i),a(e,h,i),o(h,De),o(h,G),o(G,Je),o(h,Ue),o(h,T),o(T,z),o(z,Ge),o(h,qe),a(e,ae,i),V(j,e,i),a(e,ne,i),a(e,_,i),o(_,Ce),o(_,q),o(q,We),o(_,Ae),a(e,se,i),V(M,e,i),a(e,le,i),a(e,v,i),o(v,Se),o(v,O),o(O,Ne),o(v,Be),a(e,re,i),V(Z,e,i),a(e,fe,i),a(e,$,i),o($,Ve),o($,I),o(I,K),o(K,Fe),o($,Re),a(e,pe,i),a(e,C,i),o(C,Le),a(e,ue,i),V(x,e,i),a(e,me,i),a(e,W,i),o(W,Ye),a(e,ce,i),a(e,d,i),he=!0},p:bt,i(e){he||(F(P.$$.fragment,e),F(E.$$.fragment,e),F(j.$$.fragment,e),F(M.$$.fragment,e),F(Z.$$.fragment,e),F(x.$$.fragment,e),he=!0)},o(e){R(P.$$.fragment,e),R(E.$$.fragment,e),R(j.$$.fragment,e),R(M.$$.fragment,e),R(Z.$$.fragment,e),R(x.$$.fragment,e),he=!1},d(e){t(g),e&&t(X),e&&t(b),L(P),e&&t(H),L(E,e),e&&t(ee),e&&t(D),e&&t(te),e&&t(w),e&&t(oe),e&&t(c),e&&t(ie),e&&t(h),e&&t(ae),L(j,e),e&&t(ne),e&&t(_),e&&t(se),L(M,e),e&&t(le),e&&t(v),e&&t(re),L(Z,e),e&&t(fe),e&&t($),e&&t(pe),e&&t(C),e&&t(ue),L(x,e),e&&t(me),e&&t(W),e&&t(ce),e&&t(d)}}}const $t={local:"conditional-image-generation",title:"Conditional image generation"};function Pt(Qe){return yt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Mt extends mt{constructor(g){super();ct(this,g,Pt,vt,ht,{})}}export{Mt as default,$t as metadata};
