Buckets:
hf-doc-build/doc / diffusers /v0.13.0 /en /_app /pages /using-diffusers /inpaint.mdx-hf-doc-builder.js
| import{S as nt,i as it,s as rt,e as s,k as p,w as Te,t as d,M as ot,c as n,d as a,m,a as r,x as je,h as g,b as i,N as oe,G as t,g as h,y as qe,q as De,o as Pe,B as Se,v as lt}from"../../chunks/vendor-hf-doc-builder.js";import{T as pt}from"../../chunks/Tip-hf-doc-builder.js";import{I as mt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as ct}from"../../chunks/CodeBlock-hf-doc-builder.js";function ut(X){let l;return{c(){l=d("A previous experimental implementation of in-painting used a different, lower-quality process. To ensure backwards compatibility, loading a pretrained pipeline that doesn't contain the new model will still apply the old in-painting method.")},l(_){l=g(_,"A previous experimental implementation of in-painting used a different, lower-quality process. To ensure backwards compatibility, loading a pretrained pipeline that doesn't contain the new model will still apply the old in-painting method.")},m(_,c){h(_,l,c)},d(_){_&&a(l)}}}function ft(X){let l,_,c,v,H,E,le,N,pe,Z,w,me,S,ce,ue,ee,$,te,b,Q,u,C,V,fe,de,O,z,ge,he,G,F,_e,ve,A,J,we,be,U,f,B,x,Ce,ye,Y,T,Oe,Ie,M,K,W,ke,Ee,L,j,Ge,ae,q,$e,D,R,Ae,se,y,ne;return E=new mt({}),$=new ct({props:{code:`import PIL | |
| import requests | |
| import torch | |
| from io import BytesIO | |
| from diffusers import StableDiffusionInpaintPipeline | |
| 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)) | |
| pipe = StableDiffusionInpaintPipeline.from_pretrained( | |
| "runwayml/stable-diffusion-inpainting", | |
| torch_dtype=torch.float16, | |
| ) | |
| pipe = pipe.to("cuda") | |
| 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:`<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 | |
| <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">"RGB"</span>) | |
| img_url = <span class="hljs-string">"https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"</span> | |
| mask_url = <span class="hljs-string">"https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"</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>)) | |
| pipe = StableDiffusionInpaintPipeline.from_pretrained( | |
| <span class="hljs-string">"runwayml/stable-diffusion-inpainting"</span>, | |
| torch_dtype=torch.float16, | |
| ) | |
| pipe = pipe.to(<span class="hljs-string">"cuda"</span>) | |
| prompt = <span class="hljs-string">"Face of a yellow cat, high resolution, sitting on a park bench"</span> | |
| image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[<span class="hljs-number">0</span>]`}}),y=new pt({props:{warning:!0,$$slots:{default:[ut]},$$scope:{ctx:X}}}),{c(){l=s("meta"),_=p(),c=s("h1"),v=s("a"),H=s("span"),Te(E.$$.fragment),le=p(),N=s("span"),pe=d("Text-Guided Image-Inpainting"),Z=p(),w=s("p"),me=d("The "),S=s("a"),ce=d("StableDiffusionInpaintPipeline"),ue=d(" lets you edit specific parts of an image by providing a mask and a text prompt. It uses a version of Stable Diffusion specifically trained for in-painting tasks."),ee=p(),Te($.$$.fragment),te=p(),b=s("table"),Q=s("thead"),u=s("tr"),C=s("th"),V=s("code"),fe=d("image"),de=p(),O=s("th"),z=s("code"),ge=d("mask_image"),he=p(),G=s("th"),F=s("code"),_e=d("prompt"),ve=p(),A=s("th"),J=s("strong"),we=d("Output"),be=p(),U=s("tbody"),f=s("tr"),B=s("td"),x=s("img"),ye=p(),Y=s("td"),T=s("img"),Ie=p(),M=s("td"),K=s("strong"),W=s("em"),ke=d("Face of a yellow cat, high resolution, sitting on a park bench"),Ee=p(),L=s("td"),j=s("img"),ae=p(),q=s("p"),$e=d("You can also run this example on colab "),D=s("a"),R=s("img"),se=p(),Te(y.$$.fragment),this.h()},l(e){const o=ot('[data-svelte="svelte-1phssyn"]',document.head);l=n(o,"META",{name:!0,content:!0}),o.forEach(a),_=m(e),c=n(e,"H1",{class:!0});var P=r(c);v=n(P,"A",{id:!0,class:!0,href:!0});var Be=r(v);H=n(Be,"SPAN",{});var Ye=r(H);je(E.$$.fragment,Ye),Ye.forEach(a),Be.forEach(a),le=m(P),N=n(P,"SPAN",{});var Me=r(N);pe=g(Me,"Text-Guided Image-Inpainting"),Me.forEach(a),P.forEach(a),Z=m(e),w=n(e,"P",{});var ie=r(w);me=g(ie,"The "),S=n(ie,"A",{href:!0});var Le=r(S);ce=g(Le,"StableDiffusionInpaintPipeline"),Le.forEach(a),ue=g(ie," lets you edit specific parts of an image by providing a mask and a text prompt. It uses a version of Stable Diffusion specifically trained for in-painting tasks."),ie.forEach(a),ee=m(e),je($.$$.fragment,e),te=m(e),b=n(e,"TABLE",{});var re=r(b);Q=n(re,"THEAD",{});var Re=r(Q);u=n(Re,"TR",{});var I=r(u);C=n(I,"TH",{align:!0});var He=r(C);V=n(He,"CODE",{});var Ne=r(V);fe=g(Ne,"image"),Ne.forEach(a),He.forEach(a),de=m(I),O=n(I,"TH",{align:!0});var Qe=r(O);z=n(Qe,"CODE",{});var Ve=r(z);ge=g(Ve,"mask_image"),Ve.forEach(a),Qe.forEach(a),he=m(I),G=n(I,"TH",{align:!0});var ze=r(G);F=n(ze,"CODE",{});var Fe=r(F);_e=g(Fe,"prompt"),Fe.forEach(a),ze.forEach(a),ve=m(I),A=n(I,"TH",{align:!0});var Je=r(A);J=n(Je,"STRONG",{});var Ue=r(J);we=g(Ue,"Output"),Ue.forEach(a),Je.forEach(a),I.forEach(a),Re.forEach(a),be=m(re),U=n(re,"TBODY",{});var Ke=r(U);f=n(Ke,"TR",{});var k=r(f);B=n(k,"TD",{align:!0});var We=r(B);x=n(We,"IMG",{src:!0,alt:!0,width:!0}),We.forEach(a),ye=m(k),Y=n(k,"TD",{align:!0});var Xe=r(Y);T=n(Xe,"IMG",{src:!0,alt:!0,width:!0}),Xe.forEach(a),Ie=m(k),M=n(k,"TD",{align:!0});var Ze=r(M);K=n(Ze,"STRONG",{});var et=r(K);W=n(et,"EM",{});var tt=r(W);ke=g(tt,"Face of a yellow cat, high resolution, sitting on a park bench"),tt.forEach(a),et.forEach(a),Ze.forEach(a),Ee=m(k),L=n(k,"TD",{align:!0});var at=r(L);j=n(at,"IMG",{src:!0,alt:!0,width:!0}),at.forEach(a),k.forEach(a),Ke.forEach(a),re.forEach(a),ae=m(e),q=n(e,"P",{});var xe=r(q);$e=g(xe,"You can also run this example on colab "),D=n(xe,"A",{href:!0,rel:!0});var st=r(D);R=n(st,"IMG",{src:!0,alt:!0}),st.forEach(a),xe.forEach(a),se=m(e),je(y.$$.fragment,e),this.h()},h(){i(l,"name","hf:doc:metadata"),i(l,"content",JSON.stringify(dt)),i(v,"id","textguided-imageinpainting"),i(v,"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"),i(v,"href","#textguided-imageinpainting"),i(c,"class","relative group"),i(S,"href","/docs/diffusers/v0.13.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline"),i(C,"align","center"),i(O,"align","center"),i(G,"align","center"),i(A,"align","right"),oe(x.src,Ce="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png")||i(x,"src",Ce),i(x,"alt","drawing"),i(x,"width","250"),i(B,"align","center"),oe(T.src,Oe="https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png")||i(T,"src",Oe),i(T,"alt","drawing"),i(T,"width","250"),i(Y,"align","center"),i(M,"align","center"),oe(j.src,Ge="https://huggingface.co/datasets/patrickvonplaten/images/resolve/main/test.png")||i(j,"src",Ge),i(j,"alt","drawing"),i(j,"width","250"),i(L,"align","right"),oe(R.src,Ae="https://colab.research.google.com/assets/colab-badge.svg")||i(R,"src",Ae),i(R,"alt","Open In Colab"),i(D,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb"),i(D,"rel","nofollow")},m(e,o){t(document.head,l),h(e,_,o),h(e,c,o),t(c,v),t(v,H),qe(E,H,null),t(c,le),t(c,N),t(N,pe),h(e,Z,o),h(e,w,o),t(w,me),t(w,S),t(S,ce),t(w,ue),h(e,ee,o),qe($,e,o),h(e,te,o),h(e,b,o),t(b,Q),t(Q,u),t(u,C),t(C,V),t(V,fe),t(u,de),t(u,O),t(O,z),t(z,ge),t(u,he),t(u,G),t(G,F),t(F,_e),t(u,ve),t(u,A),t(A,J),t(J,we),t(b,be),t(b,U),t(U,f),t(f,B),t(B,x),t(f,ye),t(f,Y),t(Y,T),t(f,Ie),t(f,M),t(M,K),t(K,W),t(W,ke),t(f,Ee),t(f,L),t(L,j),h(e,ae,o),h(e,q,o),t(q,$e),t(q,D),t(D,R),h(e,se,o),qe(y,e,o),ne=!0},p(e,[o]){const P={};o&2&&(P.$$scope={dirty:o,ctx:e}),y.$set(P)},i(e){ne||(De(E.$$.fragment,e),De($.$$.fragment,e),De(y.$$.fragment,e),ne=!0)},o(e){Pe(E.$$.fragment,e),Pe($.$$.fragment,e),Pe(y.$$.fragment,e),ne=!1},d(e){a(l),e&&a(_),e&&a(c),Se(E),e&&a(Z),e&&a(w),e&&a(ee),Se($,e),e&&a(te),e&&a(b),e&&a(ae),e&&a(q),e&&a(se),Se(y,e)}}}const dt={local:"textguided-imageinpainting",title:"Text-Guided Image-Inpainting"};function gt(X){return lt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class bt extends nt{constructor(l){super();it(this,l,gt,ft,rt,{})}}export{bt as default,dt as metadata}; | |
Xet Storage Details
- Size:
- 9.72 kB
- Xet hash:
- 70419f6f88ab7246c3b7ea4e5b2a06688da8ae52197c1551321a10c10a3a6767
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.