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