import{S as Hi,i as Ai,s as qi,e as a,k as c,w as h,t as o,M as Li,c as n,d as s,m as d,a as l,x as f,h as i,b as m,G as t,g as p,y as g,q as b,o as y,B as w,v as Ki,L as Qi}from"../../../chunks/vendor-hf-doc-builder.js";import{D as Et}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as I}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as he}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Di}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Oi(rt){let J,G,T,M,U;return M=new I({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQSUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBERElNU2NoZWR1bGVyJTJDJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZSUwQSUwQSUwQWRlZiUyMGRvd25sb2FkKGVtYmVkZGluZ191cmwlMkMlMjBsb2NhbF9maWxlcGF0aCklM0ElMEElMjAlMjAlMjAlMjByJTIwJTNEJTIwcmVxdWVzdHMuZ2V0KGVtYmVkZGluZ191cmwpJTBBJTIwJTIwJTIwJTIwd2l0aCUyMG9wZW4obG9jYWxfZmlsZXBhdGglMkMlMjAlMjJ3YiUyMiklMjBhcyUyMGYlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBmLndyaXRlKHIuY29udGVudCklMEElMEElMEFtb2RlbF9ja3B0JTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfY2twdCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlbGluZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLm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AlMjAlMjB0YXJnZXRfZW1iZWRzJTNEdGFyZ2V0X2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGNyb3NzX2F0dGVudGlvbl9ndWlkYW5jZV9hbW91bnQlM0QwLjE1JTJDJTBBKS5pbWFnZXMlMEElMEFpbWFnZXMlNUIwJTVELnNhdmUoJTIyZWRpdGVkX2ltYWdlX2RvZy5wbmclMjIp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPix2PixZeroPipeline


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">download</span>(<span class="hljs-params">embedding_url, local_filepath</span>):
<span class="hljs-meta">... </span>    r = requests.get(embedding_url)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(local_filepath, <span class="hljs-string">&quot;wb&quot;</span>) <span class="hljs-keyword">as</span> f:
<span class="hljs-meta">... </span>        f.write(r.content)


<span class="hljs-meta">&gt;&gt;&gt; </span>model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(model_ckpt, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;a high resolution painting of a cat in the style of van gough&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>source_emb_url = <span class="hljs-string">&quot;https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/cat.pt&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>target_emb_url = <span class="hljs-string">&quot;https://hf.co/datasets/sayakpaul/sample-datasets/resolve/main/dog.pt&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">for</span> url <span class="hljs-keyword">in</span> [source_emb_url, target_emb_url]:
<span class="hljs-meta">... </span>    download(url, url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

<span class="hljs-meta">&gt;&gt;&gt; </span>src_embeds = torch.load(source_emb_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>target_embeds = torch.load(target_emb_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
<span class="hljs-meta">&gt;&gt;&gt; </span>images = pipeline(
<span class="hljs-meta">... </span>    prompt,
<span class="hljs-meta">... </span>    source_embeds=src_embeds,
<span class="hljs-meta">... </span>    target_embeds=target_embeds,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
<span class="hljs-meta">... </span>).images

<span class="hljs-meta">&gt;&gt;&gt; </span>images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),{c(){J=a("p"),G=o("Examples:"),T=c(),h(M.$$.fragment)},l(u){J=n(u,"P",{});var Z=l(J);G=i(Z,"Examples:"),Z.forEach(s),T=d(u),f(M.$$.fragment,u)},m(u,Z){p(u,J,Z),t(J,G),p(u,T,Z),g(M,u,Z),U=!0},p:Qi,i(u){U||(b(M.$$.fragment,u),U=!0)},o(u){y(M.$$.fragment,u),U=!1},d(u){u&&s(J),u&&s(T),w(M,u)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zJTIwc2V0JTIwJTYwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCU2MCUyMHRvJTIwMC4wMSUyMG9yJTIwbGVzcyUyMHRvJTIwYXZvaWQlMjBpbnB1dCUyMGxhdGVudCUyMGdyYWRpZW50JTIwZXhwbG9zaW9uJTBBJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjBjYXB0aW9uJTJDJTBBJTIwJTIwJTIwJTIwc291cmNlX2VtYmVkcyUzRHNvdXJjZV9lbWJlZHMlMkMlMEElMjAlMjAlMjAlMjB0YXJnZXRfZW1iZWRzJTNEdGFyZ2V0X2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUwQSUyMCUyMCUyMCUyMGNyb3NzX2F0dGVudGlvbl9ndWlkYW5jZV9hbW91bnQlM0QwLjE1JTJDJTBBJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBJTIwJTIwJTIwJTIwbGF0ZW50cyUzRGludl9sYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfcHJvbXB0JTNEY2FwdGlvbiUyQyUwQSkuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyZWRpdGVkX2ltYWdlLnBuZyUyMik=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BlipForConditionalGeneration, BlipProcessor
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-meta">&gt;&gt;&gt; </span>captioner_id = <span class="hljs-string">&quot;Salesforce/blip-image-captioning-base&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>processor = BlipProcessor.from_pretrained(captioner_id)
<span class="hljs-meta">&gt;&gt;&gt; </span>model = BlipForConditionalGeneration.from_pretrained(
<span class="hljs-meta">... </span>    captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=<span class="hljs-literal">True</span>
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>sd_model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
<span class="hljs-meta">... </span>    sd_model_ckpt,
<span class="hljs-meta">... </span>    caption_generator=model,
<span class="hljs-meta">... </span>    caption_processor=processor,
<span class="hljs-meta">... </span>    torch_dtype=torch.float16,
<span class="hljs-meta">... </span>    safety_checker=<span class="hljs-literal">None</span>,
<span class="hljs-meta">... </span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.enable_model_cpu_offload()

<span class="hljs-meta">&gt;&gt;&gt; </span>img_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>raw_image = Image.<span class="hljs-built_in">open</span>(requests.get(img_url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># generate caption</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>caption = pipeline.generate_caption(raw_image)

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># &quot;a photography of a cat with flowers and dai dai daie - daie - daie kasaii&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>inv_latents = pipeline.invert(caption, image=raw_image).latents
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># we need to generate source and target embeds</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>source_prompts = [<span class="hljs-string">&quot;a cat sitting on the street&quot;</span>, <span class="hljs-string">&quot;a cat playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a cat&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>target_prompts = [<span class="hljs-string">&quot;a dog sitting on the street&quot;</span>, <span class="hljs-string">&quot;a dog playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a dog&quot;</span>]

<span class="hljs-meta">&gt;&gt;&gt; </span>source_embeds = pipeline.get_embeds(source_prompts)
<span class="hljs-meta">&gt;&gt;&gt; </span>target_embeds = pipeline.get_embeds(target_prompts)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># the latents can then be used to edit a real image</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># when using Stable Diffusion 2 or other models that use v-prediction</span>
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># set \`cross_attention_guidance_amount\` to 0.01 or less to avoid input latent gradient explosion</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipeline(
<span class="hljs-meta">... </span>    caption,
<span class="hljs-meta">... </span>    source_embeds=source_embeds,
<span class="hljs-meta">... </span>    target_embeds=target_embeds,
<span class="hljs-meta">... </span>    num_inference_steps=<span class="hljs-number">50</span>,
<span class="hljs-meta">... </span>    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
<span class="hljs-meta">... </span>    generator=generator,
<span class="hljs-meta">... </span>    latents=inv_latents,
<span class="hljs-meta">... </span>    negative_prompt=caption,
<span class="hljs-meta">... </span>).images[<span class="hljs-number">0</span>]
<span class="hljs-meta">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),{c(){J=a("p"),G=o("Examples:"),T=c(),h(M.$$.fragment)},l(u){J=n(u,"P",{});var Z=l(J);G=i(Z,"Examples:"),Z.forEach(s),T=d(u),f(M.$$.fragment,u)},m(u,Z){p(u,J,Z),t(J,G),p(u,T,Z),g(M,u,Z),U=!0},p:Qi,i(u){U||(b(M.$$.fragment,u),U=!0)},o(u){y(M.$$.fragment,u),U=!1},d(u){u&&s(J),u&&s(T),w(M,u)}}}function tr(rt){let J,G,T,M,U,u,Z,Wt,Xa,Is,fe,ge,Pa,Ra,xs,pt,Va,Gs,ct,kt,Na,Bs,B,Ca,be,Sa,Ya,ye,Fa,$a,we,za,Da,Es,N,q,Xt,Me,Qa,Pt,Ha,Ws,j,Rt,Aa,qa,x,La,Vt,Ka,Oa,Nt,en,tn,Ct,sn,an,St,nn,ln,on,C,rn,Yt,pn,cn,Ft,dn,mn,un,dt,hn,Je,S,fn,$t,gn,bn,zt,yn,wn,Mn,Dt,Jn,_n,_e,Tn,Te,Zn,jn,vn,k,Un,Qt,In,xn,Ht,Gn,Bn,mt,En,Wn,ks,Y,L,At,Ze,kn,qt,Xn,Xs,K,Lt,F,Kt,Pn,Rn,Ot,Vn,Nn,ut,Cn,Sn,es,$,ts,je,Yn,Fn,ss,as,$n,zn,ht,ve,Dn,Ps,z,O,ns,Ue,Qn,ls,Hn,Rs,D,ee,os,Ie,An,is,qn,Vs,xe,Ns,Q,te,rs,Ge,Ln,ps,Kn,Cs,se,On,cs,el,tl,Ss,ft,sl,Ys,Be,Fs,gt,al,$s,Ee,zs,bt,nl,Ds,We,Qs,yt,ll,Hs,ke,As,H,ae,ds,Xe,ol,ms,il,qs,E,rl,Pe,pl,cl,Re,dl,ml,Ve,ul,hl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pdCglMjIlMkYlMjIpJTVCLTElNUQpJTBBdGFyZ2V0X2VtYmVkcyUyMCUzRCUyMHRvcmNoLmxvYWQodGFyZ2V0X2VtYnNfdXJsLnNwbGl0KCUyMiUyRiUyMiklNUItMSU1RCklMEElMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBzb3VyY2VfZW1iZWRzJTNEc3JjX2VtYmVkcyUyQyUwQSUyMCUyMCUyMCUyMHRhcmdldF9lbWJlZHMlM0R0YXJnZXRfZW1iZWRzJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCUzRDAuMTUlMkMlMEEpLmltYWdlcyUwQWltYWdlcyU1QjAlNUQuc2F2ZSglMjJlZGl0ZWRfaW1hZ2VfZG9nLnBuZyUyMik=",highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> torch

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, StableDiffusionPix2PixZeroPipeline


<span class="hljs-keyword">def</span> <span class="hljs-title function_">download</span>(<span class="hljs-params">embedding_url, local_filepath</span>):
    r = requests.get(embedding_url)
    <span class="hljs-keyword">with</span> <span class="hljs-built_in">open</span>(local_filepath, <span class="hljs-string">&quot;wb&quot;</span>) <span class="hljs-keyword">as</span> f:
        f.write(r.content)


model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    model_ckpt, conditions_input_image=<span class="hljs-literal">False</span>, torch_dtype=torch.float16
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;a high resolution painting of a cat in the style of van gogh&quot;</span>
src_embs_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/cat.pt&quot;</span>
target_embs_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/dog.pt&quot;</span>

<span class="hljs-keyword">for</span> url <span class="hljs-keyword">in</span> [src_embs_url, target_embs_url]:
    download(url, url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

src_embeds = torch.load(src_embs_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])
target_embeds = torch.load(target_embs_url.split(<span class="hljs-string">&quot;/&quot;</span>)[-<span class="hljs-number">1</span>])

images = pipeline(
    prompt,
    source_embeds=src_embeds,
    target_embeds=target_embeds,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),Ge=new he({}),Be=new I({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQmxpcEZvckNvbmRpdGlvbmFsR2VuZXJhdGlvbiUyQyUyMEJsaXBQcm9jZXNzb3IlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRERJTVNjaGVkdWxlciUyQyUyMERESU1JbnZlcnNlU2NoZWR1bGVyJTJDJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZSUwQSUwQWNhcHRpb25lcl9pZCUyMCUzRCUyMCUyMlNhbGVzZm9yY2UlMkZibGlwLWltYWdlLWNhcHRpb25pbmctYmFzZSUyMiUwQXByb2Nlc3NvciUyMCUzRCUyMEJsaXBQcm9jZXNzb3IuZnJvbV9wcmV0cmFpbmVkKGNhcHRpb25lcl9pZCklMEFtb2RlbCUyMCUzRCUyMEJsaXBGb3JDb25kaXRpb25hbEdlbmVyYXRpb24uZnJvbV9wcmV0cmFpbmVkKGNhcHRpb25lcl9pZCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMGxvd19jcHVfbWVtX3VzYWdlJTNEVHJ1ZSklMEElMEFzZF9tb2RlbF9ja3B0JTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGl4MlBpeFplcm9QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwc2RfbW9kZWxfY2twdCUyQyUwQSUyMCUyMCUyMCUyMGNhcHRpb25fZ2VuZXJhdG9yJTNEbW9kZWwlMkMlMEElMjAlMjAlMjAlMjBjYXB0aW9uX3Byb2Nlc3NvciUzRHByb2Nlc3NvciUyQyUwQSUyMCUyMCUyMCUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUwQSUyMCUyMCUyMCUyMHNhZmV0eV9jaGVja2VyJTNETm9uZSUyQyUwQSklMEFwaXBlbGluZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGVsaW5lLnNjaGVkdWxlci5jb25maWcpJTBBcGlwZWxpbmUuaW52ZXJzZV9zY2hlZHVsZXIlMjAlM0QlMjBERElNSW52ZXJzZVNjaGVkdWxlci5mcm9tX2NvbmZpZyhwaXBlbGluZS5zY2hlZHVsZXIuY29uZmlnKSUwQXBpcGVsaW5lLmVuYWJsZV9tb2RlbF9jcHVfb2ZmbG9hZCgp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BlipForConditionalGeneration, BlipProcessor
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler, DDIMInverseScheduler, StableDiffusionPix2PixZeroPipeline

captioner_id = <span class="hljs-string">&quot;Salesforce/blip-image-captioning-base&quot;</span>
processor = BlipProcessor.from_pretrained(captioner_id)
model = BlipForConditionalGeneration.from_pretrained(captioner_id, torch_dtype=torch.float16, low_cpu_mem_usage=<span class="hljs-literal">True</span>)

sd_model_ckpt = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    sd_model_ckpt,
    caption_generator=model,
    caption_processor=processor,
    torch_dtype=torch.float16,
    safety_checker=<span class="hljs-literal">None</span>,
)
pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)
pipeline.inverse_scheduler = DDIMInverseScheduler.from_config(pipeline.scheduler.config)
pipeline.enable_model_cpu_offload()`}}),Ee=new I({props:{code:"aW1wb3J0JTIwcmVxdWVzdHMlMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEElMEFpbWdfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZnaXRodWIuY29tJTJGcGl4MnBpeHplcm8lMkZwaXgycGl4LXplcm8lMkZyYXclMkZtYWluJTJGYXNzZXRzJTJGdGVzdF9pbWFnZXMlMkZjYXRzJTJGY2F0XzYucG5nJTIyJTBBcmF3X2ltYWdlJTIwJTNEJTIwSW1hZ2Uub3BlbihyZXF1ZXN0cy5nZXQoaW1nX3VybCUyQyUyMHN0cmVhbSUzRFRydWUpLnJhdykuY29udmVydCglMjJSR0IlMjIpLnJlc2l6ZSgoNTEyJTJDJTIwNTEyKSklMEFjYXB0aW9uJTIwJTNEJTIwcGlwZWxpbmUuZ2VuZXJhdGVfY2FwdGlvbihyYXdfaW1hZ2Up",highlighted:`<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

img_url = <span class="hljs-string">&quot;https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/test_images/cats/cat_6.png&quot;</span>
raw_image = Image.<span class="hljs-built_in">open</span>(requests.get(img_url, stream=<span class="hljs-literal">True</span>).raw).convert(<span class="hljs-string">&quot;RGB&quot;</span>).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
caption = pipeline.generate_caption(raw_image)`}}),We=new I({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwdG9yY2gubWFudWFsX3NlZWQoMCklMEFpbnZfbGF0ZW50cyUyMCUzRCUyMHBpcGVsaW5lLmludmVydChjYXB0aW9uJTJDJTIwaW1hZ2UlM0RyYXdfaW1hZ2UlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmxhdGVudHM=",highlighted:`generator = torch.manual_seed(<span class="hljs-number">0</span>)
inv_latents = pipeline.invert(caption, image=raw_image, generator=generator).latents`}}),ke=new I({props:{code:"JTIzJTIwU2VlJTIwdGhlJTIwJTIyR2VuZXJhdGluZyUyMHNvdXJjZSUyMGFuZCUyMHRhcmdldCUyMGVtYmVkZGluZ3MlMjIlMjBzZWN0aW9uJTIwYmVsb3clMjB0byUwQSUyMyUyMGF1dG9tYXRlJTIwdGhlJTIwZ2VuZXJhdGlvbiUyMG9mJTIwdGhlc2UlMjBjYXB0aW9ucyUyMHdpdGglMjBhJTIwcHJlLXRyYWluZWQlMjBtb2RlbCUyMGxpa2UlMjBGbGFuLVQ1JTIwYXMlMjBleHBsYWluZWQlMjBiZWxvdy4lMEFzb3VyY2VfcHJvbXB0cyUyMCUzRCUyMCU1QiUyMmElMjBjYXQlMjBzaXR0aW5nJTIwb24lMjB0aGUlMjBzdHJlZXQlMjIlMkMlMjAlMjJhJTIwY2F0JTIwcGxheWluZyUyMGluJTIwdGhlJTIwZmllbGQlMjIlMkMlMjAlMjJhJTIwZmFjZSUyMG9mJTIwYSUyMGNhdCUyMiU1RCUwQXRhcmdldF9wcm9tcHRzJTIwJTNEJTIwJTVCJTIyYSUyMGRvZyUyMHNpdHRpbmclMjBvbiUyMHRoZSUyMHN0cmVldCUyMiUyQyUyMCUyMmElMjBkb2clMjBwbGF5aW5nJTIwaW4lMjB0aGUlMjBmaWVsZCUyMiUyQyUyMCUyMmElMjBmYWNlJTIwb2YlMjBhJTIwZG9nJTIyJTVEJTBBJTBBc291cmNlX2VtYmVkcyUyMCUzRCUyMHBpcGVsaW5lLmdldF9lbWJlZHMoc291cmNlX3Byb21wdHMlMkMlMjBiYXRjaF9zaXplJTNEMiklMEF0YXJnZXRfZW1iZWRzJTIwJTNEJTIwcGlwZWxpbmUuZ2V0X2VtYmVkcyh0YXJnZXRfcHJvbXB0cyUyQyUyMGJhdGNoX3NpemUlM0QyKSUwQSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwY2FwdGlvbiUyQyUwQSUyMCUyMCUyMCUyMHNvdXJjZV9lbWJlZHMlM0Rzb3VyY2VfZW1iZWRzJTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X2VtYmVkcyUzRHRhcmdldF9lbWJlZHMlMkMlMEElMjAlMjAlMjAlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTAlMkMlMEElMjAlMjAlMjAlMjBjcm9zc19hdHRlbnRpb25fZ3VpZGFuY2VfYW1vdW50JTNEMC4xNSUyQyUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUzRGdlbmVyYXRvciUyQyUwQSUyMCUyMCUyMCUyMGxhdGVudHMlM0RpbnZfbGF0ZW50cyUyQyUwQSUyMCUyMCUyMCUyMG5lZ2F0aXZlX3Byb21wdCUzRGNhcHRpb24lMkMlMEEpLmltYWdlcyU1QjAlNUQlMEFpbWFnZS5zYXZlKCUyMmVkaXRlZF9pbWFnZS5wbmclMjIp",highlighted:`<span class="hljs-comment"># See the &quot;Generating source and target embeddings&quot; section below to</span>
<span class="hljs-comment"># automate the generation of these captions with a pre-trained model like Flan-T5 as explained below.</span>
source_prompts = [<span class="hljs-string">&quot;a cat sitting on the street&quot;</span>, <span class="hljs-string">&quot;a cat playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a cat&quot;</span>]
target_prompts = [<span class="hljs-string">&quot;a dog sitting on the street&quot;</span>, <span class="hljs-string">&quot;a dog playing in the field&quot;</span>, <span class="hljs-string">&quot;a face of a dog&quot;</span>]

source_embeds = pipeline.get_embeds(source_prompts, batch_size=<span class="hljs-number">2</span>)
target_embeds = pipeline.get_embeds(target_prompts, batch_size=<span class="hljs-number">2</span>)


image = pipeline(
    caption,
    source_embeds=source_embeds,
    target_embeds=target_embeds,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
    generator=generator,
    latents=inv_latents,
    negative_prompt=caption,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),Xe=new he({}),Ce=new I({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQXV0b1Rva2VuaXplciUyQyUyMFQ1Rm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uJTBBJTBBdG9rZW5pemVyJTIwJTNEJTIwQXV0b1Rva2VuaXplci5mcm9tX3ByZXRyYWluZWQoJTIyZ29vZ2xlJTJGZmxhbi10NS14bCUyMiklMEFtb2RlbCUyMCUzRCUyMFQ1Rm9yQ29uZGl0aW9uYWxHZW5lcmF0aW9uLmZyb21fcHJldHJhaW5lZCglMjJnb29nbGUlMkZmbGFuLXQ1LXhsJTIyJTJDJTIwZGV2aWNlX21hcCUzRCUyMmF1dG8lMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> AutoTokenizer, T5ForConditionalGeneration

tokenizer = AutoTokenizer.from_pretrained(<span class="hljs-string">&quot;google/flan-t5-xl&quot;</span>)
model = T5ForConditionalGeneration.from_pretrained(<span class="hljs-string">&quot;google/flan-t5-xl&quot;</span>, device_map=<span class="hljs-string">&quot;auto&quot;</span>, torch_dtype=torch.float16)`}}),Ye=new I({props:{code:"c291cmNlX2NvbmNlcHQlMjAlM0QlMjAlMjJjYXQlMjIlMEF0YXJnZXRfY29uY2VwdCUyMCUzRCUyMCUyMmRvZyUyMiUwQSUwQXNvdXJjZV90ZXh0JTIwJTNEJTIwZiUyMlByb3ZpZGUlMjBhJTIwY2FwdGlvbiUyMGZvciUyMGltYWdlcyUyMGNvbnRhaW5pbmclMjBhJTIwJTdCc291cmNlX2NvbmNlcHQlN0QuJTIwJTIyJTBBJTIyVGhlJTIwY2FwdGlvbnMlMjBzaG91bGQlMjBiZSUyMGluJTIwRW5nbGlzaCUyMGFuZCUyMHNob3VsZCUyMGJlJTIwbm8lMjBsb25nZXIlMjB0aGFuJTIwMTUwJTIwY2hhcmFjdGVycy4lMjIlMEElMEF0YXJnZXRfdGV4dCUyMCUzRCUyMGYlMjJQcm92aWRlJTIwYSUyMGNhcHRpb24lMjBmb3IlMjBpbWFnZXMlMjBjb250YWluaW5nJTIwYSUyMCU3QnRhcmdldF9jb25jZXB0JTdELiUyMCUyMiUwQSUyMlRoZSUyMGNhcHRpb25zJTIwc2hvdWxkJTIwYmUlMjBpbiUyMEVuZ2xpc2glMjBhbmQlMjBzaG91bGQlMjBiZSUyMG5vJTIwbG9uZ2VyJTIwdGhhbiUyMDE1MCUyMGNoYXJhY3RlcnMuJTIy",highlighted:`source_concept = <span class="hljs-string">&quot;cat&quot;</span>
target_concept = <span class="hljs-string">&quot;dog&quot;</span>

source_text = <span class="hljs-string">f&quot;Provide a caption for images containing a <span class="hljs-subst">{source_concept}</span>. &quot;</span>
<span class="hljs-string">&quot;The captions should be in English and should be no longer than 150 characters.&quot;</span>

target_text = <span class="hljs-string">f&quot;Provide a caption for images containing a <span class="hljs-subst">{target_concept}</span>. &quot;</span>
<span class="hljs-string">&quot;The captions should be in English and should be no longer than 150 characters.&quot;</span>`}}),$e=new I({props:{code:"ZGVmJTIwZ2VuZXJhdGVfY2FwdGlvbnMoaW5wdXRfcHJvbXB0KSUzQSUwQSUyMCUyMCUyMCUyMGlucHV0X2lkcyUyMCUzRCUyMHRva2VuaXplcihpbnB1dF9wcm9tcHQlMkMlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyKS5pbnB1dF9pZHMudG8oJTIyY3VkYSUyMiklMEElMEElMjAlMjAlMjAlMjBvdXRwdXRzJTIwJTNEJTIwbW9kZWwuZ2VuZXJhdGUoJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwaW5wdXRfaWRzJTJDJTIwdGVtcGVyYXR1cmUlM0QwLjglMkMlMjBudW1fcmV0dXJuX3NlcXVlbmNlcyUzRDE2JTJDJTIwZG9fc2FtcGxlJTNEVHJ1ZSUyQyUyMG1heF9uZXdfdG9rZW5zJTNEMTI4JTJDJTIwdG9wX2slM0QxMCUwQSUyMCUyMCUyMCUyMCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjB0b2tlbml6ZXIuYmF0Y2hfZGVjb2RlKG91dHB1dHMlMkMlMjBza2lwX3NwZWNpYWxfdG9rZW5zJTNEVHJ1ZSk=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_captions</span>(<span class="hljs-params">input_prompt</span>):
    input_ids = tokenizer(input_prompt, return_tensors=<span class="hljs-string">&quot;pt&quot;</span>).input_ids.to(<span class="hljs-string">&quot;cuda&quot;</span>)

    outputs = model.generate(
        input_ids, temperature=<span class="hljs-number">0.8</span>, num_return_sequences=<span class="hljs-number">16</span>, do_sample=<span class="hljs-literal">True</span>, max_new_tokens=<span class="hljs-number">128</span>, top_k=<span class="hljs-number">10</span>
    )
    <span class="hljs-keyword">return</span> tokenizer.batch_decode(outputs, skip_special_tokens=<span class="hljs-literal">True</span>)`}}),ze=new I({props:{code:"c291cmNlX2NhcHRpb25zJTIwJTNEJTIwZ2VuZXJhdGVfY2FwdGlvbnMoc291cmNlX3RleHQpJTBBdGFyZ2V0X2NhcHRpb25zJTIwJTNEJTIwZ2VuZXJhdGVfY2FwdGlvbnModGFyZ2V0X2NvbmNlcHQp",highlighted:`source_captions = generate_captions(source_text)
target_captions = generate_captions(target_concept)`}}),He=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpeDJQaXhaZXJvUGlwZWxpbmUlMjAlMEElMEFwaXBlbGluZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblBpeDJQaXhaZXJvUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMEEpJTBBcGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZS50byglMjJjdWRhJTIyKSUwQXRva2VuaXplciUyMCUzRCUyMHBpcGVsaW5lLnRva2VuaXplciUwQXRleHRfZW5jb2RlciUyMCUzRCUyMHBpcGVsaW5lLnRleHRfZW5jb2Rlcg==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPix2PixZeroPipeline 

pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained(
    <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>, torch_dtype=torch.float16
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)
tokenizer = pipeline.tokenizer
text_encoder = pipeline.text_encoder`}}),qe=new I({props:{code:"aW1wb3J0JTIwdG9yY2glMjAlMEElMEFkZWYlMjBlbWJlZF9jYXB0aW9ucyhzZW50ZW5jZXMlMkMlMjB0b2tlbml6ZXIlMkMlMjB0ZXh0X2VuY29kZXIlMkMlMjBkZXZpY2UlM0QlMjJjdWRhJTIyKSUzQSUwQSUyMCUyMCUyMCUyMHdpdGglMjB0b3JjaC5ub19ncmFkK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ZXZpY2UpJTJDJTIwYXR0ZW50aW9uX21hc2slM0ROb25lKSU1QjAlNUQlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBlbWJlZGRpbmdzLmFwcGVuZChwcm9tcHRfZW1iZWRzKSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHRvcmNoLmNvbmNhdGVuYXRlKGVtYmVkZGluZ3MlMkMlMjBkaW0lM0QwKS5tZWFuKGRpbSUzRDApLnVuc3F1ZWV6ZSgwKSUwQSUwQXNvdXJjZV9lbWJlZGRpbmdzJTIwJTNEJTIwZW1iZWRfY2FwdGlvbnMoc291cmNlX2NhcHRpb25zJTJDJTIwdG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyKSUwQXRhcmdldF9lbWJlZGRpbmdzJTIwJTNEJTIwZW1iZWRfY2FwdGlvbnModGFyZ2V0X2NhcHRpb25zJTJDJTIwdG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyKQ==",highlighted:`<span class="hljs-keyword">import</span> torch 

<span class="hljs-keyword">def</span> <span class="hljs-title function_">embed_captions</span>(<span class="hljs-params">sentences, tokenizer, text_encoder, device=<span class="hljs-string">&quot;cuda&quot;</span></span>):
    <span class="hljs-keyword">with</span> torch.no_grad():
        embeddings = []
        <span class="hljs-keyword">for</span> sent <span class="hljs-keyword">in</span> sentences:
            text_inputs = tokenizer(
                sent,
                padding=<span class="hljs-string">&quot;max_length&quot;</span>,
                max_length=tokenizer.model_max_length,
                truncation=<span class="hljs-literal">True</span>,
                return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
            )
            text_input_ids = text_inputs.input_ids
            prompt_embeds = text_encoder(text_input_ids.to(device), attention_mask=<span class="hljs-literal">None</span>)[<span class="hljs-number">0</span>]
            embeddings.append(prompt_embeds)
    <span class="hljs-keyword">return</span> torch.concatenate(embeddings, dim=<span class="hljs-number">0</span>).mean(dim=<span class="hljs-number">0</span>).unsqueeze(<span class="hljs-number">0</span>)

source_embeddings = embed_captions(source_captions, tokenizer, text_encoder)
target_embeddings = embed_captions(target_captions, tokenizer, text_encoder)`}}),Ke=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERESU1TY2hlZHVsZXIlMEElMEFwaXBlbGluZS5zY2hlZHVsZXIlMjAlM0QlMjBERElNU2NoZWR1bGVyLmZyb21fY29uZmlnKHBpcGVsaW5lLnNjaGVkdWxlci5jb25maWcpJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwc291cmNlX2VtYmVkcyUzRHNvdXJjZV9lbWJlZGRpbmdzJTJDJTBBJTIwJTIwJTIwJTIwdGFyZ2V0X2VtYmVkcyUzRHRhcmdldF9lbWJlZGRpbmdzJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDUwJTJDJTBBJTIwJTIwJTIwJTIwY3Jvc3NfYXR0ZW50aW9uX2d1aWRhbmNlX2Ftb3VudCUzRDAuMTUlMkMlMEEpLmltYWdlcyUwQWltYWdlcyU1QjAlNUQuc2F2ZSglMjJlZGl0ZWRfaW1hZ2VfZG9nLnBuZyUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DDIMScheduler

pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config)

images = pipeline(
    prompt,
    source_embeds=source_embeddings,
    target_embeds=target_embeddings,
    num_inference_steps=<span class="hljs-number">50</span>,
    cross_attention_guidance_amount=<span class="hljs-number">0.15</span>,
).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;edited_image_dog.png&quot;</span>)`}}),Oe=new he({}),et=new Et({props:{name:"class diffusers.StableDiffusionPix2PixZeroPipeline",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": typing.Union[diffusers.schedulers.scheduling_ddpm.DDPMScheduler, diffusers.schedulers.scheduling_ddim.DDIMScheduler, diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteScheduler, diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteScheduler]"},{name:"feature_extractor",val:": CLIPImageProcessor"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"inverse_scheduler",val:": DDIMInverseScheduler"},{name:"caption_generator",val:": BlipForConditionalGeneration"},{name:"caption_processor",val:": BlipProcessor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/v0.21.0/en/api/models/autoencoderkl#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>CLIPTextModel</code>) &#x2014;
Frozen text-encoder. Stable Diffusion uses the text portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIP</a>, specifically
the <a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a> variant.`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/v0.21.0/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/v0.21.0/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents. Can be one of
<a href="/docs/diffusers/v0.21.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.21.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, <a href="/docs/diffusers/v0.21.0/en/api/schedulers/euler_ancestral#diffusers.EulerAncestralDiscreteScheduler">EulerAncestralDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.21.0/en/api/schedulers/ddpm#diffusers.DDPMScheduler">DDPMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.safety_checker",description:`<strong>safety_checker</strong> (<code>StableDiffusionSafetyChecker</code>) &#x2014;
Classification module that estimates whether generated images could be considered offensive or harmful.
Please, refer to the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow">model card</a> for details.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<code>CLIPImageProcessor</code>) &#x2014;
Model that extracts features from generated images to be used as inputs for the <code>safety_checker</code>.`,name:"feature_extractor"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.requires_safety_checker",description:`<strong>requires_safety_checker</strong> (bool) &#x2014;
Whether the pipeline requires a safety checker. We recommend setting it to True if you&#x2019;re using the
pipeline publicly.`,name:"requires_safety_checker"}],source:"https://github.com/huggingface/diffusers/blob/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L280"}}),st=new Et({props:{name:"__call__",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"source_embeds",val:": Tensor = None"},{name:"target_embeds",val:": Tensor = None"},{name:"height",val:": typing.Optional[int] = None"},{name:"width",val:": typing.Optional[int] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 7.5"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attention_guidance_amount",val:": float = 0.1"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": typing.Optional[int] = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.source_embeds",description:`<strong>source_embeds</strong> (<code>torch.Tensor</code>) &#x2014;
Source concept embeddings. Generation of the embeddings as per the <a href="https://arxiv.org/abs/2302.03027" rel="nofollow">original
paper</a>. Used in discovering the edit direction.`,name:"source_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.target_embeds",description:`<strong>target_embeds</strong> (<code>torch.Tensor</code>) &#x2014;
Target concept embeddings. Generation of the embeddings as per the <a href="https://arxiv.org/abs/2302.03027" rel="nofollow">original
paper</a>. Used in discovering the edit direction.`,name:"target_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. If not defined, one has to pass
<code>negative_prompt_embeds</code> instead. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is
less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) in the DDIM paper: <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">https://arxiv.org/abs/2010.02502</a>. Only applies to
<a href="/docs/diffusers/v0.21.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.cross_attention_guidance_amount",description:`<strong>cross_attention_guidance_amount</strong> (<code>float</code>, defaults to 0.1) &#x2014;
Amount of guidance needed from the reference cross-attention maps.`,name:"cross_attention_guidance_amount"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"}],source:"https://github.com/huggingface/diffusers/blob/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L782",returnDescription:`
<p><a
  href="/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of </code>bool<code>s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) content, according to the </code>safety_checker\`.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),oe=new Di({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.__call__.example",$$slots:{default:[Oi]},$$scope:{ctx:rt}}}),at=new Et({props:{name:"construct_direction",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.construct_direction",parameters:[{name:"embs_source",val:": Tensor"},{name:"embs_target",val:": Tensor"}],source:"https://github.com/huggingface/diffusers/blob/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L672"}}),nt=new Et({props:{name:"encode_prompt",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt",parameters:[{name:"prompt",val:""},{name:"device",val:""},{name:"num_images_per_prompt",val:""},{name:"do_classifier_free_guidance",val:""},{name:"negative_prompt",val:" = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"lora_scale",val:": typing.Optional[float] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
prompt to be encoded
device &#x2014; (<code>torch.device</code>):
torch device`,name:"prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>) &#x2014;
number of images that should be generated per prompt`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt.do_classifier_free_guidance",description:`<strong>do_classifier_free_guidance</strong> (<code>bool</code>) &#x2014;
whether to use classifier free guidance or not`,name:"do_classifier_free_guidance"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. If not defined, one has to pass
<code>negative_prompt_embeds</code> instead. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is
less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.encode_prompt.lora_scale",description:`<strong>lora_scale</strong> (<code>float</code>, <em>optional</em>) &#x2014;
A lora scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded.`,name:"lora_scale"}],source:"https://github.com/huggingface/diffusers/blob/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L400"}}),lt=new Et({props:{name:"generate_caption",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.generate_caption",parameters:[{name:"images",val:""}],source:"https://github.com/huggingface/diffusers/blob/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L652"}}),ot=new Et({props:{name:"invert",anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert",parameters:[{name:"prompt",val:": typing.Optional[str] = None"},{name:"image",val:": typing.Union[PIL.Image.Image, numpy.ndarray, torch.FloatTensor, typing.List[PIL.Image.Image], typing.List[numpy.ndarray], typing.List[torch.FloatTensor]] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 1"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"cross_attention_guidance_amount",val:": float = 0.1"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": typing.Optional[int] = 1"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"},{name:"lambda_auto_corr",val:": float = 20.0"},{name:"lambda_kl",val:": float = 20.0"},{name:"num_reg_steps",val:": int = 5"},{name:"num_auto_corr_rolls",val:": int = 5"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.image",description:`<strong>image</strong> (<code>torch.FloatTensor</code> <code>np.ndarray</code>, <code>PIL.Image.Image</code>, <code>List[torch.FloatTensor]</code>, <code>List[PIL.Image.Image]</code>, or <code>List[np.ndarray]</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch which will be used for conditioning. Can also accept
image latents as <code>image</code>, if passing latents directly, it will not be encoded again.`,name:"image"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 1) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.cross_attention_guidance_amount",description:`<strong>cross_attention_guidance_amount</strong> (<code>float</code>, defaults to 0.1) &#x2014;
Amount of guidance needed from the reference cross-attention maps.`,name:"cross_attention_guidance_amount"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.lambda_auto_corr",description:`<strong>lambda_auto_corr</strong> (<code>float</code>, <em>optional</em>, defaults to 20.0) &#x2014;
Lambda parameter to control auto correction`,name:"lambda_auto_corr"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.lambda_kl",description:`<strong>lambda_kl</strong> (<code>float</code>, <em>optional</em>, defaults to 20.0) &#x2014;
Lambda parameter to control Kullback&#x2013;Leibler divergence output`,name:"lambda_kl"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_reg_steps",description:`<strong>num_reg_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Number of regularization loss steps`,name:"num_reg_steps"},{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.num_auto_corr_rolls",description:`<strong>num_auto_corr_rolls</strong> (<code>int</code>, <em>optional</em>, defaults to 5) &#x2014;
Number of auto correction roll steps`,name:"num_auto_corr_rolls"}],source:"https://github.com/huggingface/diffusers/blob/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py#L1068",returnDescription:`
<p><code>Pix2PixInversionPipelineOutput</code> or
<code>tuple</code>:
<code>Pix2PixInversionPipelineOutput</code> if
<code>return_dict</code> is True, otherwise a \`tuple. When returning a tuple, the first element is the inverted
latents tensor and then second is the corresponding decoded image.</p>
`}}),ce=new Di({props:{anchor:"diffusers.StableDiffusionPix2PixZeroPipeline.invert.example",$$slots:{default:[er]},$$scope:{ctx:rt}}}),{c(){J=a("meta"),G=c(),T=a("h1"),M=a("a"),U=a("span"),h(u.$$.fragment),Z=c(),Wt=a("span"),Xa=o("Pix2Pix Zero"),Is=c(),fe=a("p"),ge=a("a"),Pa=o("Zero-shot Image-to-Image Translation"),Ra=o(" is by Gaurav Parmar, Krishna Kumar Singh, Richard Zhang, Yijun Li, Jingwan Lu, and Jun-Yan Zhu."),xs=c(),pt=a("p"),Va=o("The abstract from the paper is:"),Gs=c(),ct=a("p"),kt=a("em"),Na=o("Large-scale text-to-image generative models have shown their remarkable ability to synthesize diverse and high-quality images. However, it is still challenging to directly apply these models for editing real images for two reasons. First, it is hard for users to come up with a perfect text prompt that accurately describes every visual detail in the input image. Second, while existing models can introduce desirable changes in certain regions, they often dramatically alter the input content and introduce unexpected changes in unwanted regions. In this work, we propose pix2pix-zero, an image-to-image translation method that can preserve the content of the original image without manual prompting. We first automatically discover editing directions that reflect desired edits in the text embedding space. To preserve the general content structure after editing, we further propose cross-attention guidance, which aims to retain the cross-attention maps of the input image throughout the diffusion process. In addition, our method does not need additional training for these edits and can directly use the existing pre-trained text-to-image diffusion model. We conduct extensive experiments and show that our method outperforms existing and concurrent works for both real and synthetic image editing."),Bs=c(),B=a("p"),Ca=o("You can find additional information about Pix2Pix Zero on the "),be=a("a"),Sa=o("project page"),Ya=o(",  "),ye=a("a"),Fa=o("original codebase"),$a=o(", and try it out in a "),we=a("a"),za=o("demo"),Da=o("."),Es=c(),N=a("h2"),q=a("a"),Xt=a("span"),h(Me.$$.fragment),Qa=c(),Pt=a("span"),Ha=o("Tips"),Ws=c(),j=a("ul"),Rt=a("li"),Aa=o("The pipeline can be conditioned on real input images. Check out the code examples below to know more."),qa=c(),x=a("li"),La=o("The pipeline exposes two arguments namely "),Vt=a("code"),Ka=o("source_embeds"),Oa=o(" and "),Nt=a("code"),en=o("target_embeds"),tn=o(`
that let you control the direction of the semantic edits in the final image to be generated. Let\u2019s say,
you wanted to translate from \u201Ccat\u201D to \u201Cdog\u201D. In this case, the edit direction will be \u201Ccat -> dog\u201D. To reflect
this in the pipeline, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),Ct=a("code"),sn=o("source_embeds"),an=o(" and \u201Cdog\u201D to "),St=a("code"),nn=o("target_embeds"),ln=o(". Refer to the code example below for more details."),on=c(),C=a("li"),rn=o("When you\u2019re using this pipeline from a prompt, specify the "),Yt=a("em"),pn=o("source"),cn=o(` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),Ft=a("strong"),dn=o("cat"),mn=o(" in the style of van gough\u201D."),un=c(),dt=a("li"),hn=o("If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),Je=a("ul"),S=a("li"),fn=o("Swap the "),$t=a("code"),gn=o("source_embeds"),bn=o(" and "),zt=a("code"),yn=o("target_embeds"),wn=o("."),Mn=c(),Dt=a("li"),Jn=o("Change the input prompt to include \u201Cdog\u201D."),_n=c(),_e=a("li"),Tn=o("To learn more about how the source and target embeddings are generated, refer to the "),Te=a("a"),Zn=o(`original
paper`),jn=o(". Below, we also provide some directions on how to generate the embeddings."),vn=c(),k=a("li"),Un=o("Note that the quality of the outputs generated with this pipeline is dependent on how good the "),Qt=a("code"),In=o("source_embeds"),xn=o(" and "),Ht=a("code"),Gn=o("target_embeds"),Bn=o(" are. Please, refer to "),mt=a("a"),En=o("this discussion"),Wn=o(" for some suggestions on the topic."),ks=c(),Y=a("h2"),L=a("a"),At=a("span"),h(Ze.$$.fragment),kn=c(),qt=a("span"),Xn=o("Available Pipelines:"),Xs=c(),K=a("table"),Lt=a("thead"),F=a("tr"),Kt=a("th"),Pn=o("Pipeline"),Rn=c(),Ot=a("th"),Vn=o("Tasks"),Nn=c(),ut=a("th"),Cn=o("Demo"),Sn=c(),es=a("tbody"),$=a("tr"),ts=a("td"),je=a("a"),Yn=o("StableDiffusionPix2PixZeroPipeline"),Fn=c(),ss=a("td"),as=a("em"),$n=o("Text-Based Image Editing"),zn=c(),ht=a("td"),ve=a("a"),Dn=o("\u{1F917} Space"),Ps=c(),z=a("h2"),O=a("a"),ns=a("span"),h(Ue.$$.fragment),Qn=c(),ls=a("span"),Hn=o("Usage example"),Rs=c(),D=a("h3"),ee=a("a"),os=a("span"),h(Ie.$$.fragment),An=c(),is=a("span"),qn=o("Based on an image generated with the input prompt"),Vs=c(),h(xe.$$.fragment),Ns=c(),Q=a("h3"),te=a("a"),rs=a("span"),h(Ge.$$.fragment),Ln=c(),ps=a("span"),Kn=o("Based on an input image"),Cs=c(),se=a("p"),On=o(`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),cs=a("code"),el=o("DDIMInverseScheduler"),tl=o(` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),Ss=c(),ft=a("p"),sl=o("First, let\u2019s load our pipeline:"),Ys=c(),h(Be.$$.fragment),Fs=c(),gt=a("p"),al=o("Then, we load an input image for conditioning and obtain a suitable caption for it:"),$s=c(),h(Ee.$$.fragment),zs=c(),bt=a("p"),nl=o("Then we employ the generated caption and the input image to get the inverted noise:"),Ds=c(),h(We.$$.fragment),Qs=c(),yt=a("p"),ll=o("Now, generate the image with edit directions:"),Hs=c(),h(ke.$$.fragment),As=c(),H=a("h2"),ae=a("a"),ds=a("span"),h(Xe.$$.fragment),ol=c(),ms=a("span"),il=o("Generating source and target embeddings"),qs=c(),E=a("p"),rl=o("The authors originally used the "),Pe=a("a"),pl=o("GPT-3 API"),cl=o(` to generate the source and target captions for discovering
edit directions. However, we can also leverage open source and public models for the same purpose.
Below, we provide an end-to-end example with the `),Re=a("a"),dl=o("Flan-T5"),ml=o(` model
for generating captions and `),Ve=a("a"),ul=o("CLIP"),hl=o(` for
computing embeddings on the generated captions.`),Ls=c(),Ne=a("p"),us=a("strong"),fl=o("1. Load the generation model"),gl=o(":"),Ks=c(),h(Ce.$$.fragment),Os=c(),Se=a("p"),hs=a("strong"),bl=o("2. Construct a starting prompt"),yl=o(":"),ea=c(),h(Ye.$$.fragment),ta=c(),wt=a("p"),wl=o("Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),sa=c(),Fe=a("p"),fs=a("strong"),Ml=o("3. Generate captions"),Jl=o(":"),aa=c(),Mt=a("p"),_l=o("We can use a utility like so for this purpose."),na=c(),h($e.$$.fragment),la=c(),Jt=a("p"),Tl=o("And then we just call it to generate our captions:"),oa=c(),h(ze.$$.fragment),ia=c(),X=a("p"),Zl=o(`We encourage you to play around with the different parameters supported by the
`),gs=a("code"),jl=o("generate()"),vl=o(" method ("),De=a("a"),Ul=o("documentation"),Il=o(") for the generation quality you are looking for."),ra=c(),Qe=a("p"),bs=a("strong"),xl=o("4. Load the embedding model"),Gl=o(":"),pa=c(),_t=a("p"),Bl=o("Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),ca=c(),h(He.$$.fragment),da=c(),Ae=a("p"),ys=a("strong"),El=o("5. Compute embeddings"),Wl=o(":"),ma=c(),h(qe.$$.fragment),ua=c(),ne=a("p"),kl=o("And you\u2019re done! "),Le=a("a"),Xl=o("Here"),Pl=o(" is a Colab Notebook that you can use to interact with the entire process."),ha=c(),Tt=a("p"),Rl=o("Now, you can use these embeddings directly while calling the pipeline:"),fa=c(),h(Ke.$$.fragment),ga=c(),A=a("h2"),le=a("a"),ws=a("span"),h(Oe.$$.fragment),Vl=c(),Ms=a("span"),Nl=o("StableDiffusionPix2PixZeroPipeline"),ba=c(),_=a("div"),h(et.$$.fragment),Cl=c(),Js=a("p"),Sl=o("Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),Yl=c(),tt=a("p"),Fl=o("This model inherits from "),Zt=a("a"),$l=o("DiffusionPipeline"),zl=o(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Dl=c(),P=a("div"),h(st.$$.fragment),Ql=c(),_s=a("p"),Hl=o("Function invoked when calling the pipeline for generation."),Al=c(),h(oe.$$.fragment),ql=c(),ie=a("div"),h(at.$$.fragment),Ll=c(),Ts=a("p"),Kl=o("Constructs the edit direction to steer the image generation process semantically."),Ol=c(),re=a("div"),h(nt.$$.fragment),eo=c(),Zs=a("p"),to=o("Encodes the prompt into text encoder hidden states."),so=c(),pe=a("div"),h(lt.$$.fragment),ao=c(),js=a("p"),no=o("Generates caption for a given image."),lo=c(),R=a("div"),h(ot.$$.fragment),oo=c(),vs=a("p"),io=o("Function used to generate inverted latents given a prompt and image."),ro=c(),h(ce.$$.fragment),this.h()},l(e){const r=Li('[data-svelte="svelte-1phssyn"]',document.head);J=n(r,"META",{name:!0,content:!0}),r.forEach(s),G=d(e),T=n(e,"H1",{class:!0});var it=l(T);M=n(it,"A",{id:!0,class:!0,href:!0});var Us=l(M);U=n(Us,"SPAN",{});var bo=l(U);f(u.$$.fragment,bo),bo.forEach(s),Us.forEach(s),Z=d(it),Wt=n(it,"SPAN",{});var yo=l(Wt);Xa=i(yo,"Pix2Pix Zero"),yo.forEach(s),it.forEach(s),Is=d(e),fe=n(e,"P",{});var po=l(fe);ge=n(po,"A",{href:!0,rel:!0});var wo=l(ge);Pa=i(wo,"Zero-shot Image-to-Image Translation"),wo.forEach(s),Ra=i(po," is by Gaurav Parmar, Krishna Kumar Singh, Richard Zhang, Yijun Li, Jingwan Lu, and Jun-Yan Zhu."),po.forEach(s),xs=d(e),pt=n(e,"P",{});var Mo=l(pt);Va=i(Mo,"The abstract from the paper is:"),Mo.forEach(s),Gs=d(e),ct=n(e,"P",{});var Jo=l(ct);kt=n(Jo,"EM",{});var _o=l(kt);Na=i(_o,"Large-scale text-to-image generative models have shown their remarkable ability to synthesize diverse and high-quality images. However, it is still challenging to directly apply these models for editing real images for two reasons. First, it is hard for users to come up with a perfect text prompt that accurately describes every visual detail in the input image. Second, while existing models can introduce desirable changes in certain regions, they often dramatically alter the input content and introduce unexpected changes in unwanted regions. In this work, we propose pix2pix-zero, an image-to-image translation method that can preserve the content of the original image without manual prompting. We first automatically discover editing directions that reflect desired edits in the text embedding space. To preserve the general content structure after editing, we further propose cross-attention guidance, which aims to retain the cross-attention maps of the input image throughout the diffusion process. In addition, our method does not need additional training for these edits and can directly use the existing pre-trained text-to-image diffusion model. We conduct extensive experiments and show that our method outperforms existing and concurrent works for both real and synthetic image editing."),_o.forEach(s),Jo.forEach(s),Bs=d(e),B=n(e,"P",{});var de=l(B);Ca=i(de,"You can find additional information about Pix2Pix Zero on the "),be=n(de,"A",{href:!0,rel:!0});var To=l(be);Sa=i(To,"project page"),To.forEach(s),Ya=i(de,",  "),ye=n(de,"A",{href:!0,rel:!0});var Zo=l(ye);Fa=i(Zo,"original codebase"),Zo.forEach(s),$a=i(de,", and try it out in a "),we=n(de,"A",{href:!0,rel:!0});var jo=l(we);za=i(jo,"demo"),jo.forEach(s),Da=i(de,"."),de.forEach(s),Es=d(e),N=n(e,"H2",{class:!0});var wa=l(N);q=n(wa,"A",{id:!0,class:!0,href:!0});var vo=l(q);Xt=n(vo,"SPAN",{});var Uo=l(Xt);f(Me.$$.fragment,Uo),Uo.forEach(s),vo.forEach(s),Qa=d(wa),Pt=n(wa,"SPAN",{});var Io=l(Pt);Ha=i(Io,"Tips"),Io.forEach(s),wa.forEach(s),Ws=d(e),j=n(e,"UL",{});var W=l(j);Rt=n(W,"LI",{});var xo=l(Rt);Aa=i(xo,"The pipeline can be conditioned on real input images. Check out the code examples below to know more."),xo.forEach(s),qa=d(W),x=n(W,"LI",{});var V=l(x);La=i(V,"The pipeline exposes two arguments namely "),Vt=n(V,"CODE",{});var Go=l(Vt);Ka=i(Go,"source_embeds"),Go.forEach(s),Oa=i(V," and "),Nt=n(V,"CODE",{});var Bo=l(Nt);en=i(Bo,"target_embeds"),Bo.forEach(s),tn=i(V,`
that let you control the direction of the semantic edits in the final image to be generated. Let\u2019s say,
you wanted to translate from \u201Ccat\u201D to \u201Cdog\u201D. In this case, the edit direction will be \u201Ccat -> dog\u201D. To reflect
this in the pipeline, you simply have to set the embeddings related to the phrases including \u201Ccat\u201D to
`),Ct=n(V,"CODE",{});var Eo=l(Ct);sn=i(Eo,"source_embeds"),Eo.forEach(s),an=i(V," and \u201Cdog\u201D to "),St=n(V,"CODE",{});var Wo=l(St);nn=i(Wo,"target_embeds"),Wo.forEach(s),ln=i(V,". Refer to the code example below for more details."),V.forEach(s),on=d(W),C=n(W,"LI",{});var jt=l(C);rn=i(jt,"When you\u2019re using this pipeline from a prompt, specify the "),Yt=n(jt,"EM",{});var ko=l(Yt);pn=i(ko,"source"),ko.forEach(s),cn=i(jt,` concept in the prompt. Taking
the above example, a valid input prompt would be: \u201Ca high resolution painting of a `),Ft=n(jt,"STRONG",{});var Xo=l(Ft);dn=i(Xo,"cat"),Xo.forEach(s),mn=i(jt," in the style of van gough\u201D."),jt.forEach(s),un=d(W),dt=n(W,"LI",{});var co=l(dt);hn=i(co,"If you wanted to reverse the direction in the example above, i.e., \u201Cdog -> cat\u201D, then it\u2019s recommended to:"),Je=n(co,"UL",{});var Ma=l(Je);S=n(Ma,"LI",{});var vt=l(S);fn=i(vt,"Swap the "),$t=n(vt,"CODE",{});var Po=l($t);gn=i(Po,"source_embeds"),Po.forEach(s),bn=i(vt," and "),zt=n(vt,"CODE",{});var Ro=l(zt);yn=i(Ro,"target_embeds"),Ro.forEach(s),wn=i(vt,"."),vt.forEach(s),Mn=d(Ma),Dt=n(Ma,"LI",{});var Vo=l(Dt);Jn=i(Vo,"Change the input prompt to include \u201Cdog\u201D."),Vo.forEach(s),Ma.forEach(s),co.forEach(s),_n=d(W),_e=n(W,"LI",{});var Ja=l(_e);Tn=i(Ja,"To learn more about how the source and target embeddings are generated, refer to the "),Te=n(Ja,"A",{href:!0,rel:!0});var No=l(Te);Zn=i(No,`original
paper`),No.forEach(s),jn=i(Ja,". Below, we also provide some directions on how to generate the embeddings."),Ja.forEach(s),vn=d(W),k=n(W,"LI",{});var me=l(k);Un=i(me,"Note that the quality of the outputs generated with this pipeline is dependent on how good the "),Qt=n(me,"CODE",{});var Co=l(Qt);In=i(Co,"source_embeds"),Co.forEach(s),xn=i(me," and "),Ht=n(me,"CODE",{});var So=l(Ht);Gn=i(So,"target_embeds"),So.forEach(s),Bn=i(me," are. Please, refer to "),mt=n(me,"A",{href:!0});var Yo=l(mt);En=i(Yo,"this discussion"),Yo.forEach(s),Wn=i(me," for some suggestions on the topic."),me.forEach(s),W.forEach(s),ks=d(e),Y=n(e,"H2",{class:!0});var _a=l(Y);L=n(_a,"A",{id:!0,class:!0,href:!0});var Fo=l(L);At=n(Fo,"SPAN",{});var $o=l(At);f(Ze.$$.fragment,$o),$o.forEach(s),Fo.forEach(s),kn=d(_a),qt=n(_a,"SPAN",{});var zo=l(qt);Xn=i(zo,"Available Pipelines:"),zo.forEach(s),_a.forEach(s),Xs=d(e),K=n(e,"TABLE",{});var Ta=l(K);Lt=n(Ta,"THEAD",{});var Do=l(Lt);F=n(Do,"TR",{});var Ut=l(F);Kt=n(Ut,"TH",{});var Qo=l(Kt);Pn=i(Qo,"Pipeline"),Qo.forEach(s),Rn=d(Ut),Ot=n(Ut,"TH",{});var Ho=l(Ot);Vn=i(Ho,"Tasks"),Ho.forEach(s),Nn=d(Ut),ut=n(Ut,"TH",{align:!0});var Ao=l(ut);Cn=i(Ao,"Demo"),Ao.forEach(s),Ut.forEach(s),Do.forEach(s),Sn=d(Ta),es=n(Ta,"TBODY",{});var qo=l(es);$=n(qo,"TR",{});var It=l($);ts=n(It,"TD",{});var Lo=l(ts);je=n(Lo,"A",{href:!0,rel:!0});var Ko=l(je);Yn=i(Ko,"StableDiffusionPix2PixZeroPipeline"),Ko.forEach(s),Lo.forEach(s),Fn=d(It),ss=n(It,"TD",{});var Oo=l(ss);as=n(Oo,"EM",{});var ei=l(as);$n=i(ei,"Text-Based Image Editing"),ei.forEach(s),Oo.forEach(s),zn=d(It),ht=n(It,"TD",{align:!0});var ti=l(ht);ve=n(ti,"A",{href:!0,rel:!0});var si=l(ve);Dn=i(si,"\u{1F917} Space"),si.forEach(s),ti.forEach(s),It.forEach(s),qo.forEach(s),Ta.forEach(s),Ps=d(e),z=n(e,"H2",{class:!0});var Za=l(z);O=n(Za,"A",{id:!0,class:!0,href:!0});var ai=l(O);ns=n(ai,"SPAN",{});var ni=l(ns);f(Ue.$$.fragment,ni),ni.forEach(s),ai.forEach(s),Qn=d(Za),ls=n(Za,"SPAN",{});var li=l(ls);Hn=i(li,"Usage example"),li.forEach(s),Za.forEach(s),Rs=d(e),D=n(e,"H3",{class:!0});var ja=l(D);ee=n(ja,"A",{id:!0,class:!0,href:!0});var oi=l(ee);os=n(oi,"SPAN",{});var ii=l(os);f(Ie.$$.fragment,ii),ii.forEach(s),oi.forEach(s),An=d(ja),is=n(ja,"SPAN",{});var ri=l(is);qn=i(ri,"Based on an image generated with the input prompt"),ri.forEach(s),ja.forEach(s),Vs=d(e),f(xe.$$.fragment,e),Ns=d(e),Q=n(e,"H3",{class:!0});var va=l(Q);te=n(va,"A",{id:!0,class:!0,href:!0});var pi=l(te);rs=n(pi,"SPAN",{});var ci=l(rs);f(Ge.$$.fragment,ci),ci.forEach(s),pi.forEach(s),Ln=d(va),ps=n(va,"SPAN",{});var di=l(ps);Kn=i(di,"Based on an input image"),di.forEach(s),va.forEach(s),Cs=d(e),se=n(e,"P",{});var Ua=l(se);On=i(Ua,`When the pipeline is conditioned on an input image, we first obtain an inverted
noise from it using a `),cs=n(Ua,"CODE",{});var mi=l(cs);el=i(mi,"DDIMInverseScheduler"),mi.forEach(s),tl=i(Ua,` with the help of a generated caption. Then
the inverted noise is used to start the generation process.`),Ua.forEach(s),Ss=d(e),ft=n(e,"P",{});var ui=l(ft);sl=i(ui,"First, let\u2019s load our pipeline:"),ui.forEach(s),Ys=d(e),f(Be.$$.fragment,e),Fs=d(e),gt=n(e,"P",{});var hi=l(gt);al=i(hi,"Then, we load an input image for conditioning and obtain a suitable caption for it:"),hi.forEach(s),$s=d(e),f(Ee.$$.fragment,e),zs=d(e),bt=n(e,"P",{});var fi=l(bt);nl=i(fi,"Then we employ the generated caption and the input image to get the inverted noise:"),fi.forEach(s),Ds=d(e),f(We.$$.fragment,e),Qs=d(e),yt=n(e,"P",{});var gi=l(yt);ll=i(gi,"Now, generate the image with edit directions:"),gi.forEach(s),Hs=d(e),f(ke.$$.fragment,e),As=d(e),H=n(e,"H2",{class:!0});var Ia=l(H);ae=n(Ia,"A",{id:!0,class:!0,href:!0});var bi=l(ae);ds=n(bi,"SPAN",{});var yi=l(ds);f(Xe.$$.fragment,yi),yi.forEach(s),bi.forEach(s),ol=d(Ia),ms=n(Ia,"SPAN",{});var wi=l(ms);il=i(wi,"Generating source and target embeddings"),wi.forEach(s),Ia.forEach(s),qs=d(e),E=n(e,"P",{});var ue=l(E);rl=i(ue,"The authors originally used the "),Pe=n(ue,"A",{href:!0,rel:!0});var Mi=l(Pe);pl=i(Mi,"GPT-3 API"),Mi.forEach(s),cl=i(ue,` to generate the source and target captions for discovering
edit directions. However, we can also leverage open source and public models for the same purpose.
Below, we provide an end-to-end example with the `),Re=n(ue,"A",{href:!0,rel:!0});var Ji=l(Re);dl=i(Ji,"Flan-T5"),Ji.forEach(s),ml=i(ue,` model
for generating captions and `),Ve=n(ue,"A",{href:!0,rel:!0});var _i=l(Ve);ul=i(_i,"CLIP"),_i.forEach(s),hl=i(ue,` for
computing embeddings on the generated captions.`),ue.forEach(s),Ls=d(e),Ne=n(e,"P",{});var mo=l(Ne);us=n(mo,"STRONG",{});var Ti=l(us);fl=i(Ti,"1. Load the generation model"),Ti.forEach(s),gl=i(mo,":"),mo.forEach(s),Ks=d(e),f(Ce.$$.fragment,e),Os=d(e),Se=n(e,"P",{});var uo=l(Se);hs=n(uo,"STRONG",{});var Zi=l(hs);bl=i(Zi,"2. Construct a starting prompt"),Zi.forEach(s),yl=i(uo,":"),uo.forEach(s),ea=d(e),f(Ye.$$.fragment,e),ta=d(e),wt=n(e,"P",{});var ji=l(wt);wl=i(ji,"Here, we\u2019re interested in the \u201Ccat -> dog\u201D direction."),ji.forEach(s),sa=d(e),Fe=n(e,"P",{});var ho=l(Fe);fs=n(ho,"STRONG",{});var vi=l(fs);Ml=i(vi,"3. Generate captions"),vi.forEach(s),Jl=i(ho,":"),ho.forEach(s),aa=d(e),Mt=n(e,"P",{});var Ui=l(Mt);_l=i(Ui,"We can use a utility like so for this purpose."),Ui.forEach(s),na=d(e),f($e.$$.fragment,e),la=d(e),Jt=n(e,"P",{});var Ii=l(Jt);Tl=i(Ii,"And then we just call it to generate our captions:"),Ii.forEach(s),oa=d(e),f(ze.$$.fragment,e),ia=d(e),X=n(e,"P",{});var xt=l(X);Zl=i(xt,`We encourage you to play around with the different parameters supported by the
`),gs=n(xt,"CODE",{});var xi=l(gs);jl=i(xi,"generate()"),xi.forEach(s),vl=i(xt," method ("),De=n(xt,"A",{href:!0,rel:!0});var Gi=l(De);Ul=i(Gi,"documentation"),Gi.forEach(s),Il=i(xt,") for the generation quality you are looking for."),xt.forEach(s),ra=d(e),Qe=n(e,"P",{});var fo=l(Qe);bs=n(fo,"STRONG",{});var Bi=l(bs);xl=i(Bi,"4. Load the embedding model"),Bi.forEach(s),Gl=i(fo,":"),fo.forEach(s),pa=d(e),_t=n(e,"P",{});var Ei=l(_t);Bl=i(Ei,"Here, we need to use the same text encoder model used by the subsequent Stable Diffusion model."),Ei.forEach(s),ca=d(e),f(He.$$.fragment,e),da=d(e),Ae=n(e,"P",{});var go=l(Ae);ys=n(go,"STRONG",{});var Wi=l(ys);El=i(Wi,"5. Compute embeddings"),Wi.forEach(s),Wl=i(go,":"),go.forEach(s),ma=d(e),f(qe.$$.fragment,e),ua=d(e),ne=n(e,"P",{});var xa=l(ne);kl=i(xa,"And you\u2019re done! "),Le=n(xa,"A",{href:!0,rel:!0});var ki=l(Le);Xl=i(ki,"Here"),ki.forEach(s),Pl=i(xa," is a Colab Notebook that you can use to interact with the entire process."),xa.forEach(s),ha=d(e),Tt=n(e,"P",{});var Xi=l(Tt);Rl=i(Xi,"Now, you can use these embeddings directly while calling the pipeline:"),Xi.forEach(s),fa=d(e),f(Ke.$$.fragment,e),ga=d(e),A=n(e,"H2",{class:!0});var Ga=l(A);le=n(Ga,"A",{id:!0,class:!0,href:!0});var Pi=l(le);ws=n(Pi,"SPAN",{});var Ri=l(ws);f(Oe.$$.fragment,Ri),Ri.forEach(s),Pi.forEach(s),Vl=d(Ga),Ms=n(Ga,"SPAN",{});var Vi=l(Ms);Nl=i(Vi,"StableDiffusionPix2PixZeroPipeline"),Vi.forEach(s),Ga.forEach(s),ba=d(e),_=n(e,"DIV",{class:!0});var v=l(_);f(et.$$.fragment,v),Cl=d(v),Js=n(v,"P",{});var Ni=l(Js);Sl=i(Ni,"Pipeline for pixel-levl image editing using Pix2Pix Zero. Based on Stable Diffusion."),Ni.forEach(s),Yl=d(v),tt=n(v,"P",{});var Ba=l(tt);Fl=i(Ba,"This model inherits from "),Zt=n(Ba,"A",{href:!0});var Ci=l(Zt);$l=i(Ci,"DiffusionPipeline"),Ci.forEach(s),zl=i(Ba,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Ba.forEach(s),Dl=d(v),P=n(v,"DIV",{class:!0});var Gt=l(P);f(st.$$.fragment,Gt),Ql=d(Gt),_s=n(Gt,"P",{});var Si=l(_s);Hl=i(Si,"Function invoked when calling the pipeline for generation."),Si.forEach(s),Al=d(Gt),f(oe.$$.fragment,Gt),Gt.forEach(s),ql=d(v),ie=n(v,"DIV",{class:!0});var Ea=l(ie);f(at.$$.fragment,Ea),Ll=d(Ea),Ts=n(Ea,"P",{});var Yi=l(Ts);Kl=i(Yi,"Constructs the edit direction to steer the image generation process semantically."),Yi.forEach(s),Ea.forEach(s),Ol=d(v),re=n(v,"DIV",{class:!0});var Wa=l(re);f(nt.$$.fragment,Wa),eo=d(Wa),Zs=n(Wa,"P",{});var Fi=l(Zs);to=i(Fi,"Encodes the prompt into text encoder hidden states."),Fi.forEach(s),Wa.forEach(s),so=d(v),pe=n(v,"DIV",{class:!0});var ka=l(pe);f(lt.$$.fragment,ka),ao=d(ka),js=n(ka,"P",{});var $i=l(js);no=i($i,"Generates caption for a given image."),$i.forEach(s),ka.forEach(s),lo=d(v),R=n(v,"DIV",{class:!0});var Bt=l(R);f(ot.$$.fragment,Bt),oo=d(Bt),vs=n(Bt,"P",{});var zi=l(vs);io=i(zi,"Function used to generate inverted latents given a prompt and image."),zi.forEach(s),ro=d(Bt),f(ce.$$.fragment,Bt),Bt.forEach(s),v.forEach(s),this.h()},h(){m(J,"name","hf:doc:metadata"),m(J,"content",JSON.stringify(sr)),m(M,"id","pix2pix-zero"),m(M,"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"),m(M,"href","#pix2pix-zero"),m(T,"class","relative group"),m(ge,"href","https://huggingface.co/papers/2302.03027"),m(ge,"rel","nofollow"),m(be,"href","https://pix2pixzero.github.io/"),m(be,"rel","nofollow"),m(ye,"href","https://github.com/pix2pixzero/pix2pix-zero"),m(ye,"rel","nofollow"),m(we,"href","https://huggingface.co/spaces/pix2pix-zero-library/pix2pix-zero-demo"),m(we,"rel","nofollow"),m(q,"id","tips"),m(q,"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"),m(q,"href","#tips"),m(N,"class","relative group"),m(Te,"href","https://arxiv.org/abs/2302.03027"),m(Te,"rel","nofollow"),m(mt,"href","#generating-source-and-target-embeddings"),m(L,"id","available-pipelines"),m(L,"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"),m(L,"href","#available-pipelines"),m(Y,"class","relative group"),m(ut,"align","center"),m(je,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_pix2pix_zero.py"),m(je,"rel","nofollow"),m(ve,"href","https://huggingface.co/spaces/pix2pix-zero-library/pix2pix-zero-demo"),m(ve,"rel","nofollow"),m(ht,"align","center"),m(O,"id","usage-example"),m(O,"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"),m(O,"href","#usage-example"),m(z,"class","relative group"),m(ee,"id","based-on-an-image-generated-with-the-input-prompt"),m(ee,"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"),m(ee,"href","#based-on-an-image-generated-with-the-input-prompt"),m(D,"class","relative group"),m(te,"id","based-on-an-input-image"),m(te,"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"),m(te,"href","#based-on-an-input-image"),m(Q,"class","relative group"),m(ae,"id","generating-source-and-target-embeddings"),m(ae,"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"),m(ae,"href","#generating-source-and-target-embeddings"),m(H,"class","relative group"),m(Pe,"href","https://openai.com/api/"),m(Pe,"rel","nofollow"),m(Re,"href","https://huggingface.co/docs/transformers/model_doc/flan-t5"),m(Re,"rel","nofollow"),m(Ve,"href","https://huggingface.co/docs/transformers/model_doc/clip"),m(Ve,"rel","nofollow"),m(De,"href","https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.generation_tf_utils.TFGenerationMixin.generate"),m(De,"rel","nofollow"),m(Le,"href","https://colab.research.google.com/drive/1tz2C1EdfZYAPlzXXbTnf-5PRBiR8_R1F?usp=sharing"),m(Le,"rel","nofollow"),m(le,"id","diffusers.StableDiffusionPix2PixZeroPipeline"),m(le,"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"),m(le,"href","#diffusers.StableDiffusionPix2PixZeroPipeline"),m(A,"class","relative group"),m(Zt,"href","/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.DiffusionPipeline"),m(P,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(ie,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(re,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(pe,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),m(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,r){t(document.head,J),p(e,G,r),p(e,T,r),t(T,M),t(M,U),g(u,U,null),t(T,Z),t(T,Wt),t(Wt,Xa),p(e,Is,r),p(e,fe,r),t(fe,ge),t(ge,Pa),t(fe,Ra),p(e,xs,r),p(e,pt,r),t(pt,Va),p(e,Gs,r),p(e,ct,r),t(ct,kt),t(kt,Na),p(e,Bs,r),p(e,B,r),t(B,Ca),t(B,be),t(be,Sa),t(B,Ya),t(B,ye),t(ye,Fa),t(B,$a),t(B,we),t(we,za),t(B,Da),p(e,Es,r),p(e,N,r),t(N,q),t(q,Xt),g(Me,Xt,null),t(N,Qa),t(N,Pt),t(Pt,Ha),p(e,Ws,r),p(e,j,r),t(j,Rt),t(Rt,Aa),t(j,qa),t(j,x),t(x,La),t(x,Vt),t(Vt,Ka),t(x,Oa),t(x,Nt),t(Nt,en),t(x,tn),t(x,Ct),t(Ct,sn),t(x,an),t(x,St),t(St,nn),t(x,ln),t(j,on),t(j,C),t(C,rn),t(C,Yt),t(Yt,pn),t(C,cn),t(C,Ft),t(Ft,dn),t(C,mn),t(j,un),t(j,dt),t(dt,hn),t(dt,Je),t(Je,S),t(S,fn),t(S,$t),t($t,gn),t(S,bn),t(S,zt),t(zt,yn),t(S,wn),t(Je,Mn),t(Je,Dt),t(Dt,Jn),t(j,_n),t(j,_e),t(_e,Tn),t(_e,Te),t(Te,Zn),t(_e,jn),t(j,vn),t(j,k),t(k,Un),t(k,Qt),t(Qt,In),t(k,xn),t(k,Ht),t(Ht,Gn),t(k,Bn),t(k,mt),t(mt,En),t(k,Wn),p(e,ks,r),p(e,Y,r),t(Y,L),t(L,At),g(Ze,At,null),t(Y,kn),t(Y,qt),t(qt,Xn),p(e,Xs,r),p(e,K,r),t(K,Lt),t(Lt,F),t(F,Kt),t(Kt,Pn),t(F,Rn),t(F,Ot),t(Ot,Vn),t(F,Nn),t(F,ut),t(ut,Cn),t(K,Sn),t(K,es),t(es,$),t($,ts),t(ts,je),t(je,Yn),t($,Fn),t($,ss),t(ss,as),t(as,$n),t($,zn),t($,ht),t(ht,ve),t(ve,Dn),p(e,Ps,r),p(e,z,r),t(z,O),t(O,ns),g(Ue,ns,null),t(z,Qn),t(z,ls),t(ls,Hn),p(e,Rs,r),p(e,D,r),t(D,ee),t(ee,os),g(Ie,os,null),t(D,An),t(D,is),t(is,qn),p(e,Vs,r),g(xe,e,r),p(e,Ns,r),p(e,Q,r),t(Q,te),t(te,rs),g(Ge,rs,null),t(Q,Ln),t(Q,ps),t(ps,Kn),p(e,Cs,r),p(e,se,r),t(se,On),t(se,cs),t(cs,el),t(se,tl),p(e,Ss,r),p(e,ft,r),t(ft,sl),p(e,Ys,r),g(Be,e,r),p(e,Fs,r),p(e,gt,r),t(gt,al),p(e,$s,r),g(Ee,e,r),p(e,zs,r),p(e,bt,r),t(bt,nl),p(e,Ds,r),g(We,e,r),p(e,Qs,r),p(e,yt,r),t(yt,ll),p(e,Hs,r),g(ke,e,r),p(e,As,r),p(e,H,r),t(H,ae),t(ae,ds),g(Xe,ds,null),t(H,ol),t(H,ms),t(ms,il),p(e,qs,r),p(e,E,r),t(E,rl),t(E,Pe),t(Pe,pl),t(E,cl),t(E,Re),t(Re,dl),t(E,ml),t(E,Ve),t(Ve,ul),t(E,hl),p(e,Ls,r),p(e,Ne,r),t(Ne,us),t(us,fl),t(Ne,gl),p(e,Ks,r),g(Ce,e,r),p(e,Os,r),p(e,Se,r),t(Se,hs),t(hs,bl),t(Se,yl),p(e,ea,r),g(Ye,e,r),p(e,ta,r),p(e,wt,r),t(wt,wl),p(e,sa,r),p(e,Fe,r),t(Fe,fs),t(fs,Ml),t(Fe,Jl),p(e,aa,r),p(e,Mt,r),t(Mt,_l),p(e,na,r),g($e,e,r),p(e,la,r),p(e,Jt,r),t(Jt,Tl),p(e,oa,r),g(ze,e,r),p(e,ia,r),p(e,X,r),t(X,Zl),t(X,gs),t(gs,jl),t(X,vl),t(X,De),t(De,Ul),t(X,Il),p(e,ra,r),p(e,Qe,r),t(Qe,bs),t(bs,xl),t(Qe,Gl),p(e,pa,r),p(e,_t,r),t(_t,Bl),p(e,ca,r),g(He,e,r),p(e,da,r),p(e,Ae,r),t(Ae,ys),t(ys,El),t(Ae,Wl),p(e,ma,r),g(qe,e,r),p(e,ua,r),p(e,ne,r),t(ne,kl),t(ne,Le),t(Le,Xl),t(ne,Pl),p(e,ha,r),p(e,Tt,r),t(Tt,Rl),p(e,fa,r),g(Ke,e,r),p(e,ga,r),p(e,A,r),t(A,le),t(le,ws),g(Oe,ws,null),t(A,Vl),t(A,Ms),t(Ms,Nl),p(e,ba,r),p(e,_,r),g(et,_,null),t(_,Cl),t(_,Js),t(Js,Sl),t(_,Yl),t(_,tt),t(tt,Fl),t(tt,Zt),t(Zt,$l),t(tt,zl),t(_,Dl),t(_,P),g(st,P,null),t(P,Ql),t(P,_s),t(_s,Hl),t(P,Al),g(oe,P,null),t(_,ql),t(_,ie),g(at,ie,null),t(ie,Ll),t(ie,Ts),t(Ts,Kl),t(_,Ol),t(_,re),g(nt,re,null),t(re,eo),t(re,Zs),t(Zs,to),t(_,so),t(_,pe),g(lt,pe,null),t(pe,ao),t(pe,js),t(js,no),t(_,lo),t(_,R),g(ot,R,null),t(R,oo),t(R,vs),t(vs,io),t(R,ro),g(ce,R,null),ya=!0},p(e,[r]){const it={};r&2&&(it.$$scope={dirty:r,ctx:e}),oe.$set(it);const Us={};r&2&&(Us.$$scope={dirty:r,ctx:e}),ce.$set(Us)},i(e){ya||(b(u.$$.fragment,e),b(Me.$$.fragment,e),b(Ze.$$.fragment,e),b(Ue.$$.fragment,e),b(Ie.$$.fragment,e),b(xe.$$.fragment,e),b(Ge.$$.fragment,e),b(Be.$$.fragment,e),b(Ee.$$.fragment,e),b(We.$$.fragment,e),b(ke.$$.fragment,e),b(Xe.$$.fragment,e),b(Ce.$$.fragment,e),b(Ye.$$.fragment,e),b($e.$$.fragment,e),b(ze.$$.fragment,e),b(He.$$.fragment,e),b(qe.$$.fragment,e),b(Ke.$$.fragment,e),b(Oe.$$.fragment,e),b(et.$$.fragment,e),b(st.$$.fragment,e),b(oe.$$.fragment,e),b(at.$$.fragment,e),b(nt.$$.fragment,e),b(lt.$$.fragment,e),b(ot.$$.fragment,e),b(ce.$$.fragment,e),ya=!0)},o(e){y(u.$$.fragment,e),y(Me.$$.fragment,e),y(Ze.$$.fragment,e),y(Ue.$$.fragment,e),y(Ie.$$.fragment,e),y(xe.$$.fragment,e),y(Ge.$$.fragment,e),y(Be.$$.fragment,e),y(Ee.$$.fragment,e),y(We.$$.fragment,e),y(ke.$$.fragment,e),y(Xe.$$.fragment,e),y(Ce.$$.fragment,e),y(Ye.$$.fragment,e),y($e.$$.fragment,e),y(ze.$$.fragment,e),y(He.$$.fragment,e),y(qe.$$.fragment,e),y(Ke.$$.fragment,e),y(Oe.$$.fragment,e),y(et.$$.fragment,e),y(st.$$.fragment,e),y(oe.$$.fragment,e),y(at.$$.fragment,e),y(nt.$$.fragment,e),y(lt.$$.fragment,e),y(ot.$$.fragment,e),y(ce.$$.fragment,e),ya=!1},d(e){s(J),e&&s(G),e&&s(T),w(u),e&&s(Is),e&&s(fe),e&&s(xs),e&&s(pt),e&&s(Gs),e&&s(ct),e&&s(Bs),e&&s(B),e&&s(Es),e&&s(N),w(Me),e&&s(Ws),e&&s(j),e&&s(ks),e&&s(Y),w(Ze),e&&s(Xs),e&&s(K),e&&s(Ps),e&&s(z),w(Ue),e&&s(Rs),e&&s(D),w(Ie),e&&s(Vs),w(xe,e),e&&s(Ns),e&&s(Q),w(Ge),e&&s(Cs),e&&s(se),e&&s(Ss),e&&s(ft),e&&s(Ys),w(Be,e),e&&s(Fs),e&&s(gt),e&&s($s),w(Ee,e),e&&s(zs),e&&s(bt),e&&s(Ds),w(We,e),e&&s(Qs),e&&s(yt),e&&s(Hs),w(ke,e),e&&s(As),e&&s(H),w(Xe),e&&s(qs),e&&s(E),e&&s(Ls),e&&s(Ne),e&&s(Ks),w(Ce,e),e&&s(Os),e&&s(Se),e&&s(ea),w(Ye,e),e&&s(ta),e&&s(wt),e&&s(sa),e&&s(Fe),e&&s(aa),e&&s(Mt),e&&s(na),w($e,e),e&&s(la),e&&s(Jt),e&&s(oa),w(ze,e),e&&s(ia),e&&s(X),e&&s(ra),e&&s(Qe),e&&s(pa),e&&s(_t),e&&s(ca),w(He,e),e&&s(da),e&&s(Ae),e&&s(ma),w(qe,e),e&&s(ua),e&&s(ne),e&&s(ha),e&&s(Tt),e&&s(fa),w(Ke,e),e&&s(ga),e&&s(A),w(Oe),e&&s(ba),e&&s(_),w(et),w(st),w(oe),w(at),w(nt),w(lt),w(ot),w(ce)}}}const sr={local:"pix2pix-zero",sections:[{local:"tips",title:"Tips "},{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-example",sections:[{local:"based-on-an-image-generated-with-the-input-prompt",title:"Based on an image generated with the input prompt"},{local:"based-on-an-input-image",title:"Based on an input image"}],title:"Usage example"},{local:"generating-source-and-target-embeddings",title:"Generating source and target embeddings "},{local:"diffusers.StableDiffusionPix2PixZeroPipeline",title:"StableDiffusionPix2PixZeroPipeline"}],title:"Pix2Pix Zero"};function ar(rt){return Ki(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pr extends Hi{constructor(J){super();Ai(this,J,ar,tr,qi,{})}}export{pr as default,sr as metadata};
