import{S as jt,i as qt,s as St,e as i,k as p,w as K,t as m,M as Ct,c as n,d as t,m as f,a as s,x as W,h as u,b as r,N as Pe,G as a,g as l,y as X,q as Z,o as ee,B as te,v as At}from"../../chunks/vendor-hf-doc-builder.js";import{T as Ot}from"../../chunks/Tip-hf-doc-builder.js";import{I as Bt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as et}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Mt}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function Gt(ue){let c,v;return{c(){c=i("p"),v=m("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 g=s(c);v=u(g,"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."),g.forEach(t)},m(d,g){l(d,c,g),a(c,v)},d(d){d&&t(c)}}}function Nt(ue){let c,v,d,g,ae,T,xe,ie,je,ce,D,de,b,qe,B,Se,Ce,P,ne,Ae,Oe,ge,y,Be,M,Me,Ge,he,x,_e,G,Ne,be,j,we,N,Fe,ve,q,ye,k,se,h,F,oe,Le,Re,L,re,Ye,He,R,le,Qe,Ve,Y,ze,Je,pe,_,H,S,tt,Ue,Q,C,at,Ke,V,fe,me,We,Xe,z,A,it,ke,$,$e,J,Ze,Ee,w,nt,Ie;return T=new Bt({}),D=new Mt({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"}]}}),x=new et({props:{code:`import PIL
import requests
import torch
from io import BytesIO

from diffusers import StableDiffusionInpaintPipeline

pipeline = StableDiffusionInpaintPipeline.from_pretrained(
    "runwayml/stable-diffusion-inpainting",
    torch_dtype=torch.float16,
)
pipeline = pipeline.to("cuda")`,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>)`}}),j=new et({props:{code:`def download_image(url):
    response = requests.get(url)
    return PIL.Image.open(BytesIO(response.content)).convert("RGB")


img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"

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