import{S as Wt,i as $t,s as Gt,e as i,k as p,w as z,t as f,M as jt,c as n,d as t,m,a as l,x as K,h as c,b as o,N as Ie,G as a,g as r,y as L,q as O,o as ee,B as te,v as Bt}from"../../chunks/vendor-hf-doc-builder.js";import{T as St}from"../../chunks/Tip-hf-doc-builder.js";import{I as xt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as et}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Dt}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function Ct(ce){let u,J;return{c(){u=i("p"),J=f("A previous experimental implementation of inpainting used a different, lower-quality process. To ensure backwards compatibility, loading a pretrained pipeline that doesn\u2019t contain the new model will still apply the old inpainting method.")},l(d){u=n(d,"P",{});var h=l(u);J=c(h,"A previous experimental implementation of inpainting used a different, lower-quality process. To ensure backwards compatibility, loading a pretrained pipeline that doesn\u2019t contain the new model will still apply the old inpainting method."),h.forEach(t)},m(d,h){r(d,u,h),a(u,J)},d(d){d&&t(u)}}}function Rt(ce){let u,J,d,h,ae,k,Ze,ie,We,ue,E,de,y,$e,x,Ge,je,I,ne,Be,Se,he,_,xe,D,De,Ce,ge,Z,be,C,Re,ye,W,we,R,Ne,Je,$,_e,T,le,g,N,se,Xe,Ve,X,oe,Qe,Fe,V,re,Ye,He,Q,Pe,qe,pe,b,F,G,tt,Ae,Y,j,at,ze,H,me,fe,Ke,Le,P,B,it,Te,M,Me,q,Oe,ve,w,nt,Ue;return k=new xt({}),E=new Dt({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/inpaint.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/inpaint.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/inpaint.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/inpaint.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/inpaint.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/inpaint.ipynb"}]}}),Z=new et({props:{code:"aW1wb3J0JTIwUElMJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBpbyUyMGltcG9ydCUyMEJ5dGVzSU8lMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uSW5wYWludFBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25JbnBhaW50UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi1pbnBhaW50aW5nJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBJTIwJTIwJTIwJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMHZhcmlhbnQlM0QlMjJmcDE2JTIyJTJDJTBBKSUwQXBpcGVsaW5lJTIwJTNEJTIwcGlwZWxpbmUudG8oJTIyY3VkYSUyMik=",highlighted:`<span class="hljs-keyword">import</span> PIL
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> torch
<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> StableDiffusionInpaintPipeline

pipeline = StableDiffusionInpaintPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-inpainting&quot;</span>,
    torch_dtype=torch.float16,
    use_safetensors=<span class="hljs-literal">True</span>,
    variant=<span class="hljs-string">&quot;fp16&quot;</span>,
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)`}}),W=new et({props:{code:"ZGVmJTIwZG93bmxvYWRfaW1hZ2UodXJsKSUzQSUwQSUyMCUyMCUyMCUyMHJlc3BvbnNlJTIwJTNEJTIwcmVxdWVzdHMuZ2V0KHVybCklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBQSUwuSW1hZ2Uub3BlbihCeXRlc0lPKHJlc3BvbnNlLmNvbnRlbnQpKS5jb252ZXJ0KCUyMlJHQiUyMiklMEElMEElMEFpbWdfdXJsJTIwJTNEJTIwJTIyaHR0cHMlM0ElMkYlMkZyYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tJTJGQ29tcFZpcyUyRmxhdGVudC1kaWZmdXNpb24lMkZtYWluJTJGZGF0YSUyRmlucGFpbnRpbmdfZXhhbXBsZXMlMkZvdmVydHVyZS1jcmVhdGlvbnMtNXNJNmZRZ1lJdW8ucG5nJTIyJTBBbWFza191cmwlMjAlM0QlMjAlMjJodHRwcyUzQSUyRiUyRnJhdy5naXRodWJ1c2VyY29udGVudC5jb20lMkZDb21wVmlzJTJGbGF0ZW50LWRpZmZ1c2lvbiUyRm1haW4lMkZkYXRhJTJGaW5wYWludGluZ19leGFtcGxlcyUyRm92ZXJ0dXJlLWNyZWF0aW9ucy01c0k2ZlFnWUl1b19tYXNrLnBuZyUyMiUwQSUwQWluaXRfaW1hZ2UlMjAlM0QlMjBkb3dubG9hZF9pbWFnZShpbWdfdXJsKS5yZXNpemUoKDUxMiUyQyUyMDUxMikpJTBBbWFza19pbWFnZSUyMCUzRCUyMGRvd25sb2FkX2ltYWdlKG1hc2tfdXJsKS5yZXNpemUoKDUxMiUyQyUyMDUxMikp",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">download_image</span>(<span class="hljs-params">url</span>):
    response = requests.get(url)
    <span class="hljs-keyword">return</span> PIL.Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)


img_url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png&quot;</span>
mask_url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png&quot;</span>

init_image = download_image(img_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
mask_image = download_image(mask_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))`}}),$=new et({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyRmFjZSUyMG9mJTIwYSUyMHllbGxvdyUyMGNhdCUyQyUyMGhpZ2glMjByZXNvbHV0aW9uJTJDJTIwc2l0dGluZyUyMG9uJTIwYSUyMHBhcmslMjBiZW5jaCUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0JTNEcHJvbXB0JTJDJTIwaW1hZ2UlM0Rpbml0X2ltYWdlJTJDJTIwbWFza19pbWFnZSUzRG1hc2tfaW1hZ2UpLmltYWdlcyU1QjAlNUQ=",highlighted:`prompt = <span class="hljs-string">&quot;Face of a yellow cat, high resolution, sitting on a park bench&quot;</span>
image = pipeline(prompt=prompt, image=init_image, mask_image=mask_image).images[<span class="hljs-number">0</span>]`}}),M=new St({props:{warning:!0,$$slots:{default:[Ct]},$$scope:{ctx:ce}}}),{c(){u=i("meta"),J=p(),d=i("h1"),h=i("a"),ae=i("span"),z(k.$$.fragment),Ze=p(),ie=i("span"),We=f("Text-guided image-inpainting"),ue=p(),z(E.$$.fragment),de=p(),y=i("p"),$e=f("The "),x=i("a"),Ge=f("StableDiffusionInpaintPipeline"),je=f(" allows you to edit specific parts of an image by providing a mask and a text prompt. It uses a version of Stable Diffusion, like "),I=i("a"),ne=i("code"),Be=f("runwayml/stable-diffusion-inpainting"),Se=f(" specifically trained for inpainting tasks."),he=p(),_=i("p"),xe=f("Get started by loading an instance of the "),D=i("a"),De=f("StableDiffusionInpaintPipeline"),Ce=f(":"),ge=p(),z(Z.$$.fragment),be=p(),C=i("p"),Re=f("Download an image and a mask of a dog which you\u2019ll eventually replace:"),ye=p(),z(W.$$.fragment),we=p(),R=i("p"),Ne=f("Now you can create a prompt to replace the mask with something else:"),Je=p(),z($.$$.fragment),_e=p(),T=i("table"),le=i("thead"),g=i("tr"),N=i("th"),se=i("code"),Xe=f("image"),Ve=p(),X=i("th"),oe=i("code"),Qe=f("mask_image"),Fe=p(),V=i("th"),re=i("code"),Ye=f("prompt"),He=p(),Q=i("th"),Pe=f("output"),qe=p(),pe=i("tbody"),b=i("tr"),F=i("td"),G=i("img"),Ae=p(),Y=i("td"),j=i("img"),ze=p(),H=i("td"),me=i("strong"),fe=i("em"),Ke=f("Face of a yellow cat, high resolution, sitting on a park bench"),Le=p(),P=i("td"),B=i("img"),Te=p(),z(M.$$.fragment),Me=p(),q=i("p"),Oe=f("Check out the Spaces below to try out image inpainting yourself!"),ve=p(),w=i("iframe"),this.h()},l(e){const s=jt('[data-svelte="svelte-1phssyn"]',document.head);u=n(s,"META",{name:!0,content:!0}),s.forEach(t),J=m(e),d=n(e,"H1",{class:!0});var S=l(d);h=n(S,"A",{id:!0,class:!0,href:!0});var lt=l(h);ae=n(lt,"SPAN",{});var st=l(ae);K(k.$$.fragment,st),st.forEach(t),lt.forEach(t),Ze=m(S),ie=n(S,"SPAN",{});var ot=l(ie);We=c(ot,"Text-guided image-inpainting"),ot.forEach(t),S.forEach(t),ue=m(e),K(E.$$.fragment,e),de=m(e),y=n(e,"P",{});var A=l(y);$e=c(A,"The "),x=n(A,"A",{href:!0});var rt=l(x);Ge=c(rt,"StableDiffusionInpaintPipeline"),rt.forEach(t),je=c(A," allows you to edit specific parts of an image by providing a mask and a text prompt. It uses a version of Stable Diffusion, like "),I=n(A,"A",{href:!0,rel:!0});var pt=l(I);ne=n(pt,"CODE",{});var mt=l(ne);Be=c(mt,"runwayml/stable-diffusion-inpainting"),mt.forEach(t),pt.forEach(t),Se=c(A," specifically trained for inpainting tasks."),A.forEach(t),he=m(e),_=n(e,"P",{});var ke=l(_);xe=c(ke,"Get started by loading an instance of the "),D=n(ke,"A",{href:!0});var ft=l(D);De=c(ft,"StableDiffusionInpaintPipeline"),ft.forEach(t),Ce=c(ke,":"),ke.forEach(t),ge=m(e),K(Z.$$.fragment,e),be=m(e),C=n(e,"P",{});var ct=l(C);Re=c(ct,"Download an image and a mask of a dog which you\u2019ll eventually replace:"),ct.forEach(t),ye=m(e),K(W.$$.fragment,e),we=m(e),R=n(e,"P",{});var ut=l(R);Ne=c(ut,"Now you can create a prompt to replace the mask with something else:"),ut.forEach(t),Je=m(e),K($.$$.fragment,e),_e=m(e),T=n(e,"TABLE",{});var Ee=l(T);le=n(Ee,"THEAD",{});var dt=l(le);g=n(dt,"TR",{});var v=l(g);N=n(v,"TH",{align:!0});var ht=l(N);se=n(ht,"CODE",{});var gt=l(se);Xe=c(gt,"image"),gt.forEach(t),ht.forEach(t),Ve=m(v),X=n(v,"TH",{align:!0});var bt=l(X);oe=n(bt,"CODE",{});var yt=l(oe);Qe=c(yt,"mask_image"),yt.forEach(t),bt.forEach(t),Fe=m(v),V=n(v,"TH",{align:!0});var wt=l(V);re=n(wt,"CODE",{});var Jt=l(re);Ye=c(Jt,"prompt"),Jt.forEach(t),wt.forEach(t),He=m(v),Q=n(v,"TH",{align:!0});var _t=l(Q);Pe=c(_t,"output"),_t.forEach(t),v.forEach(t),dt.forEach(t),qe=m(Ee),pe=n(Ee,"TBODY",{});var Tt=l(pe);b=n(Tt,"TR",{});var U=l(b);F=n(U,"TD",{align:!0});var Mt=l(F);G=n(Mt,"IMG",{src:!0,alt:!0,width:!0}),Mt.forEach(t),Ae=m(U),Y=n(U,"TD",{align:!0});var vt=l(Y);j=n(vt,"IMG",{src:!0,alt:!0,width:!0}),vt.forEach(t),ze=m(U),H=n(U,"TD",{align:!0});var Ut=l(H);me=n(Ut,"STRONG",{});var kt=l(me);fe=n(kt,"EM",{});var Et=l(fe);Ke=c(Et,"Face of a yellow cat, high resolution, sitting on a park bench"),Et.forEach(t),kt.forEach(t),Ut.forEach(t),Le=m(U),P=n(U,"TD",{align:!0});var It=l(P);B=n(It,"IMG",{src:!0,alt:!0,width:!0}),It.forEach(t),U.forEach(t),Tt.forEach(t),Ee.forEach(t),Te=m(e),K(M.$$.fragment,e),Me=m(e),q=n(e,"P",{});var Zt=l(q);Oe=c(Zt,"Check out the Spaces below to try out image inpainting yourself!"),Zt.forEach(t),ve=m(e),w=n(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),l(w).forEach(t),this.h()},h(){o(u,"name","hf:doc:metadata"),o(u,"content",JSON.stringify(Nt)),o(h,"id","textguided-imageinpainting"),o(h,"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"),o(h,"href","#textguided-imageinpainting"),o(d,"class","relative group"),o(x,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline"),o(I,"href","https://huggingface.co/runwayml/stable-diffusion-inpainting"),o(I,"rel","nofollow"),o(D,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline"),o(N,"align","center"),o(X,"align","center"),o(V,"align","center"),o(Q,"align","right"),Ie(G.src,tt="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png")||o(G,"src",tt),o(G,"alt","drawing"),o(G,"width","250"),o(F,"align","center"),Ie(j.src,at="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png")||o(j,"src",at),o(j,"alt","drawing"),o(j,"width","250"),o(Y,"align","center"),o(H,"align","center"),Ie(B.src,it="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/in_paint/yellow_cat_sitting_on_a_park_bench.png")||o(B,"src",it),o(B,"alt","drawing"),o(B,"width","250"),o(P,"align","right"),Ie(w.src,nt="https://runwayml-stable-diffusion-inpainting.hf.space")||o(w,"src",nt),o(w,"frameborder","0"),o(w,"width","850"),o(w,"height","500")},m(e,s){a(document.head,u),r(e,J,s),r(e,d,s),a(d,h),a(h,ae),L(k,ae,null),a(d,Ze),a(d,ie),a(ie,We),r(e,ue,s),L(E,e,s),r(e,de,s),r(e,y,s),a(y,$e),a(y,x),a(x,Ge),a(y,je),a(y,I),a(I,ne),a(ne,Be),a(y,Se),r(e,he,s),r(e,_,s),a(_,xe),a(_,D),a(D,De),a(_,Ce),r(e,ge,s),L(Z,e,s),r(e,be,s),r(e,C,s),a(C,Re),r(e,ye,s),L(W,e,s),r(e,we,s),r(e,R,s),a(R,Ne),r(e,Je,s),L($,e,s),r(e,_e,s),r(e,T,s),a(T,le),a(le,g),a(g,N),a(N,se),a(se,Xe),a(g,Ve),a(g,X),a(X,oe),a(oe,Qe),a(g,Fe),a(g,V),a(V,re),a(re,Ye),a(g,He),a(g,Q),a(Q,Pe),a(T,qe),a(T,pe),a(pe,b),a(b,F),a(F,G),a(b,Ae),a(b,Y),a(Y,j),a(b,ze),a(b,H),a(H,me),a(me,fe),a(fe,Ke),a(b,Le),a(b,P),a(P,B),r(e,Te,s),L(M,e,s),r(e,Me,s),r(e,q,s),a(q,Oe),r(e,ve,s),r(e,w,s),Ue=!0},p(e,[s]){const S={};s&2&&(S.$$scope={dirty:s,ctx:e}),M.$set(S)},i(e){Ue||(O(k.$$.fragment,e),O(E.$$.fragment,e),O(Z.$$.fragment,e),O(W.$$.fragment,e),O($.$$.fragment,e),O(M.$$.fragment,e),Ue=!0)},o(e){ee(k.$$.fragment,e),ee(E.$$.fragment,e),ee(Z.$$.fragment,e),ee(W.$$.fragment,e),ee($.$$.fragment,e),ee(M.$$.fragment,e),Ue=!1},d(e){t(u),e&&t(J),e&&t(d),te(k),e&&t(ue),te(E,e),e&&t(de),e&&t(y),e&&t(he),e&&t(_),e&&t(ge),te(Z,e),e&&t(be),e&&t(C),e&&t(ye),te(W,e),e&&t(we),e&&t(R),e&&t(Je),te($,e),e&&t(_e),e&&t(T),e&&t(Te),te(M,e),e&&t(Me),e&&t(q),e&&t(ve),e&&t(w)}}}const Nt={local:"textguided-imageinpainting",title:"Text-guided image-inpainting"};function Xt(ce){return Bt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pt extends Wt{constructor(u){super();$t(this,u,Xt,Rt,Gt,{})}}export{Pt as default,Nt as metadata};
