import{S as Ha,i as La,s as Ka,e as l,k as h,w as d,t as r,M as Oa,c as o,d as s,m as f,a as i,x as y,h as n,b as c,N as as,G as t,g as p,y as g,q as b,o as w,B as J,v as el}from"../../chunks/vendor-hf-doc-builder.js";import{T as sl}from"../../chunks/Tip-hf-doc-builder.js";import{I as As}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as tl}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";function al(ls){let m,D,u,T,W,j,H,B;return{c(){m=l("p"),D=r("You can optionally save the mesh output as an "),u=l("code"),T=r("obj"),W=r(" file with the "),j=l("code"),H=r("export_to_obj()"),B=r(" function. The ability to save the mesh output in a variety of formats makes it more flexible for downstream usage!")},l($){m=o($,"P",{});var v=i(m);D=n(v,"You can optionally save the mesh output as an "),u=o(v,"CODE",{});var I=i(u);T=n(I,"obj"),I.forEach(s),W=n(v," file with the "),j=o(v,"CODE",{});var L=i(j);H=n(L,"export_to_obj()"),L.forEach(s),B=n(v," function. The ability to save the mesh output in a variety of formats makes it more flexible for downstream usage!"),v.forEach(s)},m($,v){p($,m,v),t(m,D),t(m,u),t(u,T),t(m,W),t(m,j),t(j,H),t(m,B)},d($){$&&s(m)}}}function ll(ls){let m,D,u,T,W,j,H,B,$,v,I,L,ge,Ps,os,x,xe,Hs,Ls,ze,Ks,is,be,Os,rs,we,et,ns,K,ps,G,z,Ne,O,st,Xe,tt,cs,N,at,Je,lt,ot,hs,ee,fs,X,it,Me,rt,nt,ms,se,us,S,te,je,oa,pt,ve,ct,ht,ae,Te,ia,ft,_e,mt,ds,V,F,Fe,le,ut,qe,dt,ys,Z,yt,Ie,gt,bt,Ze,wt,Jt,gs,oe,bs,q,Mt,Ee,jt,vt,ws,ie,Js,R,re,Ue,ra,Tt,ke,_t,It,ne,We,na,Zt,Be,Et,Ms,Y,Q,Qe,pe,Ut,Ae,kt,js,_,Wt,Pe,Bt,$t,He,Gt,St,ce,Vt,Rt,vs,M,Yt,$e,Ct,Dt,Ge,xt,zt,Le,Nt,Xt,Ke,Ft,qt,Ts,he,_s,E,Qt,Oe,At,Pt,es,Ht,Lt,Is,A,Zs,fe,Es,U,Kt,ss,Ot,ea,ts,sa,ta,Us,me,ks,Se,aa,Ws,ue,Bs,Ve,la,$s,de,Re,pa,Gs;return j=new As({}),I=new tl({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/shap-e.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/shap-e.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/shap-e.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/shap-e.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/shap-e.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/shap-e.ipynb"}]}}),K=new C({props:{code:"JTIzJTIwdW5jb21tZW50JTIwdG8lMjBpbnN0YWxsJTIwdGhlJTIwbmVjZXNzYXJ5JTIwbGlicmFyaWVzJTIwaW4lMjBDb2xhYiUwQSUyMyFwaXAlMjBpbnN0YWxsJTIwZGlmZnVzZXJzJTIwdHJhbnNmb3JtZXJzJTIwYWNjZWxlcmF0ZSUyMHNhZmV0ZW5zb3JzJTIwdHJpbWVzaA==",highlighted:`<span class="hljs-comment"># uncomment to install the necessary libraries in Colab</span>
<span class="hljs-comment">#!pip install diffusers transformers accelerate safetensors trimesh</span>`}}),O=new As({}),ee=new C({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU2hhcEVQaXBlbGluZSUwQSUwQWRldmljZSUyMCUzRCUyMHRvcmNoLmRldmljZSglMjJjdWRhJTIyJTIwaWYlMjB0b3JjaC5jdWRhLmlzX2F2YWlsYWJsZSgpJTIwZWxzZSUyMCUyMmNwdSUyMiklMEElMEFwaXBlJTIwJTNEJTIwU2hhcEVQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyb3BlbmFpJTJGc2hhcC1lJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTIwdmFyaWFudCUzRCUyMmZwMTYlMjIlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQXBpcGUlMjAlM0QlMjBwaXBlLnRvKGRldmljZSklMEElMEFndWlkYW5jZV9zY2FsZSUyMCUzRCUyMDE1LjAlMEFwcm9tcHQlMjAlM0QlMjAlNUIlMjJBJTIwZmlyZWNyYWNrZXIlMjIlMkMlMjAlMjJBJTIwYmlydGhkYXklMjBjdXBjYWtlJTIyJTVEJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZSglMEElMjAlMjAlMjAlMjBwcm9tcHQlMkMlMEElMjAlMjAlMjAlMjBndWlkYW5jZV9zY2FsZSUzRGd1aWRhbmNlX3NjYWxlJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDY0JTJDJTBBJTIwJTIwJTIwJTIwZnJhbWVfc2l6ZSUzRDI1NiUyQyUwQSkuaW1hZ2Vz",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ShapEPipeline

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>)

pipe = ShapEPipeline.from_pretrained(<span class="hljs-string">&quot;openai/shap-e&quot;</span>, torch_dtype=torch.float16, variant=<span class="hljs-string">&quot;fp16&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
pipe = pipe.to(device)

guidance_scale = <span class="hljs-number">15.0</span>
prompt = [<span class="hljs-string">&quot;A firecracker&quot;</span>, <span class="hljs-string">&quot;A birthday cupcake&quot;</span>]

images = pipe(
    prompt,
    guidance_scale=guidance_scale,
    num_inference_steps=<span class="hljs-number">64</span>,
    frame_size=<span class="hljs-number">256</span>,
).images`}}),se=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGV4cG9ydF90b19naWYlMEElMEFleHBvcnRfdG9fZ2lmKGltYWdlcyU1QjAlNUQlMkMlMjAlMjJmaXJlY3JhY2tlcl8zZC5naWYlMjIpJTBBZXhwb3J0X3RvX2dpZihpbWFnZXMlNUIxJTVEJTJDJTIwJTIyY2FrZV8zZC5naWYlMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_gif

export_to_gif(images[<span class="hljs-number">0</span>], <span class="hljs-string">&quot;firecracker_3d.gif&quot;</span>)
export_to_gif(images[<span class="hljs-number">1</span>], <span class="hljs-string">&quot;cake_3d.gif&quot;</span>)`}}),le=new As({}),oe=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFwcmlvcl9waXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJrYW5kaW5za3ktY29tbXVuaXR5JTJGa2FuZGluc2t5LTItMS1wcmlvciUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpLnRvKCUyMmN1ZGElMjIpJTBBcGlwZWxpbmUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIya2FuZGluc2t5LWNvbW11bml0eSUyRmthbmRpbnNreS0yLTElMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKS50byglMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkElMjBjaGVlc2VidXJnZXIlMkMlMjB3aGl0ZSUyMGJhY2tncm91bmQlMjIlMEElMEFpbWFnZV9lbWJlZHMlMkMlMjBuZWdhdGl2ZV9pbWFnZV9lbWJlZHMlMjAlM0QlMjBwcmlvcl9waXBlbGluZShwcm9tcHQlMkMlMjBndWlkYW5jZV9zY2FsZSUzRDEuMCkudG9fdHVwbGUoKSUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwcHJvbXB0JTJDJTBBJTIwJTIwJTIwJTIwaW1hZ2VfZW1iZWRzJTNEaW1hZ2VfZW1iZWRzJTJDJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfaW1hZ2VfZW1iZWRzJTNEbmVnYXRpdmVfaW1hZ2VfZW1iZWRzJTJDJTBBKS5pbWFnZXMlNUIwJTVEJTBBJTBBaW1hZ2Uuc2F2ZSglMjJidXJnZXIucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-keyword">import</span> torch

