import{S as vt,i as Zt,s as Mt,e as i,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 l,g as a,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,v,h,g,T;return{c(){u=i("p"),v=r("\u{1F4A1} "),h=i("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);v=p(b,"\u{1F4A1} "),h=o(b,"CODE",{});var Z=n(h);g=p(Z,"strength"),Z.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){a(d,u,b),l(u,v),l(u,h),l(h,g),l(u,T)},d(d){d&&t(u)}}}function Ut(ne){let u,v,h,g,T,d,b,Z,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,ve,Y,Ze,C,le,lt,Me,w,Pe,ae,He,Le,ie,qe,Ae,_e,G,Oe,q,Ke,et,Ie,J,at,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=i("meta"),v=m(),h=i("h1"),g=i("a"),T=i("span"),$(d.$$.fragment),b=m(),Z=i("span"),We=r("Text-guided image-to-image generation"),re=m(),$(S.$$.fragment),pe=m(),M=i("p"),Ee=r("The "),z=i("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=i("p"),Ne=r("Before you begin, make sure you have all the necessary libraries installed:"),fe=m(),$(B.$$.fragment),ce=m(),y=i("p"),Xe=r("Get started by creating a "),P=i("a"),De=r("StableDiffusionImg2ImgPipeline"),Ve=r(" with a pretrained Stable Diffusion model like "),N=i("a"),K=i("code"),Fe=r("nitrosocke/Ghibli-Diffusion"),Re=r("."),ue=m(),$(X.$$.fragment),he=m(),H=i("p"),Ye=r("Download and preprocess an initial image so you can pass it to the pipeline:"),de=m(),$(D.$$.fragment),ge=m(),V=i("div"),ee=i("img"),be=m(),$(_.$$.fragment),ye=m(),I=i("p"),Ce=r("Define the prompt (for this checkpoint finetuned on Ghibli-style art, you need to prefix the prompt with the "),te=i("code"),xe=r("ghibli style"),ze=r(" tokens) and run the pipeline:"),we=m(),$(F.$$.fragment),Je=m(),R=i("div"),se=i("img"),Te=m(),L=i("p"),Qe=r("You can also try experimenting with a different scheduler to see how that affects the output:"),ve=m(),$(Y.$$.fragment),Ze=m(),C=i("div"),le=i("img"),Me=m(),w=i("p"),Pe=r("Check out the Spaces below, and try generating images with different values for "),ae=i("code"),He=r("strength"),Le=r(". You\u2019ll notice that using lower values for "),ie=i("code"),qe=r("strength"),Ae=r(" produces images that are more similar to the original image."),_e=m(),G=i("p"),Oe=r("Feel free to also switch the scheduler to the "),q=i("a"),Ke=r("LMSDiscreteScheduler"),et=r(" and see how that affects the output."),Ie=m(),J=i("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),v=f(e),h=o(e,"H1",{class:!0});var x=n(h);g=o(x,"A",{id:!0,class:!0,href:!0});var it=n(g);T=o(it,"SPAN",{});var ot=n(T);j(d.$$.fragment,ot),ot.forEach(t),it.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(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),ve=f(e),j(Y.$$.fragment,e),Ze=f(e),C=o(e,"DIV",{class:!0});var yt=n(C);le=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 "),ae=o(O,"CODE",{});var wt=n(ae);He=p(wt,"strength"),wt.forEach(t),Le=p(O,". You\u2019ll notice that using lower values for "),ie=o(O,"CODE",{});var Jt=n(ie);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/v0.21.0/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),c(P,"href","/docs/diffusers/v0.21.0/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(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.21.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler"),Ue(J.src,at="https://stevhliu-ghibli-img2img.hf.space")||c(J,"src",at),c(J,"frameborder","0"),c(J,"width","850"),c(J,"height","500")},m(e,s){l(document.head,u),a(e,v,s),a(e,h,s),l(h,g),l(g,T),k(d,T,null),l(h,b),l(h,Z),l(Z,We),a(e,re,s),k(S,e,s),a(e,pe,s),a(e,M,s),l(M,Ee),l(M,z),l(z,Se),l(M,Be),a(e,me,s),a(e,Q,s),l(Q,Ne),a(e,fe,s),k(B,e,s),a(e,ce,s),a(e,y,s),l(y,Xe),l(y,P),l(P,De),l(y,Ve),l(y,N),l(N,K),l(K,Fe),l(y,Re),a(e,ue,s),k(X,e,s),a(e,he,s),a(e,H,s),l(H,Ye),a(e,de,s),k(D,e,s),a(e,ge,s),a(e,V,s),l(V,ee),a(e,be,s),k(_,e,s),a(e,ye,s),a(e,I,s),l(I,Ce),l(I,te),l(te,xe),l(I,ze),a(e,we,s),k(F,e,s),a(e,Je,s),a(e,R,s),l(R,se),a(e,Te,s),a(e,L,s),l(L,Qe),a(e,ve,s),k(Y,e,s),a(e,Ze,s),a(e,C,s),l(C,le),a(e,Me,s),a(e,w,s),l(w,Pe),l(w,ae),l(ae,He),l(w,Le),l(w,ie),l(ie,qe),l(w,Ae),a(e,_e,s),a(e,G,s),l(G,Oe),l(G,q),l(q,Ke),l(G,et),a(e,Ie,s),a(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(v),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(ve),E(Y,e),e&&t(Ze),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 vt{constructor(u){super();Zt(this,u,Et,Ut,Mt,{})}}export{Vt as default,Wt as metadata};
