import{S as $t,i as Wt,s as Gt,e as i,k as p,w as A,t as f,M as jt,c as n,d as t,m,a as l,x as K,h as u,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 Rt}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function Ct(ue){let c,_;return{c(){c=i("p"),_=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){c=n(d,"P",{});var h=l(c);_=u(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,c,h),a(c,_)},d(d){d&&t(c)}}}function Dt(ue){let c,_,d,h,ae,k,Ze,ie,$e,ce,E,de,y,We,x,Ge,je,I,ne,Be,Se,he,J,xe,R,Re,Ce,ge,Z,be,C,De,ye,$,we,D,Ne,_e,W,Je,v,le,g,N,se,Xe,Ve,X,oe,Fe,Qe,V,re,He,Ye,F,Pe,qe,pe,b,Q,G,tt,ze,H,j,at,Ae,Y,me,fe,Ke,Le,P,B,it,ve,M,Me,q,Oe,Te,w,nt,Ue;return k=new xt({}),E=new Rt({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:"aW1wb3J0JTIwUElMJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBpbyUyMGltcG9ydCUyMEJ5dGVzSU8lMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uSW5wYWludFBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25JbnBhaW50UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi1pbnBhaW50aW5nJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBJTIwJTIwJTIwJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSUyQyUwQSklMEFwaXBlbGluZSUyMCUzRCUyMHBpcGVsaW5lLnRvKCUyMmN1ZGElMjIp",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>,
)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)`}}),$=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>))`}}),W=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:ue}}}),{c(){c=i("meta"),_=p(),d=i("h1"),h=i("a"),ae=i("span"),A(k.$$.fragment),Ze=p(),ie=i("span"),$e=f("Text-guided image-inpainting"),ce=p(),A(E.$$.fragment),de=p(),y=i("p"),We=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(),J=i("p"),xe=f("Get started by loading an instance of the "),R=i("a"),Re=f("StableDiffusionInpaintPipeline"),Ce=f(":"),ge=p(),A(Z.$$.fragment),be=p(),C=i("p"),De=f("Download an image and a mask of a dog which you\u2019ll eventually replace:"),ye=p(),A($.$$.fragment),we=p(),D=i("p"),Ne=f("Now you can create a prompt to replace the mask with something else:"),_e=p(),A(W.$$.fragment),Je=p(),v=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"),Fe=f("mask_image"),Qe=p(),V=i("th"),re=i("code"),He=f("prompt"),Ye=p(),F=i("th"),Pe=f("output"),qe=p(),pe=i("tbody"),b=i("tr"),Q=i("td"),G=i("img"),ze=p(),H=i("td"),j=i("img"),Ae=p(),Y=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"),ve=p(),A(M.$$.fragment),Me=p(),q=i("p"),Oe=f("Check out the Spaces below to try out image inpainting yourself!"),Te=p(),w=i("iframe"),this.h()},l(e){const s=jt('[data-svelte="svelte-1phssyn"]',document.head);c=n(s,"META",{name:!0,content:!0}),s.forEach(t),_=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);$e=u(ot,"Text-guided image-inpainting"),ot.forEach(t),S.forEach(t),ce=m(e),K(E.$$.fragment,e),de=m(e),y=n(e,"P",{});var z=l(y);We=u(z,"The "),x=n(z,"A",{href:!0});var rt=l(x);Ge=u(rt,"StableDiffusionInpaintPipeline"),rt.forEach(t),je=u(z," 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(z,"A",{href:!0,rel:!0});var pt=l(I);ne=n(pt,"CODE",{});var mt=l(ne);Be=u(mt,"runwayml/stable-diffusion-inpainting"),mt.forEach(t),pt.forEach(t),Se=u(z," specifically trained for inpainting tasks."),z.forEach(t),he=m(e),J=n(e,"P",{});var ke=l(J);xe=u(ke,"Get started by loading an instance of the "),R=n(ke,"A",{href:!0});var ft=l(R);Re=u(ft,"StableDiffusionInpaintPipeline"),ft.forEach(t),Ce=u(ke,":"),ke.forEach(t),ge=m(e),K(Z.$$.fragment,e),be=m(e),C=n(e,"P",{});var ut=l(C);De=u(ut,"Download an image and a mask of a dog which you\u2019ll eventually replace:"),ut.forEach(t),ye=m(e),K($.$$.fragment,e),we=m(e),D=n(e,"P",{});var ct=l(D);Ne=u(ct,"Now you can create a prompt to replace the mask with something else:"),ct.forEach(t),_e=m(e),K(W.$$.fragment,e),Je=m(e),v=n(e,"TABLE",{});var Ee=l(v);le=n(Ee,"THEAD",{});var dt=l(le);g=n(dt,"TR",{});var T=l(g);N=n(T,"TH",{align:!0});var ht=l(N);se=n(ht,"CODE",{});var gt=l(se);Xe=u(gt,"image"),gt.forEach(t),ht.forEach(t),Ve=m(T),X=n(T,"TH",{align:!0});var bt=l(X);oe=n(bt,"CODE",{});var yt=l(oe);Fe=u(yt,"mask_image"),yt.forEach(t),bt.forEach(t),Qe=m(T),V=n(T,"TH",{align:!0});var wt=l(V);re=n(wt,"CODE",{});var _t=l(re);He=u(_t,"prompt"),_t.forEach(t),wt.forEach(t),Ye=m(T),F=n(T,"TH",{align:!0});var Jt=l(F);Pe=u(Jt,"output"),Jt.forEach(t),T.forEach(t),dt.forEach(t),qe=m(Ee),pe=n(Ee,"TBODY",{});var vt=l(pe);b=n(vt,"TR",{});var U=l(b);Q=n(U,"TD",{align:!0});var Mt=l(Q);G=n(Mt,"IMG",{src:!0,alt:!0,width:!0}),Mt.forEach(t),ze=m(U),H=n(U,"TD",{align:!0});var Tt=l(H);j=n(Tt,"IMG",{src:!0,alt:!0,width:!0}),Tt.forEach(t),Ae=m(U),Y=n(U,"TD",{align:!0});var Ut=l(Y);me=n(Ut,"STRONG",{});var kt=l(me);fe=n(kt,"EM",{});var Et=l(fe);Ke=u(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),vt.forEach(t),Ee.forEach(t),ve=m(e),K(M.$$.fragment,e),Me=m(e),q=n(e,"P",{});var Zt=l(q);Oe=u(Zt,"Check out the Spaces below to try out image inpainting yourself!"),Zt.forEach(t),Te=m(e),w=n(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),l(w).forEach(t),this.h()},h(){o(c,"name","hf:doc:metadata"),o(c,"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/v0.20.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline"),o(I,"href","https://huggingface.co/runwayml/stable-diffusion-inpainting"),o(I,"rel","nofollow"),o(R,"href","/docs/diffusers/v0.20.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline"),o(N,"align","center"),o(X,"align","center"),o(V,"align","center"),o(F,"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(Q,"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(H,"align","center"),o(Y,"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,c),r(e,_,s),r(e,d,s),a(d,h),a(h,ae),L(k,ae,null),a(d,Ze),a(d,ie),a(ie,$e),r(e,ce,s),L(E,e,s),r(e,de,s),r(e,y,s),a(y,We),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,J,s),a(J,xe),a(J,R),a(R,Re),a(J,Ce),r(e,ge,s),L(Z,e,s),r(e,be,s),r(e,C,s),a(C,De),r(e,ye,s),L($,e,s),r(e,we,s),r(e,D,s),a(D,Ne),r(e,_e,s),L(W,e,s),r(e,Je,s),r(e,v,s),a(v,le),a(le,g),a(g,N),a(N,se),a(se,Xe),a(g,Ve),a(g,X),a(X,oe),a(oe,Fe),a(g,Qe),a(g,V),a(V,re),a(re,He),a(g,Ye),a(g,F),a(F,Pe),a(v,qe),a(v,pe),a(pe,b),a(b,Q),a(Q,G),a(b,ze),a(b,H),a(H,j),a(b,Ae),a(b,Y),a(Y,me),a(me,fe),a(fe,Ke),a(b,Le),a(b,P),a(P,B),r(e,ve,s),L(M,e,s),r(e,Me,s),r(e,q,s),a(q,Oe),r(e,Te,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($.$$.fragment,e),O(W.$$.fragment,e),O(M.$$.fragment,e),Ue=!0)},o(e){ee(k.$$.fragment,e),ee(E.$$.fragment,e),ee(Z.$$.fragment,e),ee($.$$.fragment,e),ee(W.$$.fragment,e),ee(M.$$.fragment,e),Ue=!1},d(e){t(c),e&&t(_),e&&t(d),te(k),e&&t(ce),te(E,e),e&&t(de),e&&t(y),e&&t(he),e&&t(J),e&&t(ge),te(Z,e),e&&t(be),e&&t(C),e&&t(ye),te($,e),e&&t(we),e&&t(D),e&&t(_e),te(W,e),e&&t(Je),e&&t(v),e&&t(ve),te(M,e),e&&t(Me),e&&t(q),e&&t(Te),e&&t(w)}}}const Nt={local:"textguided-imageinpainting",title:"Text-guided image-inpainting"};function Xt(ue){return Bt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pt extends $t{constructor(c){super();Wt(this,c,Xt,Dt,Gt,{})}}export{Pt as default,Nt as metadata};
