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