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 c,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 ce,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 ct(Ae){let g,x,b,w,W,_,fe,Q,ue,H,T,q,m,ge,k,be,we,U,ye,Me,X,ve,_e,j,Te,je,C,y,Je,D,Ee,Be,z,J,L,M,Ie,A,ke,De,V,E,O,v,G,B,P,Ze,$e,N,Se,We,R,I,F,Z,Ge,Qe,Y,$,Pe,K,S,Ue,ee,f,Ne,te;return _=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:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjByZXF1ZXN0cyUwQWZyb20lMjBQSUwlMjBpbXBvcnQlMjBJbWFnZSUwQSUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBTdGFibGVEaWZmdXNpb25EZXB0aDJJbWdQaXBlbGluZSUwQSUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25EZXB0aDJJbWdQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLTItZGVwdGglMjIlMkMlMEElMjAlMjAlMjAlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMEElMjAlMjAlMjAlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlJTJDJTBBKS50byglMjJjdWRhJTIyKQ==",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,
    use_safetensors=<span class="hljs-literal">True</span>,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)`}}),E=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"),W=s("span"),re(_.$$.fragment),fe=h(),Q=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 "),U=s("code"),ye=n("depth_map"),Me=n(" to preserve the image structure. If no "),X=s("code"),ve=n("depth_map"),_e=n(" is provided, the pipeline automatically predicts the depth via an integrated "),j=s("a"),Te=n("depth-estimation model"),je=n("."),C=h(),y=s("p"),Je=n("Start by creating an instance of the "),D=s("a"),Ee=n("StableDiffusionDepth2ImgPipeline"),Be=n(":"),z=h(),re(J.$$.fragment),L=h(),M=s("p"),Ie=n("Now pass your prompt to the pipeline. You can also pass a "),A=s("code"),ke=n("negative_prompt"),De=n(" to prevent certain words from guiding how an image is generated:"),V=h(),re(E.$$.fragment),O=h(),v=s("table"),G=s("thead"),B=s("tr"),P=s("th"),Ze=n("Input"),$e=h(),N=s("th"),Se=n("Output"),We=h(),R=s("tbody"),I=s("tr"),F=s("td"),Z=s("img"),Qe=h(),Y=s("td"),$=s("img"),K=h(),S=s("p"),Ue=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(),f=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=c(e),b=o(e,"H1",{class:!0});var ae=i(b);w=o(ae,"A",{id:!0,class:!0,href:!0});var Re=i(w);W=o(Re,"SPAN",{});var Fe=i(W);pe(_.$$.fragment,Fe),Fe.forEach(t),Re.forEach(t),fe=c(ae),Q=o(ae,"SPAN",{});var Ye=i(Q);ue=r(Ye,"Text-guided depth-to-image generation"),Ye.forEach(t),ae.forEach(t),H=c(e),pe(T.$$.fragment,e),q=c(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 "),U=o(u,"CODE",{});var He=i(U);ye=r(He,"depth_map"),He.forEach(t),Me=r(u," to preserve the image structure. If no "),X=o(u,"CODE",{});var qe=i(X);ve=r(qe,"depth_map"),qe.forEach(t),_e=r(u," is provided, the pipeline automatically predicts the depth via an integrated "),j=o(u,"A",{href:!0,rel:!0});var Ce=i(j);Te=r(Ce,"depth-estimation model"),Ce.forEach(t),je=r(u,"."),u.forEach(t),C=c(e),y=o(e,"P",{});var se=i(y);Je=r(se,"Start by creating an instance of the "),D=o(se,"A",{href:!0});var ze=i(D);Ee=r(ze,"StableDiffusionDepth2ImgPipeline"),ze.forEach(t),Be=r(se,":"),se.forEach(t),z=c(e),pe(J.$$.fragment,e),L=c(e),M=o(e,"P",{});var oe=i(M);Ie=r(oe,"Now pass your prompt to the pipeline. You can also pass a "),A=o(oe,"CODE",{});var Le=i(A);ke=r(Le,"negative_prompt"),Le.forEach(t),De=r(oe," to prevent certain words from guiding how an image is generated:"),oe.forEach(t),V=c(e),pe(E.$$.fragment,e),O=c(e),v=o(e,"TABLE",{});var ie=i(v);G=o(ie,"THEAD",{});var Ve=i(G);B=o(Ve,"TR",{});var le=i(B);P=o(le,"TH",{});var Oe=i(P);Ze=r(Oe,"Input"),Oe.forEach(t),$e=c(le),N=o(le,"TH",{});var Ke=i(N);Se=r(Ke,"Output"),Ke.forEach(t),le.forEach(t),Ve.forEach(t),We=c(ie),R=o(ie,"TBODY",{});var et=i(R);I=o(et,"TR",{});var ne=i(I);F=o(ne,"TD",{});var tt=i(F);Z=o(tt,"IMG",{src:!0,width:!0}),tt.forEach(t),Qe=c(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=c(e),S=o(e,"P",{});var st=i(S);Ue=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=c(e),f=o(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),i(f).forEach(t),this.h()},h(){p(g,"name","hf:doc:metadata"),p(g,"content",JSON.stringify(ft)),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.21.0/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline"),p(j,"href","https://github.com/isl-org/MiDaS"),p(j,"rel","nofollow"),p(D,"href","/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline"),Xe(Z.src,Ge="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/coco-cats.png")||p(Z,"src",Ge),p(Z,"width","500"),Xe($.src,Pe="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/depth2img-tigers.png")||p($,"src",Pe),p($,"width","500"),Xe(f.src,Ne="https://radames-stable-diffusion-depth2img.hf.space")||p(f,"src",Ne),p(f,"frameborder","0"),p(f,"width","850"),p(f,"height","500")},m(e,l){a(document.head,g),d(e,x,l),d(e,b,l),a(b,w),a(w,W),de(_,W,null),a(b,fe),a(b,Q),a(Q,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,U),a(U,ye),a(m,Me),a(m,X),a(X,ve),a(m,_e),a(m,j),a(j,Te),a(m,je),d(e,C,l),d(e,y,l),a(y,Je),a(y,D),a(D,Ee),a(y,Be),d(e,z,l),de(J,e,l),d(e,L,l),d(e,M,l),a(M,Ie),a(M,A),a(A,ke),a(M,De),d(e,V,l),de(E,e,l),d(e,O,l),d(e,v,l),a(v,G),a(G,B),a(B,P),a(P,Ze),a(B,$e),a(B,N),a(N,Se),a(v,We),a(v,R),a(R,I),a(I,F),a(F,Z),a(I,Qe),a(I,Y),a(Y,$),d(e,K,l),d(e,S,l),a(S,Ue),d(e,ee,l),d(e,f,l),te=!0},p:pt,i(e){te||(me(_.$$.fragment,e),me(T.$$.fragment,e),me(J.$$.fragment,e),me(E.$$.fragment,e),te=!0)},o(e){he(_.$$.fragment,e),he(T.$$.fragment,e),he(J.$$.fragment,e),he(E.$$.fragment,e),te=!1},d(e){t(g),e&&t(x),e&&t(b),ce(_),e&&t(H),ce(T,e),e&&t(q),e&&t(m),e&&t(C),e&&t(y),e&&t(z),ce(J,e),e&&t(L),e&&t(M),e&&t(V),ce(E,e),e&&t(O),e&&t(v),e&&t(K),e&&t(S),e&&t(ee),e&&t(f)}}}const ft={local:"textguided-depthtoimage-generation",title:"Text-guided depth-to-image generation"};function ut(Ae){return dt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Mt extends it{constructor(g){super();lt(this,g,ut,ct,nt,{})}}export{Mt as default,ft as metadata};
