import{S as Mt,i as Tt,s as Zt,e as a,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 Ee,G as l,g as i,y as k,q as E,o as W,B as U,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,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 T=n(h);g=p(T,"strength"),T.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,T,We,re,S,pe,Z,Ue,z,Se,Be,me,Q,Xe,fe,B,ce,y,De,P,Ne,Fe,X,K,Ye,Re,ue,D,he,H,Ve,de,N,ge,F,ee,tt,be,_,ye,I,xe,te,Ce,ze,we,Y,Je,R,se,st,ve,A,Qe,Me,V,Te,x,le,lt,Ze,w,Pe,ie,He,Ae,ae,Le,qe,_e,G,Oe,L,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>`}}),D=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
)`}}),N=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}}}),Y=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(),T=a("span"),We=r("Text-guided image-to-image generation"),re=m(),$(S.$$.fragment),pe=m(),Z=a("p"),Ue=r("The "),z=a("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=a("p"),Xe=r("Before you begin, make sure you have all the necessary libraries installed:"),fe=m(),$(B.$$.fragment),ce=m(),y=a("p"),De=r("Get started by creating a "),P=a("a"),Ne=r("StableDiffusionImg2ImgPipeline"),Fe=r(" with a pretrained Stable Diffusion model like "),X=a("a"),K=a("code"),Ye=r("nitrosocke/Ghibli-Diffusion"),Re=r("."),ue=m(),$(D.$$.fragment),he=m(),H=a("p"),Ve=r("Download and preprocess an initial image so you can pass it to the pipeline:"),de=m(),$(N.$$.fragment),ge=m(),F=a("div"),ee=a("img"),be=m(),$(_.$$.fragment),ye=m(),I=a("p"),xe=r("Define the prompt (for this checkpoint finetuned on Ghibli-style art, you need to prefix the prompt with the "),te=a("code"),Ce=r("ghibli style"),ze=r(" tokens) and run the pipeline:"),we=m(),$(Y.$$.fragment),Je=m(),R=a("div"),se=a("img"),ve=m(),A=a("p"),Qe=r("You can also try experimenting with a different scheduler to see how that affects the output:"),Me=m(),$(V.$$.fragment),Te=m(),x=a("div"),le=a("img"),Ze=m(),w=a("p"),Pe=r("Check out the Spaces below, and try generating images with different values for "),ie=a("code"),He=r("strength"),Ae=r(". You\u2019ll notice that using lower values for "),ae=a("code"),Le=r("strength"),qe=r(" produces images that are more similar to the original image."),_e=m(),G=a("p"),Oe=r("Feel free to also switch the scheduler to the "),L=a("a"),Ke=r("LMSDiscreteScheduler"),et=r(" and see how that affects the output."),Ie=m(),J=a("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),M=f(e),h=o(e,"H1",{class:!0});var C=n(h);g=o(C,"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(C),T=o(C,"SPAN",{});var nt=n(T);We=p(nt,"Text-guided image-to-image generation"),nt.forEach(t),C.forEach(t),re=f(e),j(S.$$.fragment,e),pe=f(e),Z=o(e,"P",{});var $e=n(Z);Ue=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);Xe=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 q=n(y);De=p(q,"Get started by creating a "),P=o(q,"A",{href:!0});var mt=n(P);Ne=p(mt,"StableDiffusionImg2ImgPipeline"),mt.forEach(t),Fe=p(q," with a pretrained Stable Diffusion model like "),X=o(q,"A",{href:!0,rel:!0});var ft=n(X);K=o(ft,"CODE",{});var ct=n(K);Ye=p(ct,"nitrosocke/Ghibli-Diffusion"),ct.forEach(t),ft.forEach(t),Re=p(q,"."),q.forEach(t),ue=f(e),j(D.$$.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(N.$$.fragment,e),ge=f(e),F=o(e,"DIV",{class:!0});var ht=n(F);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);xe=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);Ce=p(dt,"ghibli style"),dt.forEach(t),ze=p(je," tokens) and run the pipeline:"),je.forEach(t),we=f(e),j(Y.$$.fragment,e),Je=f(e),R=o(e,"DIV",{class:!0});var gt=n(R);se=o(gt,"IMG",{src:!0}),gt.forEach(t),ve=f(e),A=o(e,"P",{});var bt=n(A);Qe=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),Te=f(e),x=o(e,"DIV",{class:!0});var yt=n(x);le=o(yt,"IMG",{src:!0}),yt.forEach(t),Ze=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),Ae=p(O,". You\u2019ll notice that using lower values for "),ae=o(O,"CODE",{});var Jt=n(ae);Le=p(Jt,"strength"),Jt.forEach(t),qe=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 "),L=o(ke,"A",{href:!0});var vt=n(L);Ke=p(vt,"LMSDiscreteScheduler"),vt.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.19.0/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),c(P,"href","/docs/diffusers/v0.19.0/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),c(X,"href","https://huggingface.co/nitrosocke/Ghibli-Diffusion"),c(X,"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(F,"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(R,"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(x,"class","flex justify-center"),c(L,"href","/docs/diffusers/v0.19.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,T),l(T,We),i(e,re,s),k(S,e,s),i(e,pe,s),i(e,Z,s),l(Z,Ue),l(Z,z),l(z,Se),l(Z,Be),i(e,me,s),i(e,Q,s),l(Q,Xe),i(e,fe,s),k(B,e,s),i(e,ce,s),i(e,y,s),l(y,De),l(y,P),l(P,Ne),l(y,Fe),l(y,X),l(X,K),l(K,Ye),l(y,Re),i(e,ue,s),k(D,e,s),i(e,he,s),i(e,H,s),l(H,Ve),i(e,de,s),k(N,e,s),i(e,ge,s),i(e,F,s),l(F,ee),i(e,be,s),k(_,e,s),i(e,ye,s),i(e,I,s),l(I,xe),l(I,te),l(te,Ce),l(I,ze),i(e,we,s),k(Y,e,s),i(e,Je,s),i(e,R,s),l(R,se),i(e,ve,s),i(e,A,s),l(A,Qe),i(e,Me,s),k(V,e,s),i(e,Te,s),i(e,x,s),l(x,le),i(e,Ze,s),i(e,w,s),l(w,Pe),l(w,ie),l(ie,He),l(w,Ae),l(w,ae),l(ae,Le),l(w,qe),i(e,_e,s),i(e,G,s),l(G,Oe),l(G,L),l(L,Ke),l(G,et),i(e,Ie,s),i(e,J,s),Ge=!0},p(e,[s]){const C={};s&2&&(C.$$scope={dirty:s,ctx:e}),_.$set(C)},i(e){Ge||(E(d.$$.fragment,e),E(S.$$.fragment,e),E(B.$$.fragment,e),E(D.$$.fragment,e),E(N.$$.fragment,e),E(_.$$.fragment,e),E(Y.$$.fragment,e),E(V.$$.fragment,e),Ge=!0)},o(e){W(d.$$.fragment,e),W(S.$$.fragment,e),W(B.$$.fragment,e),W(D.$$.fragment,e),W(N.$$.fragment,e),W(_.$$.fragment,e),W(Y.$$.fragment,e),W(V.$$.fragment,e),Ge=!1},d(e){t(u),e&&t(M),e&&t(h),U(d),e&&t(re),U(S,e),e&&t(pe),e&&t(Z),e&&t(me),e&&t(Q),e&&t(fe),U(B,e),e&&t(ce),e&&t(y),e&&t(ue),U(D,e),e&&t(he),e&&t(H),e&&t(de),U(N,e),e&&t(ge),e&&t(F),e&&t(be),U(_,e),e&&t(ye),e&&t(I),e&&t(we),U(Y,e),e&&t(Je),e&&t(R),e&&t(ve),e&&t(A),e&&t(Me),U(V,e),e&&t(Te),e&&t(x),e&&t(Ze),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 Ut(ne){return It(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ft extends Mt{constructor(u){super();Tt(this,u,Ut,Et,Zt,{})}}export{Ft as default,Wt as metadata};
