import{S as $t,i as Wt,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 Rt(ce){let u,_;return{c(){u=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){u=n(d,"P",{});var h=l(u);_=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,_)},d(d){d&&t(u)}}}function Ct(ce){let u,_,d,h,ae,U,Ze,ie,$e,ue,E,de,y,We,x,Ge,je,I,ne,Be,Se,he,J,xe,D,De,Re,ge,Z,be,R,Ce,ye,$,we,C,Ne,_e,W,Je,v,le,g,N,se,Xe,Ve,X,oe,Fe,Qe,V,re,Ye,He,F,Pe,qe,pe,b,Q,G,tt,Ae,Y,j,at,ze,H,me,fe,Ke,Le,P,B,it,ve,T,Te,q,Oe,Me,w,nt,ke;return U=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:"aW1wb3J0JTIwUElMJTBBaW1wb3J0JTIwcmVxdWVzdHMlMEFpbXBvcnQlMjB0b3JjaCUwQWZyb20lMjBpbyUyMGltcG9ydCUyMEJ5dGVzSU8lMEElMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uSW5wYWludFBpcGVsaW5lJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25JbnBhaW50UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi1pbnBhaW50aW5nJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTBBKSUwQXBpcGVsaW5lJTIwJTNEJTIwcGlwZWxpbmUudG8oJTIyY3VkYSUyMik=",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,
)
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>]`}}),T=new St({props:{warning:!0,$$slots:{default:[Rt]},$$scope:{ctx:ce}}}),{c(){u=i("meta"),_=p(),d=i("h1"),h=i("a"),ae=i("span"),z(U.$$.fragment),Ze=p(),ie=i("span"),$e=f("Text-guided image-inpainting"),ue=p(),z(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 "),D=i("a"),De=f("StableDiffusionInpaintPipeline"),Re=f(":"),ge=p(),z(Z.$$.fragment),be=p(),R=i("p"),Ce=f("Download an image and a mask of a dog which you\u2019ll eventually replace:"),ye=p(),z($.$$.fragment),we=p(),C=i("p"),Ne=f("Now you can create a prompt to replace the mask with something else:"),_e=p(),z(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"),Ye=f("prompt"),He=p(),F=i("th"),Pe=f("output"),qe=p(),pe=i("tbody"),b=i("tr"),Q=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"),ve=p(),z(T.$$.fragment),Te=p(),q=i("p"),Oe=f("Check out the Spaces below to try out image inpainting yourself!"),Me=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),_=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(U.$$.fragment,st),st.forEach(t),lt.forEach(t),Ze=m(S),ie=n(S,"SPAN",{});var ot=l(ie);$e=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);We=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),J=n(e,"P",{});var Ue=l(J);xe=c(Ue,"Get started by loading an instance of the "),D=n(Ue,"A",{href:!0});var ft=l(D);De=c(ft,"StableDiffusionInpaintPipeline"),ft.forEach(t),Re=c(Ue,":"),Ue.forEach(t),ge=m(e),K(Z.$$.fragment,e),be=m(e),R=n(e,"P",{});var ct=l(R);Ce=c(ct,"Download an image and a mask of a dog which you\u2019ll eventually replace:"),ct.forEach(t),ye=m(e),K($.$$.fragment,e),we=m(e),C=n(e,"P",{});var ut=l(C);Ne=c(ut,"Now you can create a prompt to replace the mask with something else:"),ut.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 M=l(g);N=n(M,"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(M),X=n(M,"TH",{align:!0});var bt=l(X);oe=n(bt,"CODE",{});var yt=l(oe);Fe=c(yt,"mask_image"),yt.forEach(t),bt.forEach(t),Qe=m(M),V=n(M,"TH",{align:!0});var wt=l(V);re=n(wt,"CODE",{});var _t=l(re);Ye=c(_t,"prompt"),_t.forEach(t),wt.forEach(t),He=m(M),F=n(M,"TH",{align:!0});var Jt=l(F);Pe=c(Jt,"output"),Jt.forEach(t),M.forEach(t),dt.forEach(t),qe=m(Ee),pe=n(Ee,"TBODY",{});var vt=l(pe);b=n(vt,"TR",{});var k=l(b);Q=n(k,"TD",{align:!0});var Tt=l(Q);G=n(Tt,"IMG",{src:!0,alt:!0,width:!0}),Tt.forEach(t),Ae=m(k),Y=n(k,"TD",{align:!0});var Mt=l(Y);j=n(Mt,"IMG",{src:!0,alt:!0,width:!0}),Mt.forEach(t),ze=m(k),H=n(k,"TD",{align:!0});var kt=l(H);me=n(kt,"STRONG",{});var Ut=l(me);fe=n(Ut,"EM",{});var Et=l(fe);Ke=c(Et,"Face of a yellow cat, high resolution, sitting on a park bench"),Et.forEach(t),Ut.forEach(t),kt.forEach(t),Le=m(k),P=n(k,"TD",{align:!0});var It=l(P);B=n(It,"IMG",{src:!0,alt:!0,width:!0}),It.forEach(t),k.forEach(t),vt.forEach(t),Ee.forEach(t),ve=m(e),K(T.$$.fragment,e),Te=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),Me=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/v0.19.2/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/v0.19.2/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(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,_,s),r(e,d,s),a(d,h),a(h,ae),L(U,ae,null),a(d,Ze),a(d,ie),a(ie,$e),r(e,ue,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,D),a(D,De),a(J,Re),r(e,ge,s),L(Z,e,s),r(e,be,s),r(e,R,s),a(R,Ce),r(e,ye,s),L($,e,s),r(e,we,s),r(e,C,s),a(C,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,Ye),a(g,He),a(g,F),a(F,Pe),a(v,qe),a(v,pe),a(pe,b),a(b,Q),a(Q,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,ve,s),L(T,e,s),r(e,Te,s),r(e,q,s),a(q,Oe),r(e,Me,s),r(e,w,s),ke=!0},p(e,[s]){const S={};s&2&&(S.$$scope={dirty:s,ctx:e}),T.$set(S)},i(e){ke||(O(U.$$.fragment,e),O(E.$$.fragment,e),O(Z.$$.fragment,e),O($.$$.fragment,e),O(W.$$.fragment,e),O(T.$$.fragment,e),ke=!0)},o(e){ee(U.$$.fragment,e),ee(E.$$.fragment,e),ee(Z.$$.fragment,e),ee($.$$.fragment,e),ee(W.$$.fragment,e),ee(T.$$.fragment,e),ke=!1},d(e){t(u),e&&t(_),e&&t(d),te(U),e&&t(ue),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(R),e&&t(ye),te($,e),e&&t(we),e&&t(C),e&&t(_e),te(W,e),e&&t(Je),e&&t(v),e&&t(ve),te(T,e),e&&t(Te),e&&t(q),e&&t(Me),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 $t{constructor(u){super();Wt(this,u,Xt,Ct,Gt,{})}}export{Pt as default,Nt as metadata};
