import{s as V,z as K,n as O,o as ee}from"../chunks/scheduler.182ea377.js";import{S as te,i as ae,g as p,s as l,r as S,A as se,h as r,f as a,c as i,j as P,u as H,x as T,k as w,y as le,a as s,v as E,d as G,t as x,w as F}from"../chunks/index.abf12888.js";import{C as z}from"../chunks/CodeBlock.57fe6e13.js";import{D as ie}from"../chunks/DocNotebookDropdown.d9060979.js";import{H as ne}from"../chunks/Heading.16916d63.js";function oe(R){let o,J,y,_,m,B,d,v,c,A='The <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline">StableDiffusionDepth2ImgPipeline</a> lets you pass a text prompt and an initial image to condition the generation of new images. In addition, you can also pass a <code>depth_map</code> to preserve the image structure. If no <code>depth_map</code> is provided, the pipeline automatically predicts the depth via an integrated <a href="https://github.com/isl-org/MiDaS" rel="nofollow">depth-estimation model</a>.',Z,u,C='Start by creating an instance of the <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/depth2img#diffusers.StableDiffusionDepth2ImgPipeline">StableDiffusionDepth2ImgPipeline</a>:',k,f,$,h,L="Now pass your prompt to the pipeline. You can also pass a <code>negative_prompt</code> to prevent certain words from guiding how an image is generated:",I,g,W,b,N='<thead><tr><th>Input</th> <th>Output</th></tr></thead> <tbody><tr><td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/coco-cats.png" width="500"/></td> <td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/depth2img-tigers.png" width="500"/></td></tr></tbody>',Q,M,Y="Play around with the Spaces below and see if you notice a difference between generated images with and without a depth map!",U,n,q,X,j,D;return m=new ne({props:{title:"Text-guided depth-to-image generation",local:"text-guided-depth-to-image-generation",headingTag:"h1"}}),d=new ie({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"}]}}),f=new z({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>)`,wrap:!1}}),g=new z({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`,wrap:!1}}),{c(){o=p("meta"),J=l(),y=p("p"),_=l(),S(m.$$.fragment),B=l(),S(d.$$.fragment),v=l(),c=p("p"),c.innerHTML=A,Z=l(),u=p("p"),u.innerHTML=C,k=l(),S(f.$$.fragment),$=l(),h=p("p"),h.innerHTML=L,I=l(),S(g.$$.fragment),W=l(),b=p("table"),b.innerHTML=N,Q=l(),M=p("p"),M.textContent=Y,U=l(),n=p("iframe"),X=l(),j=p("p"),this.h()},l(e){const t=se("svelte-u9bgzb",document.head);o=r(t,"META",{name:!0,content:!0}),t.forEach(a),J=i(e),y=r(e,"P",{}),P(y).forEach(a),_=i(e),H(m.$$.fragment,e),B=i(e),H(d.$$.fragment,e),v=i(e),c=r(e,"P",{"data-svelte-h":!0}),T(c)!=="svelte-du0wp2"&&(c.innerHTML=A),Z=i(e),u=r(e,"P",{"data-svelte-h":!0}),T(u)!=="svelte-181psnb"&&(u.innerHTML=C),k=i(e),H(f.$$.fragment,e),$=i(e),h=r(e,"P",{"data-svelte-h":!0}),T(h)!=="svelte-deexa5"&&(h.innerHTML=L),I=i(e),H(g.$$.fragment,e),W=i(e),b=r(e,"TABLE",{"data-svelte-h":!0}),T(b)!=="svelte-175x2as"&&(b.innerHTML=N),Q=i(e),M=r(e,"P",{"data-svelte-h":!0}),T(M)!=="svelte-lknzmp"&&(M.textContent=Y),U=i(e),n=r(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),P(n).forEach(a),X=i(e),j=r(e,"P",{}),P(j).forEach(a),this.h()},h(){w(o,"name","hf:doc:metadata"),w(o,"content",pe),K(n.src,q="https://radames-stable-diffusion-depth2img.hf.space")||w(n,"src",q),w(n,"frameborder","0"),w(n,"width","850"),w(n,"height","500")},m(e,t){le(document.head,o),s(e,J,t),s(e,y,t),s(e,_,t),E(m,e,t),s(e,B,t),E(d,e,t),s(e,v,t),s(e,c,t),s(e,Z,t),s(e,u,t),s(e,k,t),E(f,e,t),s(e,$,t),s(e,h,t),s(e,I,t),E(g,e,t),s(e,W,t),s(e,b,t),s(e,Q,t),s(e,M,t),s(e,U,t),s(e,n,t),s(e,X,t),s(e,j,t),D=!0},p:O,i(e){D||(G(m.$$.fragment,e),G(d.$$.fragment,e),G(f.$$.fragment,e),G(g.$$.fragment,e),D=!0)},o(e){x(m.$$.fragment,e),x(d.$$.fragment,e),x(f.$$.fragment,e),x(g.$$.fragment,e),D=!1},d(e){e&&(a(J),a(y),a(_),a(B),a(v),a(c),a(Z),a(u),a(k),a($),a(h),a(I),a(W),a(b),a(Q),a(M),a(U),a(n),a(X),a(j)),a(o),F(m,e),F(d,e),F(f,e),F(g,e)}}}const pe='{"title":"Text-guided depth-to-image generation","local":"text-guided-depth-to-image-generation","sections":[],"depth":1}';function re(R){return ee(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class he extends te{constructor(o){super(),ae(this,o,re,oe,V,{})}}export{he as component};
