import{S as Mt,i as Zt,s as _t,e as a,k as m,w as $,t as r,M as Tt,c as o,d as t,m as f,a as n,x as j,h as p,b as c,N as Ee,G as l,g as i,y as k,q as E,o as W,B as U,v as Gt}from"../../chunks/vendor-hf-doc-builder.js";import{T as It}from"../../chunks/Tip-hf-doc-builder.js";import{I as $t}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as oe}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as jt}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function kt(ne){let u,M,h,g,v;return{c(){u=a("p"),M=r("\u{1F4A1} "),h=a("code"),g=r("strength"),v=r(" is a value between 0.0 and 1.0 that controls the amount of noise added to the input image. Values that approach 1.0 allow for lots of variations but will also produce images that are not semantically consistent with the input.")},l(d){u=o(d,"P",{});var b=n(u);M=p(b,"\u{1F4A1} "),h=o(b,"CODE",{});var Z=n(h);g=p(Z,"strength"),Z.forEach(t),v=p(b," is a value between 0.0 and 1.0 that controls the amount of noise added to the input image. Values that approach 1.0 allow for lots of variations but will also produce images that are not semantically consistent with the input."),b.forEach(t)},m(d,b){i(d,u,b),l(u,M),l(u,h),l(h,g),l(u,v)},d(d){d&&t(u)}}}function Et(ne){let u,M,h,g,v,d,b,Z,We,re,B,pe,_,Ue,Q,Be,Se,me,P,De,fe,S,ce,y,Ne,z,Fe,Re,D,K,Xe,Ye,ue,N,he,H,Ve,de,F,ge,R,ee,tt,be,T,ye,G,Ce,te,xe,Qe,we,X,Je,Y,se,st,ve,L,Pe,Me,V,Ze,C,le,lt,_e,w,ze,ie,He,Le,ae,qe,Ae,Te,I,Oe,q,Ke,et,Ge,J,it,Ie;return d=new $t({}),B=new jt({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/img2img.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/img2img.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/img2img.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/img2img.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/img2img.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/img2img.ipynb"}]}}),S=new oe({props:{code:"IXBpcCUyMGluc3RhbGwlMjBkaWZmdXNlcnMlMjB0cmFuc2Zvcm1lcnMlMjBmdGZ5JTIwYWNjZWxlcmF0ZQ==",highlighted:"!pip install diffusers transformers ftfy accelerate"}}),N=new oe({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjByZXF1ZXN0cyUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQWZyb20lMjBpbyUyMGltcG9ydCUyMEJ5dGVzSU8lMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uSW1nMkltZ1BpcGVsaW5lJTBBJTBBZGV2aWNlJTIwJTNEJTIwJTIyY3VkYSUyMiUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25JbWcySW1nUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMm5pdHJvc29ja2UlMkZHaGlibGktRGlmZnVzaW9uJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KS50byglMEElMjAlMjAlMjAlMjBkZXZpY2UlMEEp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">from</span> io <span class="hljs-keyword">import</span> BytesIO
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionImg2ImgPipeline

device = <span class="hljs-string">&quot;cuda&quot;</span>
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(<span class="hljs-string">&quot;nitrosocke/Ghibli-Diffusion&quot;</span>, torch_dtype=torch.float16).to(
    device
)`}}),F=new oe({props:{code:"dXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZyYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tJTJGQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24lMkZtYWluJTJGYXNzZXRzJTJGc3RhYmxlLXNhbXBsZXMlMkZpbWcyaW1nJTJGc2tldGNoLW1vdW50YWlucy1pbnB1dC5qcGclMjIlMEElMEFyZXNwb25zZSUyMCUzRCUyMHJlcXVlc3RzLmdldCh1cmwpJTBBaW5pdF9pbWFnZSUyMCUzRCUyMEltYWdlLm9wZW4oQnl0ZXNJTyhyZXNwb25zZS5jb250ZW50KSkuY29udmVydCglMjJSR0IlMjIpJTBBaW5pdF9pbWFnZS50aHVtYm5haWwoKDc2OCUyQyUyMDc2OCkpJTBBaW5pdF9pbWFnZQ==",highlighted:`url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg&quot;</span>

response = requests.get(url)
init_image = Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)
init_image.thumbnail((<span class="hljs-number">768</span>, <span class="hljs-number">768</span>))
init_image`}}),T=new It({props:{$$slots:{default:[kt]},$$scope:{ctx:ne}}}),X=new oe({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyZ2hpYmxpJTIwc3R5bGUlMkMlMjBhJTIwZmFudGFzeSUyMGxhbmRzY2FwZSUyMHdpdGglMjBjYXN0bGVzJTIyJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRGRldmljZSkubWFudWFsX3NlZWQoMTAyNCklMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTNEcHJvbXB0JTJDJTIwaW1hZ2UlM0Rpbml0X2ltYWdlJTJDJTIwc3RyZW5ndGglM0QwLjc1JTJDJTIwZ3VpZGFuY2Vfc2NhbGUlM0Q3LjUlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",highlighted:`prompt = <span class="hljs-string">&quot;ghibli style, a fantasy landscape with castles&quot;</span>
generator = torch.Generator(device=device).manual_seed(<span class="hljs-number">1024</span>)
image = pipe(prompt=prompt, image=init_image, strength=<span class="hljs-number">0.75</span>, guidance_scale=<span class="hljs-number">7.5</span>, generator=generator).images[<span class="hljs-number">0</span>]
image`}}),V=new oe({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMExNU0Rpc2NyZXRlU2NoZWR1bGVyJTBBJTBBbG1zJTIwJTNEJTIwTE1TRGlzY3JldGVTY2hlZHVsZXIuZnJvbV9jb25maWcocGlwZS5zY2hlZHVsZXIuY29uZmlnKSUwQXBpcGUuc2NoZWR1bGVyJTIwJTNEJTIwbG1zJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRGRldmljZSkubWFudWFsX3NlZWQoMTAyNCklMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTNEcHJvbXB0JTJDJTIwaW1hZ2UlM0Rpbml0X2ltYWdlJTJDJTIwc3RyZW5ndGglM0QwLjc1JTJDJTIwZ3VpZGFuY2Vfc2NhbGUlM0Q3LjUlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> LMSDiscreteScheduler

lms = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
pipe.scheduler = lms
generator = torch.Generator(device=device).manual_seed(<span class="hljs-number">1024</span>)
image = pipe(prompt=prompt, image=init_image, strength=<span class="hljs-number">0.75</span>, guidance_scale=<span class="hljs-number">7.5</span>, generator=generator).images[<span class="hljs-number">0</span>]
image`}}),{c(){u=a("meta"),M=m(),h=a("h1"),g=a("a"),v=a("span"),$(d.$$.fragment),b=m(),Z=a("span"),We=r("Text-guided image-to-image generation"),re=m(),$(B.$$.fragment),pe=m(),_=a("p"),Ue=r("The "),Q=a("a"),Be=r("StableDiffusionImg2ImgPipeline"),Se=r(" lets you pass a text prompt and an initial image to condition the generation of new images."),me=m(),P=a("p"),De=r("Before you begin, make sure you have all the necessary libraries installed:"),fe=m(),$(S.$$.fragment),ce=m(),y=a("p"),Ne=r("Get started by creating a "),z=a("a"),Fe=r("StableDiffusionImg2ImgPipeline"),Re=r(" with a pretrained Stable Diffusion model like "),D=a("a"),K=a("code"),Xe=r("nitrosocke/Ghibli-Diffusion"),Ye=r("."),ue=m(),$(N.$$.fragment),he=m(),H=a("p"),Ve=r("Download and preprocess an initial image so you can pass it to the pipeline:"),de=m(),$(F.$$.fragment),ge=m(),R=a("div"),ee=a("img"),be=m(),$(T.$$.fragment),ye=m(),G=a("p"),Ce=r("Define the prompt (for this checkpoint finetuned on Ghibli-style art, you need to prefix the prompt with the "),te=a("code"),xe=r("ghibli style"),Qe=r(" tokens) and run the pipeline:"),we=m(),$(X.$$.fragment),Je=m(),Y=a("div"),se=a("img"),ve=m(),L=a("p"),Pe=r("You can also try experimenting with a different scheduler to see how that affects the output:"),Me=m(),$(V.$$.fragment),Ze=m(),C=a("div"),le=a("img"),_e=m(),w=a("p"),ze=r("Check out the Spaces below, and try generating images with different values for "),ie=a("code"),He=r("strength"),Le=r(". You\u2019ll notice that using lower values for "),ae=a("code"),qe=r("strength"),Ae=r(" produces images that are more similar to the original image."),Te=m(),I=a("p"),Oe=r("Feel free to also switch the scheduler to the "),q=a("a"),Ke=r("LMSDiscreteScheduler"),et=r(" and see how that affects the output."),Ge=m(),J=a("iframe"),this.h()},l(e){const s=Tt('[data-svelte="svelte-1phssyn"]',document.head);u=o(s,"META",{name:!0,content:!0}),s.forEach(t),M=f(e),h=o(e,"H1",{class:!0});var x=n(h);g=o(x,"A",{id:!0,class:!0,href:!0});var at=n(g);v=o(at,"SPAN",{});var ot=n(v);j(d.$$.fragment,ot),ot.forEach(t),at.forEach(t),b=f(x),Z=o(x,"SPAN",{});var nt=n(Z);We=p(nt,"Text-guided image-to-image generation"),nt.forEach(t),x.forEach(t),re=f(e),j(B.$$.fragment,e),pe=f(e),_=o(e,"P",{});var $e=n(_);Ue=p($e,"The "),Q=o($e,"A",{href:!0});var rt=n(Q);Be=p(rt,"StableDiffusionImg2ImgPipeline"),rt.forEach(t),Se=p($e," lets you pass a text prompt and an initial image to condition the generation of new images."),$e.forEach(t),me=f(e),P=o(e,"P",{});var pt=n(P);De=p(pt,"Before you begin, make sure you have all the necessary libraries installed:"),pt.forEach(t),fe=f(e),j(S.$$.fragment,e),ce=f(e),y=o(e,"P",{});var A=n(y);Ne=p(A,"Get started by creating a "),z=o(A,"A",{href:!0});var mt=n(z);Fe=p(mt,"StableDiffusionImg2ImgPipeline"),mt.forEach(t),Re=p(A," with a pretrained Stable Diffusion model like "),D=o(A,"A",{href:!0,rel:!0});var ft=n(D);K=o(ft,"CODE",{});var ct=n(K);Xe=p(ct,"nitrosocke/Ghibli-Diffusion"),ct.forEach(t),ft.forEach(t),Ye=p(A,"."),A.forEach(t),ue=f(e),j(N.$$.fragment,e),he=f(e),H=o(e,"P",{});var ut=n(H);Ve=p(ut,"Download and preprocess an initial image so you can pass it to the pipeline:"),ut.forEach(t),de=f(e),j(F.$$.fragment,e),ge=f(e),R=o(e,"DIV",{class:!0});var ht=n(R);ee=o(ht,"IMG",{src:!0}),ht.forEach(t),be=f(e),j(T.$$.fragment,e),ye=f(e),G=o(e,"P",{});var je=n(G);Ce=p(je,"Define the prompt (for this checkpoint finetuned on Ghibli-style art, you need to prefix the prompt with the "),te=o(je,"CODE",{});var dt=n(te);xe=p(dt,"ghibli style"),dt.forEach(t),Qe=p(je," tokens) and run the pipeline:"),je.forEach(t),we=f(e),j(X.$$.fragment,e),Je=f(e),Y=o(e,"DIV",{class:!0});var gt=n(Y);se=o(gt,"IMG",{src:!0}),gt.forEach(t),ve=f(e),L=o(e,"P",{});var bt=n(L);Pe=p(bt,"You can also try experimenting with a different scheduler to see how that affects the output:"),bt.forEach(t),Me=f(e),j(V.$$.fragment,e),Ze=f(e),C=o(e,"DIV",{class:!0});var yt=n(C);le=o(yt,"IMG",{src:!0}),yt.forEach(t),_e=f(e),w=o(e,"P",{});var O=n(w);ze=p(O,"Check out the Spaces below, and try generating images with different values for "),ie=o(O,"CODE",{});var wt=n(ie);He=p(wt,"strength"),wt.forEach(t),Le=p(O,". You\u2019ll notice that using lower values for "),ae=o(O,"CODE",{});var Jt=n(ae);qe=p(Jt,"strength"),Jt.forEach(t),Ae=p(O," produces images that are more similar to the original image."),O.forEach(t),Te=f(e),I=o(e,"P",{});var ke=n(I);Oe=p(ke,"Feel free to also switch the scheduler to the "),q=o(ke,"A",{href:!0});var vt=n(q);Ke=p(vt,"LMSDiscreteScheduler"),vt.forEach(t),et=p(ke," and see how that affects the output."),ke.forEach(t),Ge=f(e),J=o(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),n(J).forEach(t),this.h()},h(){c(u,"name","hf:doc:metadata"),c(u,"content",JSON.stringify(Wt)),c(g,"id","textguided-imagetoimage-generation"),c(g,"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"),c(g,"href","#textguided-imagetoimage-generation"),c(h,"class","relative group"),c(Q,"href","/docs/diffusers/v0.17.0/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),c(z,"href","/docs/diffusers/v0.17.0/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),c(D,"href","https://huggingface.co/nitrosocke/Ghibli-Diffusion"),c(D,"rel","nofollow"),Ee(ee.src,tt="https://huggingface.co/datasets/YiYiXu/test-doc-assets/resolve/main/image_2_image_using_diffusers_cell_8_output_0.jpeg")||c(ee,"src",tt),c(R,"class","flex justify-center"),Ee(se.src,st="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/ghibli-castles.png")||c(se,"src",st),c(Y,"class","flex justify-center"),Ee(le.src,lt="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/lms-ghibli.png")||c(le,"src",lt),c(C,"class","flex justify-center"),c(q,"href","/docs/diffusers/v0.17.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler"),Ee(J.src,it="https://stevhliu-ghibli-img2img.hf.space")||c(J,"src",it),c(J,"frameborder","0"),c(J,"width","850"),c(J,"height","500")},m(e,s){l(document.head,u),i(e,M,s),i(e,h,s),l(h,g),l(g,v),k(d,v,null),l(h,b),l(h,Z),l(Z,We),i(e,re,s),k(B,e,s),i(e,pe,s),i(e,_,s),l(_,Ue),l(_,Q),l(Q,Be),l(_,Se),i(e,me,s),i(e,P,s),l(P,De),i(e,fe,s),k(S,e,s),i(e,ce,s),i(e,y,s),l(y,Ne),l(y,z),l(z,Fe),l(y,Re),l(y,D),l(D,K),l(K,Xe),l(y,Ye),i(e,ue,s),k(N,e,s),i(e,he,s),i(e,H,s),l(H,Ve),i(e,de,s),k(F,e,s),i(e,ge,s),i(e,R,s),l(R,ee),i(e,be,s),k(T,e,s),i(e,ye,s),i(e,G,s),l(G,Ce),l(G,te),l(te,xe),l(G,Qe),i(e,we,s),k(X,e,s),i(e,Je,s),i(e,Y,s),l(Y,se),i(e,ve,s),i(e,L,s),l(L,Pe),i(e,Me,s),k(V,e,s),i(e,Ze,s),i(e,C,s),l(C,le),i(e,_e,s),i(e,w,s),l(w,ze),l(w,ie),l(ie,He),l(w,Le),l(w,ae),l(ae,qe),l(w,Ae),i(e,Te,s),i(e,I,s),l(I,Oe),l(I,q),l(q,Ke),l(I,et),i(e,Ge,s),i(e,J,s),Ie=!0},p(e,[s]){const x={};s&2&&(x.$$scope={dirty:s,ctx:e}),T.$set(x)},i(e){Ie||(E(d.$$.fragment,e),E(B.$$.fragment,e),E(S.$$.fragment,e),E(N.$$.fragment,e),E(F.$$.fragment,e),E(T.$$.fragment,e),E(X.$$.fragment,e),E(V.$$.fragment,e),Ie=!0)},o(e){W(d.$$.fragment,e),W(B.$$.fragment,e),W(S.$$.fragment,e),W(N.$$.fragment,e),W(F.$$.fragment,e),W(T.$$.fragment,e),W(X.$$.fragment,e),W(V.$$.fragment,e),Ie=!1},d(e){t(u),e&&t(M),e&&t(h),U(d),e&&t(re),U(B,e),e&&t(pe),e&&t(_),e&&t(me),e&&t(P),e&&t(fe),U(S,e),e&&t(ce),e&&t(y),e&&t(ue),U(N,e),e&&t(he),e&&t(H),e&&t(de),U(F,e),e&&t(ge),e&&t(R),e&&t(be),U(T,e),e&&t(ye),e&&t(G),e&&t(we),U(X,e),e&&t(Je),e&&t(Y),e&&t(ve),e&&t(L),e&&t(Me),U(V,e),e&&t(Ze),e&&t(C),e&&t(_e),e&&t(w),e&&t(Te),e&&t(I),e&&t(Ge),e&&t(J)}}}const Wt={local:"textguided-imagetoimage-generation",title:"Text-guided image-to-image generation"};function Ut(ne){return Gt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Rt extends Mt{constructor(u){super();Zt(this,u,Ut,Et,_t,{})}}export{Rt as default,Wt as metadata};
