import{S as it,i as lt,s as nt,e as s,k as h,w as re,t as n,M as rt,c as o,d as t,m as f,a as i,x as pe,h as r,b as p,N as Xe,G as a,g as d,y as de,L as pt,q as me,o as he,B as fe,v as dt}from"../../chunks/vendor-hf-doc-builder.js";import{I as mt}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as ot}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as ht}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function ft(Ge){let g,x,b,w,U,M,ce,W,ue,H,T,q,m,ge,k,be,we,Q,ye,ve,X,_e,Me,E,Te,Ee,C,y,je,Z,Je,Be,L,j,z,v,Ie,G,ke,Ze,V,J,O,_,P,B,A,De,$e,N,Se,Ue,F,I,R,D,Pe,We,Y,$,Ae,K,S,Qe,ee,c,Ne,te;return M=new mt({}),T=new ht({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/depth2img.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/depth2img.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/depth2img.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/depth2img.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/depth2img.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/depth2img.ipynb"}]}}),j=new ot({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjByZXF1ZXN0cyUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQSUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBTdGFibGVEaWZmdXNpb25EZXB0aDJJbWdQaXBlbGluZSUwQSUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25EZXB0aDJJbWdQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLTItZGVwdGglMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMEEpLnRvKCUyMmN1ZGElMjIp",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionDepth2ImgPipeline

pipe = StableDiffusionDepth2ImgPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-2-depth&quot;</span>,
    torch_dtype=torch.float16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)`}}),J=new ot({props:{code:"dXJsJTIwJTNEJTIwJTIyaHR0cCUzQSUyRiUyRmltYWdlcy5jb2NvZGF0YXNldC5vcmclMkZ2YWwyMDE3JTJGMDAwMDAwMDM5NzY5LmpwZyUyMiUwQWluaXRfaW1hZ2UlMjAlM0QlMjBJbWFnZS5vcGVuKHJlcXVlc3RzLmdldCh1cmwlMkMlMjBzdHJlYW0lM0RUcnVlKS5yYXcpJTBBcHJvbXB0JTIwJTNEJTIwJTIydHdvJTIwdGlnZXJzJTIyJTBBbl9wcm9tcHQlMjAlM0QlMjAlMjJiYWQlMkMlMjBkZWZvcm1lZCUyQyUyMHVnbHklMkMlMjBiYWQlMjBhbmF0b215JTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKHByb21wdCUzRHByb21wdCUyQyUyMGltYWdlJTNEaW5pdF9pbWFnZSUyQyUyMG5lZ2F0aXZlX3Byb21wdCUzRG5fcHJvbXB0JTJDJTIwc3RyZW5ndGglM0QwLjcpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",highlighted:`url = <span class="hljs-string">&quot;http://images.cocodataset.org/val2017/000000039769.jpg&quot;</span>
init_image = Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
prompt = <span class="hljs-string">&quot;two tigers&quot;</span>
n_prompt = <span class="hljs-string">&quot;bad, deformed, ugly, bad anatomy&quot;</span>
image = pipe(prompt=prompt, image=init_image, negative_prompt=n_prompt, strength=<span class="hljs-number">0.7</span>).images[<span class="hljs-number">0</span>]
image`}}),{c(){g=s("meta"),x=h(),b=s("h1"),w=s("a"),U=s("span"),re(M.$$.fragment),ce=h(),W=s("span"),ue=n("Text-guided depth-to-image generation"),H=h(),re(T.$$.fragment),q=h(),m=s("p"),ge=n("The "),k=s("a"),be=n("StableDiffusionDepth2ImgPipeline"),we=n(" lets you pass a text prompt and an initial image to condition the generation of new images. In addition, you can also pass a "),Q=s("code"),ye=n("depth_map"),ve=n(" to preserve the image structure. If no "),X=s("code"),_e=n("depth_map"),Me=n(" is provided, the pipeline automatically predicts the depth via an integrated "),E=s("a"),Te=n("depth-estimation model"),Ee=n("."),C=h(),y=s("p"),je=n("Start by creating an instance of the "),Z=s("a"),Je=n("StableDiffusionDepth2ImgPipeline"),Be=n(":"),L=h(),re(j.$$.fragment),z=h(),v=s("p"),Ie=n("Now pass your prompt to the pipeline. You can also pass a "),G=s("code"),ke=n("negative_prompt"),Ze=n(" to prevent certain words from guiding how an image is generated:"),V=h(),re(J.$$.fragment),O=h(),_=s("table"),P=s("thead"),B=s("tr"),A=s("th"),De=n("Input"),$e=h(),N=s("th"),Se=n("Output"),Ue=h(),F=s("tbody"),I=s("tr"),R=s("td"),D=s("img"),We=h(),Y=s("td"),$=s("img"),K=h(),S=s("p"),Qe=n("Play around with the Spaces below and see if you notice a difference between generated images with and without a depth map!"),ee=h(),c=s("iframe"),this.h()},l(e){const l=rt('[data-svelte="svelte-1phssyn"]',document.head);g=o(l,"META",{name:!0,content:!0}),l.forEach(t),x=f(e),b=o(e,"H1",{class:!0});var ae=i(b);w=o(ae,"A",{id:!0,class:!0,href:!0});var Fe=i(w);U=o(Fe,"SPAN",{});var Re=i(U);pe(M.$$.fragment,Re),Re.forEach(t),Fe.forEach(t),ce=f(ae),W=o(ae,"SPAN",{});var Ye=i(W);ue=r(Ye,"Text-guided depth-to-image generation"),Ye.forEach(t),ae.forEach(t),H=f(e),pe(T.$$.fragment,e),q=f(e),m=o(e,"P",{});var u=i(m);ge=r(u,"The "),k=o(u,"A",{href:!0});var xe=i(k);be=r(xe,"StableDiffusionDepth2ImgPipeline"),xe.forEach(t),we=r(u," lets you pass a text prompt and an initial image to condition the generation of new images. In addition, you can also pass a "),Q=o(u,"CODE",{});var He=i(Q);ye=r(He,"depth_map"),He.forEach(t),ve=r(u," to preserve the image structure. If no "),X=o(u,"CODE",{});var qe=i(X);_e=r(qe,"depth_map"),qe.forEach(t),Me=r(u," is provided, the pipeline automatically predicts the depth via an integrated "),E=o(u,"A",{href:!0,rel:!0});var Ce=i(E);Te=r(Ce,"depth-estimation model"),Ce.forEach(t),Ee=r(u,"."),u.forEach(t),C=f(e),y=o(e,"P",{});var se=i(y);je=r(se,"Start by creating an instance of the "),Z=o(se,"A",{href:!0});var Le=i(Z);Je=r(Le,"StableDiffusionDepth2ImgPipeline"),Le.forEach(t),Be=r(se,":"),se.forEach(t),L=f(e),pe(j.$$.fragment,e),z=f(e),v=o(e,"P",{});var oe=i(v);Ie=r(oe,"Now pass your prompt to the pipeline. You can also pass a "),G=o(oe,"CODE",{});var ze=i(G);ke=r(ze,"negative_prompt"),ze.forEach(t),Ze=r(oe," to prevent certain words from guiding how an image is generated:"),oe.forEach(t),V=f(e),pe(J.$$.fragment,e),O=f(e),_=o(e,"TABLE",{});var ie=i(_);P=o(ie,"THEAD",{});var Ve=i(P);B=o(Ve,"TR",{});var le=i(B);A=o(le,"TH",{});var Oe=i(A);De=r(Oe,"Input"),Oe.forEach(t),$e=f(le),N=o(le,"TH",{});var Ke=i(N);Se=r(Ke,"Output"),Ke.forEach(t),le.forEach(t),Ve.forEach(t),Ue=f(ie),F=o(ie,"TBODY",{});var et=i(F);I=o(et,"TR",{});var ne=i(I);R=o(ne,"TD",{});var tt=i(R);D=o(tt,"IMG",{src:!0,width:!0}),tt.forEach(t),We=f(ne),Y=o(ne,"TD",{});var at=i(Y);$=o(at,"IMG",{src:!0,width:!0}),at.forEach(t),ne.forEach(t),et.forEach(t),ie.forEach(t),K=f(e),S=o(e,"P",{});var st=i(S);Qe=r(st,"Play around with the Spaces below and see if you notice a difference between generated images with and without a depth map!"),st.forEach(t),ee=f(e),c=o(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),i(c).forEach(t),this.h()},h(){p(g,"name","hf:doc:metadata"),p(g,"content",JSON.stringify(ct)),p(w,"id","textguided-depthtoimage-generation"),p(w,"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"),p(w,"href","#textguided-depthtoimage-generation"),p(b,"class","relative group"),p(k,"href","/docs/diffusers/v0.19.2/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline"),p(E,"href","https://github.com/isl-org/MiDaS"),p(E,"rel","nofollow"),p(Z,"href","/docs/diffusers/v0.19.2/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline"),Xe(D.src,Pe="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/coco-cats.png")||p(D,"src",Pe),p(D,"width","500"),Xe($.src,Ae="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/depth2img-tigers.png")||p($,"src",Ae),p($,"width","500"),Xe(c.src,Ne="https://radames-stable-diffusion-depth2img.hf.space")||p(c,"src",Ne),p(c,"frameborder","0"),p(c,"width","850"),p(c,"height","500")},m(e,l){a(document.head,g),d(e,x,l),d(e,b,l),a(b,w),a(w,U),de(M,U,null),a(b,ce),a(b,W),a(W,ue),d(e,H,l),de(T,e,l),d(e,q,l),d(e,m,l),a(m,ge),a(m,k),a(k,be),a(m,we),a(m,Q),a(Q,ye),a(m,ve),a(m,X),a(X,_e),a(m,Me),a(m,E),a(E,Te),a(m,Ee),d(e,C,l),d(e,y,l),a(y,je),a(y,Z),a(Z,Je),a(y,Be),d(e,L,l),de(j,e,l),d(e,z,l),d(e,v,l),a(v,Ie),a(v,G),a(G,ke),a(v,Ze),d(e,V,l),de(J,e,l),d(e,O,l),d(e,_,l),a(_,P),a(P,B),a(B,A),a(A,De),a(B,$e),a(B,N),a(N,Se),a(_,Ue),a(_,F),a(F,I),a(I,R),a(R,D),a(I,We),a(I,Y),a(Y,$),d(e,K,l),d(e,S,l),a(S,Qe),d(e,ee,l),d(e,c,l),te=!0},p:pt,i(e){te||(me(M.$$.fragment,e),me(T.$$.fragment,e),me(j.$$.fragment,e),me(J.$$.fragment,e),te=!0)},o(e){he(M.$$.fragment,e),he(T.$$.fragment,e),he(j.$$.fragment,e),he(J.$$.fragment,e),te=!1},d(e){t(g),e&&t(x),e&&t(b),fe(M),e&&t(H),fe(T,e),e&&t(q),e&&t(m),e&&t(C),e&&t(y),e&&t(L),fe(j,e),e&&t(z),e&&t(v),e&&t(V),fe(J,e),e&&t(O),e&&t(_),e&&t(K),e&&t(S),e&&t(ee),e&&t(c)}}}const ct={local:"textguided-depthtoimage-generation",title:"Text-guided depth-to-image generation"};function ut(Ge){return dt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class vt extends it{constructor(g){super();lt(this,g,ut,ft,nt,{})}}export{vt as default,ct as metadata};