prior_pipeline = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;kandinsky-community/kandinsky-2-1-prior&quot;</span>, torch_dtype=torch.float16, use_safetensors=<span class="hljs-literal">True</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;kandinsky-community/kandinsky-2-1&quot;</span>, torch_dtype=torch.float16, use_safetensors=<span class="hljs-literal">True</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;A cheeseburger, white background&quot;</span>

image_embeds, negative_image_embeds = prior_pipeline(prompt, guidance_scale=<span class="hljs-number">1.0</span>).to_tuple()
image = pipeline(
    prompt,
    image_embeds=image_embeds,
    negative_image_embeds=negative_image_embeds,
).images[<span class="hljs-number">0</span>]

image.save(<span class="hljs-string">&quot;burger.png&quot;</span>)`}}),ie=new C({props:{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGV4cG9ydF90b19naWYlMEElMEFwaXBlJTIwJTNEJTIwU2hhcEVJbWcySW1nUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMm9wZW5haSUyRnNoYXAtZS1pbWcyaW1nJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTIwdmFyaWFudCUzRCUyMmZwMTYlMjIpLnRvKCUyMmN1ZGElMjIpJTBBJTBBZ3VpZGFuY2Vfc2NhbGUlMjAlM0QlMjAzLjAlMEFpbWFnZSUyMCUzRCUyMEltYWdlLm9wZW4oJTIyYnVyZ2VyLnBuZyUyMikucmVzaXplKCgyNTYlMkMlMjAyNTYpKSUwQSUwQWltYWdlcyUyMCUzRCUyMHBpcGUoJTBBJTIwJTIwJTIwJTIwaW1hZ2UlMkMlMEElMjAlMjAlMjAlMjBndWlkYW5jZV9zY2FsZSUzRGd1aWRhbmNlX3NjYWxlJTJDJTBBJTIwJTIwJTIwJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDY0JTJDJTBBJTIwJTIwJTIwJTIwZnJhbWVfc2l6ZSUzRDI1NiUyQyUwQSkuaW1hZ2VzJTBBJTBBZ2lmX3BhdGglMjAlM0QlMjBleHBvcnRfdG9fZ2lmKGltYWdlcyU1QjAlNUQlMkMlMjAlMjJidXJnZXJfM2QuZ2lmJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_gif

pipe = ShapEImg2ImgPipeline.from_pretrained(<span class="hljs-string">&quot;openai/shap-e-img2img&quot;</span>, torch_dtype=torch.float16, variant=<span class="hljs-string">&quot;fp16&quot;</span>).to(<span class="hljs-string">&quot;cuda&quot;</span>)

guidance_scale = <span class="hljs-number">3.0</span>
image = Image.<span class="hljs-built_in">open</span>(<span class="hljs-string">&quot;burger.png&quot;</span>).resize((<span class="hljs-number">256</span>, <span class="hljs-number">256</span>))

images = pipe(
    image,
    guidance_scale=guidance_scale,
    num_inference_steps=<span class="hljs-number">64</span>,
    frame_size=<span class="hljs-number">256</span>,
).images

gif_path = export_to_gif(images[<span class="hljs-number">0</span>], <span class="hljs-string">&quot;burger_3d.gif&quot;</span>)`}}),pe=new As({}),he=new C({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU2hhcEVQaXBlbGluZSUwQSUwQWRldmljZSUyMCUzRCUyMHRvcmNoLmRldmljZSglMjJjdWRhJTIyJTIwaWYlMjB0b3JjaC5jdWRhLmlzX2F2YWlsYWJsZSgpJTIwZWxzZSUyMCUyMmNwdSUyMiklMEElMEFwaXBlJTIwJTNEJTIwU2hhcEVQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyb3BlbmFpJTJGc2hhcC1lJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTIwdmFyaWFudCUzRCUyMmZwMTYlMjIlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQXBpcGUlMjAlM0QlMjBwaXBlLnRvKGRldmljZSklMEElMEFndWlkYW5jZV9zY2FsZSUyMCUzRCUyMDE1LjAlMEFwcm9tcHQlMjAlM0QlMjAlMjJBJTIwYmlydGhkYXklMjBjdXBjYWtlJTIyJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBndWlkYW5jZV9zY2FsZSUzRGd1aWRhbmNlX3NjYWxlJTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDY0JTJDJTIwZnJhbWVfc2l6ZSUzRDI1NiUyQyUyMG91dHB1dF90eXBlJTNEJTIybWVzaCUyMikuaW1hZ2Vz",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ShapEPipeline

device = torch.device(<span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-keyword">if</span> torch.cuda.is_available() <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;cpu&quot;</span>)

pipe = ShapEPipeline.from_pretrained(<span class="hljs-string">&quot;openai/shap-e&quot;</span>, torch_dtype=torch.float16, variant=<span class="hljs-string">&quot;fp16&quot;</span>, use_safetensors=<span class="hljs-literal">True</span>)
pipe = pipe.to(device)

guidance_scale = <span class="hljs-number">15.0</span>
prompt = <span class="hljs-string">&quot;A birthday cupcake&quot;</span>

images = pipe(prompt, guidance_scale=guidance_scale, num_inference_steps=<span class="hljs-number">64</span>, frame_size=<span class="hljs-number">256</span>, output_type=<span class="hljs-string">&quot;mesh&quot;</span>).images`}}),A=new sl({props:{$$slots:{default:[al]},$$scope:{ctx:ls}}}),fe=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGV4cG9ydF90b19wbHklMEElMEFwbHlfcGF0aCUyMCUzRCUyMGV4cG9ydF90b19wbHkoaW1hZ2VzJTVCMCU1RCUyQyUyMCUyMjNkX2Nha2UucGx5JTIyKSUwQXByaW50KGYlMjJzYXZlZCUyMHRvJTIwZm9sZGVyJTNBJTIwJTdCcGx5X3BhdGglN0QlMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_ply

ply_path = export_to_ply(images[<span class="hljs-number">0</span>], <span class="hljs-string">&quot;3d_cake.ply&quot;</span>)
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;saved to folder: <span class="hljs-subst">{ply_path}</span>&quot;</span>)`}}),me=new C({props:{code:"aW1wb3J0JTIwdHJpbWVzaCUwQSUwQW1lc2glMjAlM0QlMjB0cmltZXNoLmxvYWQoJTIyM2RfY2FrZS5wbHklMjIpJTBBbWVzaC5leHBvcnQoJTIyM2RfY2FrZS5nbGIlMjIlMkMlMjBmaWxlX3R5cGUlM0QlMjJnbGIlMjIp",highlighted:`<span class="hljs-keyword">import</span> trimesh

mesh = trimesh.load(<span class="hljs-string">&quot;3d_cake.ply&quot;</span>)
mesh.export(<span class="hljs-string">&quot;3d_cake.glb&quot;</span>, file_type=<span class="hljs-string">&quot;glb&quot;</span>)`}}),ue=new C({props:{code:"aW1wb3J0JTIwdHJpbWVzaCUwQWltcG9ydCUyMG51bXB5JTIwYXMlMjBucCUwQSUwQW1lc2glMjAlM0QlMjB0cmltZXNoLmxvYWQoJTIyM2RfY2FrZS5wbHklMjIpJTBBcm90JTIwJTNEJTIwdHJpbWVzaC50cmFuc2Zvcm1hdGlvbnMucm90YXRpb25fbWF0cml4KC1ucC5waSUyMCUyRiUyMDIlMkMlMjAlNUIxJTJDJTIwMCUyQyUyMDAlNUQpJTBBbWVzaCUyMCUzRCUyMG1lc2guYXBwbHlfdHJhbnNmb3JtKHJvdCklMEFtZXNoLmV4cG9ydCglMjIzZF9jYWtlLmdsYiUyMiUyQyUyMGZpbGVfdHlwZSUzRCUyMmdsYiUyMik=",highlighted:`<span class="hljs-keyword">import</span> trimesh
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

mesh = trimesh.load(<span class="hljs-string">&quot;3d_cake.ply&quot;</span>)
rot = trimesh.transformations.rotation_matrix(-np.pi / <span class="hljs-number">2</span>, [<span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">0</span>])
mesh = mesh.apply_transform(rot)
mesh.export(<span class="hljs-string">&quot;3d_cake.glb&quot;</span>, file_type=<span class="hljs-string">&quot;glb&quot;</span>)`}}),{c(){m=l("meta"),D=h(),u=l("h1"),T=l("a"),W=l("span"),d(j.$$.fragment),H=h(),B=l("span"),$=r("Shap-E"),v=h(),d(I.$$.fragment),L=h(),ge=l("p"),Ps=r("Shap-E is a conditional model for generating 3D assets which could be used for video game development, interior design, and architecture. It is trained on a large dataset of 3D assets, and post-processed to render more views of each object and produce 16K instead of 4K point clouds. The Shap-E model is trained in two steps:"),os=h(),x=l("ol"),xe=l("li"),Hs=r("a encoder accepts the point clouds and rendered views of a 3D asset and outputs the parameters of implicit functions that represent the asset"),Ls=h(),ze=l("li"),Ks=r("a diffusion model is trained on the latents produced by the encoder to generate either neural radiance fields (NeRFs) or a textured 3D mesh, making it easier to render and use the 3D asset in downstream applications"),is=h(),be=l("p"),Os=r("This guide will show you how to use Shap-E to start generating your own 3D assets!"),rs=h(),we=l("p"),et=r("Before you begin, make sure you have the following libraries installed:"),ns=h(),d(K.$$.fragment),ps=h(),G=l("h2"),z=l("a"),Ne=l("span"),d(O.$$.fragment),st=h(),Xe=l("span"),tt=r("Text-to-3D"),cs=h(),N=l("p"),at=r("To generate a gif of a 3D object, pass a text prompt to the "),Je=l("a"),lt=r("ShapEPipeline"),ot=r(". The pipeline generates a list of image frames which are used to create the 3D object."),hs=h(),d(ee.$$.fragment),fs=h(),X=l("p"),it=r("Now use the "),Me=l("a"),rt=r("export_to_gif()"),nt=r(" function to turn the list of image frames into a gif of the 3D object."),ms=h(),d(se.$$.fragment),us=h(),S=l("div"),te=l("div"),je=l("img"),pt=h(),ve=l("figcaption"),ct=r("firecracker"),ht=h(),ae=l("div"),Te=l("img"),ft=h(),_e=l("figcaption"),mt=r("cupcake"),ds=h(),V=l("h2"),F=l("a"),Fe=l("span"),d(le.$$.fragment),ut=h(),qe=l("span"),dt=r("Image-to-3D"),ys=h(),Z=l("p"),yt=r("To generate a 3D object from another image, use the "),Ie=l("a"),gt=r("ShapEImg2ImgPipeline"),bt=r(". You can use an existing image or generate an entirely new one. Let\u2019s use the the "),Ze=l("a"),wt=r("Kandinsky 2.1"),Jt=r(" model to generate a new image."),gs=h(),d(oe.$$.fragment),bs=h(),q=l("p"),Mt=r("Pass the cheeseburger to the "),Ee=l("a"),jt=r("ShapEImg2ImgPipeline"),vt=r(" to generate a 3D representation of it."),ws=h(),d(ie.$$.fragment),Js=h(),R=l("div"),re=l("div"),Ue=l("img"),Tt=h(),ke=l("figcaption"),_t=r("cheeseburger"),It=h(),ne=l("div"),We=l("img"),Zt=h(),Be=l("figcaption"),Et=r("3D cheeseburger"),Ms=h(),Y=l("h2"),Q=l("a"),Qe=l("span"),d(pe.$$.fragment),Ut=h(),Ae=l("span"),kt=r("Generate mesh"),js=h(),_=l("p"),Wt=r("Shap-E is a flexible model that can also generate textured mesh outputs to be rendered for downstream applications. In this example, you\u2019ll convert the output into a "),Pe=l("code"),Bt=r("glb"),$t=r(" file because the \u{1F917} Datasets library supports mesh visualization of "),He=l("code"),Gt=r("glb"),St=r(" files which can be rendered by the "),ce=l("a"),Vt=r("Dataset viewer"),Rt=r("."),vs=h(),M=l("p"),Yt=r("You can generate mesh outputs for both the "),$e=l("a"),Ct=r("ShapEPipeline"),Dt=r(" and "),Ge=l("a"),xt=r("ShapEImg2ImgPipeline"),zt=r(" by specifying the "),Le=l("code"),Nt=r("output_type"),Xt=r(" parameter as "),Ke=l("code"),Ft=r('"mesh"'),qt=r(":"),Ts=h(),d(he.$$.fragment),_s=h(),E=l("p"),Qt=r("Use the "),Oe=l("code"),At=r("export_to_ply()"),Pt=r(" function to save the mesh output as a "),es=l("code"),Ht=r("ply"),Lt=r(" file:"),Is=h(),d(A.$$.fragment),Zs=h(),d(fe.$$.fragment),Es=h(),U=l("p"),Kt=r("Then you can convert the "),ss=l("code"),Ot=r("ply"),ea=r(" file to a "),ts=l("code"),sa=r("glb"),ta=r(" file with the trimesh library:"),Us=h(),d(me.$$.fragment),ks=h(),Se=l("p"),aa=r("By default, the mesh output is focused from the bottom viewpoint but you can change the default viewpoint by applying a rotation transform:"),Ws=h(),d(ue.$$.fragment),Bs=h(),Ve=l("p"),la=r("Upload the mesh file to your dataset repository to visualize it with the Dataset viewer!"),$s=h(),de=l("div"),Re=l("img"),this.h()},l(e){const a=Oa('[data-svelte="svelte-1phssyn"]',document.head);m=o(a,"META",{name:!0,content:!0}),a.forEach(s),D=f(e),u=o(e,"H1",{class:!0});var ye=i(u);T=o(ye,"A",{id:!0,class:!0,href:!0});var ca=i(T);W=o(ca,"SPAN",{});var ha=i(W);y(j.$$.fragment,ha),ha.forEach(s),ca.forEach(s),H=f(ye),B=o(ye,"SPAN",{});var fa=i(B);$=n(fa,"Shap-E"),fa.forEach(s),ye.forEach(s),v=f(e),y(I.$$.fragment,e),L=f(e),ge=o(e,"P",{});var ma=i(ge);Ps=n(ma,"Shap-E is a conditional model for generating 3D assets which could be used for video game development, interior design, and architecture. It is trained on a large dataset of 3D assets, and post-processed to render more views of each object and produce 16K instead of 4K point clouds. The Shap-E model is trained in two steps:"),ma.forEach(s),os=f(e),x=o(e,"OL",{});var Ss=i(x);xe=o(Ss,"LI",{});var ua=i(xe);Hs=n(ua,"a encoder accepts the point clouds and rendered views of a 3D asset and outputs the parameters of implicit functions that represent the asset"),ua.forEach(s),Ls=f(Ss),ze=o(Ss,"LI",{});var da=i(ze);Ks=n(da,"a diffusion model is trained on the latents produced by the encoder to generate either neural radiance fields (NeRFs) or a textured 3D mesh, making it easier to render and use the 3D asset in downstream applications"),da.forEach(s),Ss.forEach(s),is=f(e),be=o(e,"P",{});var ya=i(be);Os=n(ya,"This guide will show you how to use Shap-E to start generating your own 3D assets!"),ya.forEach(s),rs=f(e),we=o(e,"P",{});var ga=i(we);et=n(ga,"Before you begin, make sure you have the following libraries installed:"),ga.forEach(s),ns=f(e),y(K.$$.fragment,e),ps=f(e),G=o(e,"H2",{class:!0});var Vs=i(G);z=o(Vs,"A",{id:!0,class:!0,href:!0});var ba=i(z);Ne=o(ba,"SPAN",{});var wa=i(Ne);y(O.$$.fragment,wa),wa.forEach(s),ba.forEach(s),st=f(Vs),Xe=o(Vs,"SPAN",{});var Ja=i(Xe);tt=n(Ja,"Text-to-3D"),Ja.forEach(s),Vs.forEach(s),cs=f(e),N=o(e,"P",{});var Rs=i(N);at=n(Rs,"To generate a gif of a 3D object, pass a text prompt to the "),Je=o(Rs,"A",{href:!0});var Ma=i(Je);lt=n(Ma,"ShapEPipeline"),Ma.forEach(s),ot=n(Rs,". The pipeline generates a list of image frames which are used to create the 3D object."),Rs.forEach(s),hs=f(e),y(ee.$$.fragment,e),fs=f(e),X=o(e,"P",{});var Ys=i(X);it=n(Ys,"Now use the "),Me=o(Ys,"A",{href:!0});var ja=i(Me);rt=n(ja,"export_to_gif()"),ja.forEach(s),nt=n(Ys," function to turn the list of image frames into a gif of the 3D object."),Ys.forEach(s),ms=f(e),y(se.$$.fragment,e),us=f(e),S=o(e,"DIV",{class:!0});var Cs=i(S);te=o(Cs,"DIV",{});var Ds=i(te);je=o(Ds,"IMG",{class:!0,src:!0}),pt=f(Ds),ve=o(Ds,"FIGCAPTION",{class:!0});var va=i(ve);ct=n(va,"firecracker"),va.forEach(s),Ds.forEach(s),ht=f(Cs),ae=o(Cs,"DIV",{});var xs=i(ae);Te=o(xs,"IMG",{class:!0,src:!0}),ft=f(xs),_e=o(xs,"FIGCAPTION",{class:!0});var Ta=i(_e);mt=n(Ta,"cupcake"),Ta.forEach(s),xs.forEach(s),Cs.forEach(s),ds=f(e),V=o(e,"H2",{class:!0});var zs=i(V);F=o(zs,"A",{id:!0,class:!0,href:!0});var _a=i(F);Fe=o(_a,"SPAN",{});var Ia=i(Fe);y(le.$$.fragment,Ia),Ia.forEach(s),_a.forEach(s),ut=f(zs),qe=o(zs,"SPAN",{});var Za=i(qe);dt=n(Za,"Image-to-3D"),Za.forEach(s),zs.forEach(s),ys=f(e),Z=o(e,"P",{});var Ye=i(Z);yt=n(Ye,"To generate a 3D object from another image, use the "),Ie=o(Ye,"A",{href:!0});var Ea=i(Ie);gt=n(Ea,"ShapEImg2ImgPipeline"),Ea.forEach(s),bt=n(Ye,". You can use an existing image or generate an entirely new one. Let\u2019s use the the "),Ze=o(Ye,"A",{href:!0});var Ua=i(Ze);wt=n(Ua,"Kandinsky 2.1"),Ua.forEach(s),Jt=n(Ye," model to generate a new image."),Ye.forEach(s),gs=f(e),y(oe.$$.fragment,e),bs=f(e),q=o(e,"P",{});var Ns=i(q);Mt=n(Ns,"Pass the cheeseburger to the "),Ee=o(Ns,"A",{href:!0});var ka=i(Ee);jt=n(ka,"ShapEImg2ImgPipeline"),ka.forEach(s),vt=n(Ns," to generate a 3D representation of it."),Ns.forEach(s),ws=f(e),y(ie.$$.fragment,e),Js=f(e),R=o(e,"DIV",{class:!0});var Xs=i(R);re=o(Xs,"DIV",{});var Fs=i(re);Ue=o(Fs,"IMG",{class:!0,src:!0}),Tt=f(Fs),ke=o(Fs,"FIGCAPTION",{class:!0});var Wa=i(ke);_t=n(Wa,"cheeseburger"),Wa.forEach(s),Fs.forEach(s),It=f(Xs),ne=o(Xs,"DIV",{});var qs=i(ne);We=o(qs,"IMG",{class:!0,src:!0}),Zt=f(qs),Be=o(qs,"FIGCAPTION",{class:!0});var Ba=i(Be);Et=n(Ba,"3D cheeseburger"),Ba.forEach(s),qs.forEach(s),Xs.forEach(s),Ms=f(e),Y=o(e,"H2",{class:!0});var Qs=i(Y);Q=o(Qs,"A",{id:!0,class:!0,href:!0});var $a=i(Q);Qe=o($a,"SPAN",{});var Ga=i(Qe);y(pe.$$.fragment,Ga),Ga.forEach(s),$a.forEach(s),Ut=f(Qs),Ae=o(Qs,"SPAN",{});var Sa=i(Ae);kt=n(Sa,"Generate mesh"),Sa.forEach(s),Qs.forEach(s),js=f(e),_=o(e,"P",{});var P=i(_);Wt=n(P,"Shap-E is a flexible model that can also generate textured mesh outputs to be rendered for downstream applications. In this example, you\u2019ll convert the output into a "),Pe=o(P,"CODE",{});var Va=i(Pe);Bt=n(Va,"glb"),Va.forEach(s),$t=n(P," file because the \u{1F917} Datasets library supports mesh visualization of "),He=o(P,"CODE",{});var Ra=i(He);Gt=n(Ra,"glb"),Ra.forEach(s),St=n(P," files which can be rendered by the "),ce=o(P,"A",{href:!0,rel:!0});var Ya=i(ce);Vt=n(Ya,"Dataset viewer"),Ya.forEach(s),Rt=n(P,"."),P.forEach(s),vs=f(e),M=o(e,"P",{});var k=i(M);Yt=n(k,"You can generate mesh outputs for both the "),$e=o(k,"A",{href:!0});var Ca=i($e);Ct=n(Ca,"ShapEPipeline"),Ca.forEach(s),Dt=n(k," and "),Ge=o(k,"A",{href:!0});var Da=i(Ge);xt=n(Da,"ShapEImg2ImgPipeline"),Da.forEach(s),zt=n(k," by specifying the "),Le=o(k,"CODE",{});var xa=i(Le);Nt=n(xa,"output_type"),xa.forEach(s),Xt=n(k," parameter as "),Ke=o(k,"CODE",{});var za=i(Ke);Ft=n(za,'"mesh"'),za.forEach(s),qt=n(k,":"),k.forEach(s),Ts=f(e),y(he.$$.fragment,e),_s=f(e),E=o(e,"P",{});var Ce=i(E);Qt=n(Ce,"Use the "),Oe=o(Ce,"CODE",{});var Na=i(Oe);At=n(Na,"export_to_ply()"),Na.forEach(s),Pt=n(Ce," function to save the mesh output as a "),es=o(Ce,"CODE",{});var Xa=i(es);Ht=n(Xa,"ply"),Xa.forEach(s),Lt=n(Ce," file:"),Ce.forEach(s),Is=f(e),y(A.$$.fragment,e),Zs=f(e),y(fe.$$.fragment,e),Es=f(e),U=o(e,"P",{});var De=i(U);Kt=n(De,"Then you can convert the "),ss=o(De,"CODE",{});var Fa=i(ss);Ot=n(Fa,"ply"),Fa.forEach(s),ea=n(De," file to a "),ts=o(De,"CODE",{});var qa=i(ts);sa=n(qa,"glb"),qa.forEach(s),ta=n(De," file with the trimesh library:"),De.forEach(s),Us=f(e),y(me.$$.fragment,e),ks=f(e),Se=o(e,"P",{});var Qa=i(Se);aa=n(Qa,"By default, the mesh output is focused from the bottom viewpoint but you can change the default viewpoint by applying a rotation transform:"),Qa.forEach(s),Ws=f(e),y(ue.$$.fragment,e),Bs=f(e),Ve=o(e,"P",{});var Aa=i(Ve);la=n(Aa,"Upload the mesh file to your dataset repository to visualize it with the Dataset viewer!"),Aa.forEach(s),$s=f(e),de=o(e,"DIV",{class:!0});var Pa=i(de);Re=o(Pa,"IMG",{class:!0,src:!0}),Pa.forEach(s),this.h()},h(){c(m,"name","hf:doc:metadata"),c(m,"content",JSON.stringify(ol)),c(T,"id","shape"),c(T,"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"),c(T,"href","#shape"),c(u,"class","relative group"),c(z,"id","textto3d"),c(z,"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"),c(z,"href","#textto3d"),c(G,"class","relative group"),c(Je,"href","/docs/diffusers/v0.21.0/en/api/pipelines/shap_e#diffusers.ShapEPipeline"),c(Me,"href","/docs/diffusers/v0.21.0/en/api/utilities#diffusers.utils.export_to_gif"),c(je,"class","rounded-xl"),as(je.src,oa="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/shap_e/firecracker_out.gif")||c(je,"src",oa),c(ve,"class","mt-2 text-center text-sm text-gray-500"),c(Te,"class","rounded-xl"),as(Te.src,ia="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/shap_e/cake_out.gif")||c(Te,"src",ia),c(_e,"class","mt-2 text-center text-sm text-gray-500"),c(S,"class","flex gap-4"),c(F,"id","imageto3d"),c(F,"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"),c(F,"href","#imageto3d"),c(V,"class","relative group"),c(Ie,"href","/docs/diffusers/v0.21.0/en/api/pipelines/shap_e#diffusers.ShapEImg2ImgPipeline"),c(Ze,"href","../api/pipelines/kandinsky"),c(Ee,"href","/docs/diffusers/v0.21.0/en/api/pipelines/shap_e#diffusers.ShapEImg2ImgPipeline"),c(Ue,"class","rounded-xl"),as(Ue.src,ra="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/shap_e/burger_in.png")||c(Ue,"src",ra),c(ke,"class","mt-2 text-center text-sm text-gray-500"),c(We,"class","rounded-xl"),as(We.src,na="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/shap_e/burger_out.gif")||c(We,"src",na),c(Be,"class","mt-2 text-center text-sm text-gray-500"),c(R,"class","flex gap-4"),c(Q,"id","generate-mesh"),c(Q,"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"),c(Q,"href","#generate-mesh"),c(Y,"class","relative group"),c(ce,"href","https://huggingface.co/docs/hub/datasets-viewer#dataset-preview"),c(ce,"rel","nofollow"),c($e,"href","/docs/diffusers/v0.21.0/en/api/pipelines/shap_e#diffusers.ShapEPipeline"),c(Ge,"href","/docs/diffusers/v0.21.0/en/api/pipelines/shap_e#diffusers.ShapEImg2ImgPipeline"),c(Re,"class","rounded-xl"),as(Re.src,pa="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/3D-cake.gif")||c(Re,"src",pa),c(de,"class","flex justify-center")},m(e,a){t(document.head,m),p(e,D,a),p(e,u,a),t(u,T),t(T,W),g(j,W,null),t(u,H),t(u,B),t(B,$),p(e,v,a),g(I,e,a),p(e,L,a),p(e,ge,a),t(ge,Ps),p(e,os,a),p(e,x,a),t(x,xe),t(xe,Hs),t(x,Ls),t(x,ze),t(ze,Ks),p(e,is,a),p(e,be,a),t(be,Os),p(e,rs,a),p(e,we,a),t(we,et),p(e,ns,a),g(K,e,a),p(e,ps,a),p(e,G,a),t(G,z),t(z,Ne),g(O,Ne,null),t(G,st),t(G,Xe),t(Xe,tt),p(e,cs,a),p(e,N,a),t(N,at),t(N,Je),t(Je,lt),t(N,ot),p(e,hs,a),g(ee,e,a),p(e,fs,a),p(e,X,a),t(X,it),t(X,Me),t(Me,rt),t(X,nt),p(e,ms,a),g(se,e,a),p(e,us,a),p(e,S,a),t(S,te),t(te,je),t(te,pt),t(te,ve),t(ve,ct),t(S,ht),t(S,ae),t(ae,Te),t(ae,ft),t(ae,_e),t(_e,mt),p(e,ds,a),p(e,V,a),t(V,F),t(F,Fe),g(le,Fe,null),t(V,ut),t(V,qe),t(qe,dt),p(e,ys,a),p(e,Z,a),t(Z,yt),t(Z,Ie),t(Ie,gt),t(Z,bt),t(Z,Ze),t(Ze,wt),t(Z,Jt),p(e,gs,a),g(oe,e,a),p(e,bs,a),p(e,q,a),t(q,Mt),t(q,Ee),t(Ee,jt),t(q,vt),p(e,ws,a),g(ie,e,a),p(e,Js,a),p(e,R,a),t(R,re),t(re,Ue),t(re,Tt),t(re,ke),t(ke,_t),t(R,It),t(R,ne),t(ne,We),t(ne,Zt),t(ne,Be),t(Be,Et),p(e,Ms,a),p(e,Y,a),t(Y,Q),t(Q,Qe),g(pe,Qe,null),t(Y,Ut),t(Y,Ae),t(Ae,kt),p(e,js,a),p(e,_,a),t(_,Wt),t(_,Pe),t(Pe,Bt),t(_,$t),t(_,He),t(He,Gt),t(_,St),t(_,ce),t(ce,Vt),t(_,Rt),p(e,vs,a),p(e,M,a),t(M,Yt),t(M,$e),t($e,Ct),t(M,Dt),t(M,Ge),t(Ge,xt),t(M,zt),t(M,Le),t(Le,Nt),t(M,Xt),t(M,Ke),t(Ke,Ft),t(M,qt),p(e,Ts,a),g(he,e,a),p(e,_s,a),p(e,E,a),t(E,Qt),t(E,Oe),t(Oe,At),t(E,Pt),t(E,es),t(es,Ht),t(E,Lt),p(e,Is,a),g(A,e,a),p(e,Zs,a),g(fe,e,a),p(e,Es,a),p(e,U,a),t(U,Kt),t(U,ss),t(ss,Ot),t(U,ea),t(U,ts),t(ts,sa),t(U,ta),p(e,Us,a),g(me,e,a),p(e,ks,a),p(e,Se,a),t(Se,aa),p(e,Ws,a),g(ue,e,a),p(e,Bs,a),p(e,Ve,a),t(Ve,la),p(e,$s,a),p(e,de,a),t(de,Re),Gs=!0},p(e,[a]){const ye={};a&2&&(ye.$$scope={dirty:a,ctx:e}),A.$set(ye)},i(e){Gs||(b(j.$$.fragment,e),b(I.$$.fragment,e),b(K.$$.fragment,e),b(O.$$.fragment,e),b(ee.$$.fragment,e),b(se.$$.fragment,e),b(le.$$.fragment,e),b(oe.$$.fragment,e),b(ie.$$.fragment,e),b(pe.$$.fragment,e),b(he.$$.fragment,e),b(A.$$.fragment,e),b(fe.$$.fragment,e),b(me.$$.fragment,e),b(ue.$$.fragment,e),Gs=!0)},o(e){w(j.$$.fragment,e),w(I.$$.fragment,e),w(K.$$.fragment,e),w(O.$$.fragment,e),w(ee.$$.fragment,e),w(se.$$.fragment,e),w(le.$$.fragment,e),w(oe.$$.fragment,e),w(ie.$$.fragment,e),w(pe.$$.fragment,e),w(he.$$.fragment,e),w(A.$$.fragment,e),w(fe.$$.fragment,e),w(me.$$.fragment,e),w(ue.$$.fragment,e),Gs=!1},d(e){s(m),e&&s(D),e&&s(u),J(j),e&&s(v),J(I,e),e&&s(L),e&&s(ge),e&&s(os),e&&s(x),e&&s(is),e&&s(be),e&&s(rs),e&&s(we),e&&s(ns),J(K,e),e&&s(ps),e&&s(G),J(O),e&&s(cs),e&&s(N),e&&s(hs),J(ee,e),e&&s(fs),e&&s(X),e&&s(ms),J(se,e),e&&s(us),e&&s(S),e&&s(ds),e&&s(V),J(le),e&&s(ys),e&&s(Z),e&&s(gs),J(oe,e),e&&s(bs),e&&s(q),e&&s(ws),J(ie,e),e&&s(Js),e&&s(R),e&&s(Ms),e&&s(Y),J(pe),e&&s(js),e&&s(_),e&&s(vs),e&&s(M),e&&s(Ts),J(he,e),e&&s(_s),e&&s(E),e&&s(Is),J(A,e),e&&s(Zs),J(fe,e),e&&s(Es),e&&s(U),e&&s(Us),J(me,e),e&&s(ks),e&&s(Se),e&&s(Ws),J(ue,e),e&&s(Bs),e&&s(Ve),e&&s($s),e&&s(de)}}}const ol={local:"shape",sections:[{local:"textto3d",title:"Text-to-3D"},{local:"imageto3d",title:"Image-to-3D"},{local:"generate-mesh",title:"Generate mesh"}],title:"Shap-E"};function il(ls){return el(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class fl extends Ha{constructor(m){super();La(this,m,il,ll,Ka,{})}}export{fl as default,ol as metadata};
