import{s as Ze,n as ue,o as Be}from"../chunks/scheduler.1f027d5a.js";import{S as Ce,i as Ge,e as n,s as t,c as p,h as We,a as y,d as e,b as a,f as re,g as w,j as J,k as he,l as fe,m as s,n as U,t as i,o as T,p as j}from"../chunks/index.6117a65d.js";import{D as Ve,C as m}from"../chunks/DocNotebookDropdown.316c3715.js";import{H as o,E as Xe}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.0eecd2bb.js";function Ae(HM){let c,Wl,Cl,fl,d,Vl,I,Xl,b,YM='<em>作者: <a href="https://github.com/AkiRusProd" rel="nofollow">Rustam Akimov</a></em>',Al,r,QM="这个 notebook 展示了如何使用 Stable Diffusion 来对图像进行插值。使用 Stable Diffusion 的图像插值是通过基于扩散的生成模型，从一张给定的图像平滑过渡到另一张图像，创建中间图像的过程。",gl,h,SM="以下是一些使用 Stable Diffusion 进行图像插值的不同应用场景：",Rl,Z,NM="<li>数据增强： Stable Diffusion 可以通过生成介于现有数据点之间的合成图像，来增强机器学习模型的训练数据。这可以提高机器学习模型的一般化和鲁棒性，特别是在图像生成、分类或对象检测等任务中。</li> <li>产品设计和原型制作： Stable Diffusion 可以通过生成具有微妙差异的产品设计或原型变体，来辅助产品设计。这对于探索设计替代方案、进行用户研究或在投入物理原型之前可视化设计迭代非常有用。</li> <li>媒体制作内容生成：在媒体制作中，如电影和视频编辑， Stable Diffusion 可以用来生成关键帧之间的中间帧，实现更平滑的过渡并增强视觉叙事。与手动逐帧编辑相比，这可以节省时间和资源。</li>",kl,u,FM="在图像插值的背景下， Stable Diffusion 模型通常用于在多维潜在空间中导航。每个维度代表模型学到的特定特征。通过在这个潜在空间中行走并在不同图像的潜在表示之间进行插值，模型能够生成一系列中间图像，这些图像显示了原始图像之间的平滑过渡。 Stable Diffusion 中有两种类型的潜在：提示潜在和图像潜在。",vl,B,xM="潜在空间行走涉及沿着由两个或多个点（代表图像）定义的路径在潜在空间中移动。通过仔细选择这些点和它们之间的路径，可以控制生成图像的特征，如风格、内容和其他视觉方面。",El,C,zM="在这个 notebook 中，我们将探索使用 Stable Diffusion 进行图像插值的示例，并展示如何实现和利用潜在空间行走来创建图像之间的平滑过渡。我们将提供代码片段和可视化来展示这个过程的效果，从而更深入地理解生成模型如何以有意义的方式操纵和转化图像表示。",_l,G,$M="首先，让我们安装所有需要的模块",Hl,W,Yl,f,DM="导入模块",Ql,V,Sl,X,LM="让我们查看一下 CUDA 是否可用",Nl,A,Fl,g,qM="这些设置用于优化在启用 CUDA 的 GPU 上 PyTorch 模型的性能，尤其是在使用混合精度训练或推理时，这在速度和内存使用方面可能有益。",xl,R,KM='来源：<a href="https://huggingface.co/docs/diffusers/optimization/fp16#memory-efficient-attention" rel="nofollow">https://huggingface.co/docs/diffusers/optimization/fp16#memory-efficient-attention</a>',zl,k,$l,v,Dl,E,PM='我们在这个项目中使用了 <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow"><code>runwayml/stable-diffusion-v1-5</code></a> 模型和 <a href="https://huggingface.co/docs/diffusers/en/api/schedulers/lms_discrete" rel="nofollow"><code>LMSDiscreteScheduler</code></a> 调度器来生成图片。尽管这个模型已经不是最新的技术，但因为它的速度快、对内存的需求小，而且有很多社区成员基于这个版本改进的模型，所以还是挺受欢迎的。当然，如果你想尝试其他模型或调度器来生成图片，也是可以的。',Ll,_,ql,H,OM="这些方法旨在减少 GPU 消耗的内存。如果你有足够的显存，可以跳过这个步骤。",Kl,Y,le=`更详细的信息可以在这里找到：<a href="https://huggingface.co/docs/diffusers/en/optimization/opt_overview" rel="nofollow">https://huggingface.co/docs/diffusers/en/optimization/opt_overview</a><br/>
特别是，关于以下方法的信息可以在这里找到：<a href="https://huggingface.co/docs/diffusers/optimization/memory" rel="nofollow">https://huggingface.co/docs/diffusers/optimization/memory</a>`,Pl,Q,Ol,S,Me="<code>display_images</code> 函数将图像数组的列表转换成 GIF，保存到指定路径，并返回 GIF 对象以供显示。它使用当前时间来命名 GIF 文件，并通过打印出来处理任何错误。",lM,N,MM,F,eM,x,ee="<li><code>seed</code>: 这个变量用于设置一个特定的随机种子，以便复现结果。</li> <li><code>generator</code>: 如果提供了种子，这将设置为一个 PyTorch 随机数生成器对象，否则为 None。它确保使用它的操作具有可复现的结果。</li> <li><code>guidance_scale</code>: 这个参数控制模型在文本到图像生成任务中遵循提示的程度，值越高，对提示的遵循越强。</li> <li><code>num_inference_steps</code>: 这指定了模型生成图像所需的步骤数。更多的步骤可以导致生成更高质量的图像，但生成时间会更长。</li> <li><code>num_interpolation_steps</code>: 这决定了在潜在空间中两点之间插值时使用的步骤数，影响生成动画中过渡的平滑度。</li> <li><code>height</code>: 生成图像的高度，以像素为单位。</li> <li><code>width</code>: 生成图像的宽度，以像素为单位。</li> <li><code>save_path</code>: 生成的 GIF 将保存的文件系统路径。</li>",sM,z,tM,$,aM,D,se="在这个例子中，我们将通过在积极提示和消极提示之间进行插值，来探索这两个提示定义的概念之间的空间。这样做可以让我们看到一系列逐渐融合这两种提示特征的图像。具体来说，我们会修改原始提示的嵌入向量，逐渐添加一些小的变化，从而创建出一系列新的提示嵌入。这些新的嵌入将被用来生成图像，这些图像会平滑地从一种提示的状态过渡到另一种。",nM,L,te='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/sd_interpolation_1.gif" alt="Example 1"/>',yM,q,ae="首先，我们需要对积极和消极的文本提示进行标记化并获得它们的嵌入。积极提示引导图像生成朝向期望的特征，而消极提示则使其远离不希望出现的特征。",JM,K,pM,P,ne="现在让我们来看看生成随机初始向量的代码部分，该向量使用正态分布生成，其结构符合扩散模型（UNet）预期的维度。这允许通过可选地使用随机数生成器来复现结果。创建了初始向量后，代码通过每次迭代增量地添加一个小步长，在两个嵌入（积极和消极提示）之间进行一系列插值。结果存储在一个名为 “walked_embeddings” 的列表中。",wM,O,UM,ll,ye="最后，让我们根据插值嵌入生成一系列图像，然后显示这些图像。我们将遍历一个嵌入数组，使用每个嵌入生成具有指定特征（如高度、宽度以及与图像生成相关的其他参数）的图像。然后我们将这些图像收集到一个列表中。一旦生成完成，我们将调用 <code>display_image</code> 函数，以在给定的保存路径上将这些图像保存并显示为 GIF。",iM,Ml,TM,el,jM,sl,Je="与第一个示例不同，在这个示例中，我们是在扩散模型本身的两个嵌入之间执行插值，而不是在提示之间。请注意，在这种情况下，我们使用 slerp 函数进行插值。然而，这并不妨碍我们在一个嵌入中添加一个常数。",mM,tl,pe='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/sd_interpolation_2.gif" alt="Example 2"/>',cM,al,we="下面呈现的函数代表球面线性插值（Spherical Linear Interpolation）。这是一种在球面上进行插值的方法。这个函数在计算机图形学中常用于平滑地动画旋转，并且也可以用于机器学习中高维数据点之间的插值，比如生成模型中使用的潜在向量。",oM,nl,Ue=`该函数的来源是 Andrej Karpathy 的 gist：<a href="https://gist.github.com/karpathy/00103b0037c5aaea32fe1da1af553355%E3%80%82" rel="nofollow">https://gist.github.com/karpathy/00103b0037c5aaea32fe1da1af553355。</a><br/>
关于这种方法更详细的解释可以在：<a href="https://en.wikipedia.org/wiki/Slerp" rel="nofollow">https://en.wikipedia.org/wiki/Slerp</a> 找到。`,dM,yl,IM,Jl,bM,pl,rM,wl,ie="与第一个示例中我们从一个提示移动开来不同，在这个示例中，我们将对任意数量的提示进行插值。为此，我们将取连续的提示对，并创建它们之间的平滑过渡。然后，我们将这些连续对的插值组合起来，并指示模型基于它们生成图像。我们将使用第二个示例中的 slerp 函数进行插值。",hM,Ul,Te='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/sd_interpolation_3.gif" alt="Example 3"/>',ZM,il,je="再次，让我们对多个积极和消极的文本提示进行标记化并获得它们的嵌入。",uM,Tl,BM,jl,me="如前所述，我们将使用 <code>slerp</code> 函数对连续的提示对创建平滑过渡。",CM,ml,GM,cl,ce="最后，我们需要根据嵌入生成图像。",WM,ol,fM,dl,VM,Il,oe='这个示例来自：<a href="https://keras.io/examples/generative/random_walks_with_stable_diffusion/" rel="nofollow">https://keras.io/examples/generative/random_walks_with_stable_diffusion/</a>',XM,bl,de="假设我们有两个噪声成分，我们称之为 x 和 y。我们从 0 移动到 2π，在每一步中，我们将 x 的余弦和 y 的正弦加到结果中。使用这种方法，在我们的移动结束时，我们得到了与开始时相同的噪声值。这意味着向量最终转变成它们自己，结束了我们的移动。",AM,rl,Ie='<img src="https://huggingface.co/datasets/huggingface/cookbook-images/resolve/main/sd_interpolation_4.gif" alt="Example 4"/>',gM,hl,RM,Zl,kM,ul,be="接下来，您可以探索各种参数，如指导比例（guidance scale）、种子（seed）和插值步骤数（number of interpolation steps），以观察它们如何影响生成的图像。此外，尝试使用不同的提示和调度器来进一步优化你的结果。另一个有价值的步骤是实施线性插值（<code>linspace</code>），而不是球面线性插值（<code>slerp</code>），并比较结果，以更深入地了解插值过程。",vM,Bl,EM,Gl,_M;return d=new Ve({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Google Colab",value:"https://colab.research.google.com/github/huggingface/cookbook/blob/main/notebooks/zh-CN/stable_diffusion_interpolation.ipynb"}]}}),I=new o({props:{title:"使用 Stable Diffusion 进行图像插值",local:"使用-stable-diffusion-进行图像插值",headingTag:"h2"}}),W=new m({props:{code:"IXBpcCUyMGluc3RhbGwlMjAtcSUyMGRpZmZ1c2VycyUyMHRyYW5zZm9ybWVycyUyMHhmb3JtZXJzJTIwYWNjZWxlcmF0ZSUwQSFwaXAlMjBpbnN0YWxsJTIwLXElMjBudW1weSUyMHNjaXB5JTIwZnRmeSUyMFBpbGxvdw==",highlighted:`!pip install -q diffusers transformers xformers accelerate
!pip install -q numpy scipy ftfy Pillow`,wrap:!1}}),V=new m({props:{code:"aW1wb3J0JTIwdG9yY2glMEFpbXBvcnQlMjBudW1weSUyMGFzJTIwbnAlMEFpbXBvcnQlMjBvcyUwQSUwQWltcG9ydCUyMHRpbWUlMEElMEFmcm9tJTIwUElMJTIwaW1wb3J0JTIwSW1hZ2UlMEFmcm9tJTIwSVB5dGhvbiUyMGltcG9ydCUyMGRpc3BsYXklMjBhcyUyMElQZGlzcGxheSUwQWZyb20lMjB0cWRtLmF1dG8lMjBpbXBvcnQlMjB0cWRtJTBBJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMCglMEElMjAlMjAlMjAlMjBERElNU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwUE5ETVNjaGVkdWxlciUyQyUwQSUyMCUyMCUyMCUyMExNU0Rpc2NyZXRlU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwRFBNU29sdmVyTXVsdGlzdGVwU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwRXVsZXJBbmNlc3RyYWxEaXNjcmV0ZVNjaGVkdWxlciUyQyUwQSUyMCUyMCUyMCUyMEV1bGVyRGlzY3JldGVTY2hlZHVsZXIlMkMlMEEpJTBBZnJvbSUyMHRyYW5zZm9ybWVycyUyMGltcG9ydCUyMGxvZ2dpbmclMEElMEFsb2dnaW5nLnNldF92ZXJib3NpdHlfZXJyb3IoKQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">import</span> os

<span class="hljs-keyword">import</span> time

<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image
<span class="hljs-keyword">from</span> IPython <span class="hljs-keyword">import</span> display <span class="hljs-keyword">as</span> IPdisplay
<span class="hljs-keyword">from</span> tqdm.auto <span class="hljs-keyword">import</span> tqdm

<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> (
    DDIMScheduler,
    PNDMScheduler,
    LMSDiscreteScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
)
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> logging

logging.set_verbosity_error()`,wrap:!1}}),A=new m({props:{code:"cHJpbnQodG9yY2guY3VkYS5pc19hdmFpbGFibGUoKSklMEElMEFkZXZpY2UlMjAlM0QlMjB0b3JjaC5kZXZpY2UoJTIyY3VkYSUyMiklMjBpZiUyMHRvcmNoLmN1ZGEuaXNfYXZhaWxhYmxlKCklMjBlbHNlJTIwdG9yY2guZGV2aWNlKCUyMmNwdSUyMik=",highlighted:`<span class="hljs-built_in">print</span>(torch.cuda.is_available())

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> torch.device(<span class="hljs-string">&quot;cpu&quot;</span>)`,wrap:!1}}),k=new m({props:{code:"dG9yY2guYmFja2VuZHMuY3Vkbm4uYmVuY2htYXJrJTIwJTNEJTIwVHJ1ZSUwQXRvcmNoLmJhY2tlbmRzLmN1ZGEubWF0bXVsLmFsbG93X3RmMzIlMjAlM0QlMjBUcnVl",highlighted:`torch.backends.cudnn.benchmark = <span class="hljs-literal">True</span>
torch.backends.cuda.matmul.allow_tf32 = <span class="hljs-literal">True</span>`,wrap:!1}}),v=new o({props:{title:"模型",local:"模型",headingTag:"h3"}}),_=new m({props:{code:"bW9kZWxfbmFtZV9vcl9wYXRoJTIwJTNEJTIwJTIycnVud2F5bWwlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUlMjIlMEElMEFzY2hlZHVsZXIlMjAlM0QlMjBMTVNEaXNjcmV0ZVNjaGVkdWxlcihiZXRhX3N0YXJ0JTNEMC4wMDA4NSUyQyUyMGJldGFfZW5kJTNEMC4wMTIlMkMlMjBiZXRhX3NjaGVkdWxlJTNEJTIyc2NhbGVkX2xpbmVhciUyMiUyQyUyMG51bV90cmFpbl90aW1lc3RlcHMlM0QxMDAwKSUwQSUwQSUwQXBpcGUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwbW9kZWxfbmFtZV9vcl9wYXRoJTJDJTBBJTIwJTIwJTIwJTIwc2NoZWR1bGVyJTNEc2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDMyJTJDJTBBKS50byhkZXZpY2UpJTBBJTBBJTNDQ29weUxMTVR4dE1lbnUlMjBjb250YWluZXJTdHlsZSUzRCUyMmZsb2F0JTNBJTIwcmlnaHQlM0IlMjBtYXJnaW4tbGVmdCUzQSUyMDEwcHglM0IlMjBkaXNwbGF5JTNBJTIwaW5saW5lLWZsZXglM0IlMjBwb3NpdGlvbiUzQSUyMHJlbGF0aXZlJTNCJTIwei1pbmRleCUzQSUyMDEwJTNCJTIyJTNFJTNDJTJGQ29weUxMTVR4dE1lbnUlM0UlMEElMEElMjMlMjBEaXNhYmxlJTIwaW1hZ2UlMjBnZW5lcmF0aW9uJTIwcHJvZ3Jlc3MlMjBiYXIlMkMlMjB3ZSdsbCUyMGRpc3BsYXklMjBvdXIlMjBvd24lMEFwaXBlLnNldF9wcm9ncmVzc19iYXJfY29uZmlnKGRpc2FibGUlM0RUcnVlKQ==",highlighted:`model_name_or_path = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>

scheduler = LMSDiscreteScheduler(beta_start=<span class="hljs-number">0.00085</span>, beta_end=<span class="hljs-number">0.012</span>, beta_schedule=<span class="hljs-string">&quot;scaled_linear&quot;</span>, num_train_timesteps=<span class="hljs-number">1000</span>)


pipe = StableDiffusionPipeline.from_pretrained(
    model_name_or_path,
    scheduler=scheduler,
    torch_dtype=torch.float32,
).to(device)

&lt;CopyLLMTxtMenu containerStyle=<span class="hljs-string">&quot;float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;&quot;</span>&gt;&lt;/CopyLLMTxtMenu&gt;

<span class="hljs-comment"># Disable image generation progress bar, we&#x27;ll display our own</span>
pipe.set_progress_bar_config(disable=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5nJTIwRmxhc2glMjBBdHRlbnRpb24lM0IlMjBJZiUyMHlvdSUyMGhhdmUlMjBQeVRvcmNoJTIwJTNFJTNEJTIwMi4wJTIwaW5zdGFsbGVkJTJDJTIweW91JTIwc2hvdWxkJTIwbm90JTIwZXhwZWN0JTIwYSUyMHNwZWVkLXVwJTIwZm9yJTIwaW5mZXJlbmNlJTIwd2hlbiUyMGVuYWJsaW5nJTIweGZvcm1lcnMuJTBBcGlwZS5lbmFibGVfeGZvcm1lcnNfbWVtb3J5X2VmZmljaWVudF9hdHRlbnRpb24oKQ==",highlighted:`<span class="hljs-comment"># Offloading the weights to the CPU and only loading them on the GPU can reduce memory consumption to less than 3GB.</span>
pipe.enable_model_cpu_offload()

<span class="hljs-comment"># Tighter ordering of memory tensors.</span>
pipe.unet.to(memory_format=torch.channels_last)

<span class="hljs-comment"># Decoding large batches of images with limited VRAM or batches with 32 images or more by decoding the batches of latents one image at a time.</span>
pipe.enable_vae_slicing()

<span class="hljs-comment"># Splitting the image into overlapping tiles, decoding the tiles, and then blending the outputs together to compose the final image. </span>
pipe.enable_vae_tiling()

<span class="hljs-comment"># Using Flash Attention; If you have PyTorch &gt;= 2.0 installed, you should not expect a speed-up for inference when enabling xformers.</span>
pipe.enable_xformers_memory_efficient_attention()`,wrap:!1}}),N=new m({props:{code:"ZGVmJTIwZGlzcGxheV9pbWFnZXMoaW1hZ2VzJTJDJTIwc2F2ZV9wYXRoKSUzQSUwQSUyMCUyMCUyMCUyMHRyeSUzQSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMyUyMENvbnZlcnQlMjBlYWNoJTIwaW1hZ2UlMjBpbiUyMHRoZSUyMCdpbWFnZXMnJTIwbGlzdCUyMGZyb20lMjBhbiUyMGFycmF5JTIwdG8lMjBhbiUyMEltYWdlJTIwb2JqZWN0LiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGltYWdlcyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyM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biUyMGVycm9yJTIwZHVyaW5nJTIwdGhlJTIwcHJvY2VzcyUyQyUyMHByaW50JTIwdGhlJTIwZXhjZXB0aW9uJTIwbWVzc2FnZS4lMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludChlKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMFJldHVybiUyMHRoZSUyMHNhdmVkJTIwR0lGJTIwYXMlMjBhbiUyMElQeXRob24lMjBkaXNwbGF5JTIwb2JqZWN0JTIwc28lMjBpdCUyMGNhbiUyMGJlJTIwZGlzcGxheWVkJTIwaW4lMjBhJTIwbm90ZWJvb2suJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwSVBkaXNwbGF5LkltYWdlKGYlMjIlN0JzYXZlX3BhdGglN0QlMkYlN0JmaWxlbmFtZSU3RC5naWYlMjIp",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">display_images</span>(<span class="hljs-params">images, save_path</span>):
    <span class="hljs-keyword">try</span>:
        <span class="hljs-comment"># Convert each image in the &#x27;images&#x27; list from an array to an Image object.</span>
        images = [
            Image.fromarray(np.array(image[<span class="hljs-number">0</span>], dtype=np.uint8)) <span class="hljs-keyword">for</span> image <span class="hljs-keyword">in</span> images
        ]

        <span class="hljs-comment"># Generate a file name based on the current time, replacing colons with hyphens</span>
        <span class="hljs-comment"># to ensure the filename is valid for file systems that don&#x27;t allow colons.</span>
        filename = (
            time.strftime(<span class="hljs-string">&quot;%H:%M:%S&quot;</span>, time.localtime())
            .replace(<span class="hljs-string">&quot;:&quot;</span>, <span class="hljs-string">&quot;-&quot;</span>)
        )
        <span class="hljs-comment"># Save the first image in the list as a GIF file at the &#x27;save_path&#x27; location.</span>
        <span class="hljs-comment"># The rest of the images in the list are added as subsequent frames to the GIF.</span>
        <span class="hljs-comment"># The GIF will play each frame for 100 milliseconds and will loop indefinitely.</span>
        images[<span class="hljs-number">0</span>].save(
            <span class="hljs-string">f&quot;<span class="hljs-subst">{save_path}</span>/<span class="hljs-subst">{filename}</span>.gif&quot;</span>,
            save_all=<span class="hljs-literal">True</span>,
            append_images=images[<span class="hljs-number">1</span>:],
            duration=<span class="hljs-number">100</span>,
            loop=<span class="hljs-number">0</span>,
        )
    <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e:
        <span class="hljs-comment"># If there is an error during the process, print the exception message.</span>
        <span class="hljs-built_in">print</span>(e)

    <span class="hljs-comment"># Return the saved GIF as an IPython display object so it can be displayed in a notebook.</span>
    <span class="hljs-keyword">return</span> IPdisplay.Image(<span class="hljs-string">f&quot;<span class="hljs-subst">{save_path}</span>/<span class="hljs-subst">{filename}</span>.gif&quot;</span>)`,wrap:!1}}),F=new o({props:{title:"生成参数",local:"生成参数",headingTag:"h3"}}),z=new m({props:{code:"JTIzJTIwVGhlJTIwc2VlZCUyMGlzJTIwc2V0JTIwdG8lMjAlMjJOb25lJTIyJTJDJTIwYmVjYXVzZSUyMHdlJTIwd2FudCUyMGRpZmZlcmVudCUyMHJlc3VsdHMlMjBlYWNoJTIwdGltZSUyMHdlJTIwcnVuJTIwdGhlJTIwZ2VuZXJhdGlvbi4lMEFzZWVkJTIwJTNEJTIwTm9uZSUwQSUwQWlmJTIwc2VlZCUyMGlzJTIwbm90JTIwTm9uZSUzQSUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUyMCUzRCUyMHRvcmNoLm1hbnVhbF9zZWVkKHNlZWQpJTBBZWxzZSUzQSUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUyMCUzRCUyME5vbmUlMEElMEElMjMlMjBUaGUlMjBndWlkYW5jZSUyMHNjYWxlJTIwaXMlMjBzZXQlMjB0byUyMGl0cyUyMG5vcm1hbCUyMHJhbmdlJTIwKDclMjAtJTIwMTApLiUwQWd1aWRhbmNlX3NjYWxlJTIwJTNEJTIwOCUwQSUwQSUyMyUyMFRoZSUyMG51bWJlciUyMG9mJTIwaW5mZXJlbmNlJTIwc3RlcHMlMjB3YXMlMjBjaG9zZW4lMj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lighted:`<span class="hljs-comment"># The seed is set to &quot;None&quot;, because we want different results each time we run the generation.</span>
seed = <span class="hljs-literal">None</span>

<span class="hljs-keyword">if</span> seed <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:
    generator = torch.manual_seed(seed)
<span class="hljs-keyword">else</span>:
    generator = <span class="hljs-literal">None</span>

<span class="hljs-comment"># The guidance scale is set to its normal range (7 - 10).</span>
guidance_scale = <span class="hljs-number">8</span>

<span class="hljs-comment"># The number of inference steps was chosen empirically to generate an acceptable picture within an acceptable time.</span>
num_inference_steps = <span class="hljs-number">15</span>

<span class="hljs-comment"># The higher you set this value, the smoother the interpolations will be. However, the generation time will increase. This value was chosen empirically.</span>
num_interpolation_steps = <span class="hljs-number">30</span>

<span class="hljs-comment"># I would not recommend less than 512 on either dimension. This is because this model was trained on 512x512 image resolution.</span>
height = <span class="hljs-number">512</span> 
width = <span class="hljs-number">512</span>

<span class="hljs-comment"># The path where the generated GIFs will be saved</span>
save_path = <span class="hljs-string">&quot;/output&quot;</span>

<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(save_path):
    os.makedirs(save_path)`,wrap:!1}}),$=new o({props:{title:"示例 1：提示插值",local:"示例-1提示插值",headingTag:"h3"}}),K=new m({props:{code:"JTIzJTIwVGhlJTIwdGV4dCUyMHByb21wdCUyMHRoYXQlMjBkZXNjcmliZXMlMjB0aGUlMjBkZXNpcmVkJTIwb3V0cHV0JTIwaW1hZ2UuJTBBcHJvbXB0JTIwJTNEJTIwJTIyRXBpYyUyMHNob3QlMjBvZiUyMFN3ZWRlbiUyQyUyMHVsdHJhJTIwZGV0YWlsZWQlMjBsYWtlJTIwd2l0aCUyMGFuJTIwcmVuJTIwZGVhciUyQyUyMG5vc3RhbGdpYyUyMHZpbnRhZ2UlMkMlMjB1bHRyYSUyMGNvenklMjBhbmQlMjBpbnZpdGluZyUyQyUyMHdvbmRlcmZ1bCUyMGxpZ2h0JTIwYXRtb3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wQSklMEFuZWdhdGl2ZV9wcm9tcHRfZW1iZWRzJTIwJTNEJTIwcGlwZS50ZXh0X2VuY29kZXIobmVnYXRpdmVfcHJvbXB0X3Rva2Vucy5pbnB1dF9pZHMudG8oZGV2aWNlKSklNUIwJTVE",highlighted:`<span class="hljs-comment"># The text prompt that describes the desired output image.</span>
prompt = <span class="hljs-string">&quot;Epic shot of Sweden, ultra detailed lake with an ren dear, nostalgic vintage, ultra cozy and inviting, wonderful light atmosphere, fairy, little photorealistic, digital painting, sharp focus, ultra cozy and inviting, wish to be there. very detailed, arty, should rank high on youtube for a dream trip.&quot;</span>
<span class="hljs-comment"># A negative prompt that can be used to steer the generation away from certain features; here, it is empty.</span>
negative_prompt = <span class="hljs-string">&quot;poorly drawn,cartoon, 2d, disfigured, bad art, deformed, poorly drawn, extra limbs, close up, b&amp;w, weird colors, blurry&quot;</span>

<span class="hljs-comment"># The step size for the interpolation in the latent space.</span>
step_size = <span class="hljs-number">0.001</span>

<span class="hljs-comment"># Tokenizing and encoding the prompt into embeddings.</span>
prompt_tokens = pipe.tokenizer(
    prompt,
    padding=<span class="hljs-string">&quot;max_length&quot;</span>,
    max_length=pipe.tokenizer.model_max_length,
    truncation=<span class="hljs-literal">True</span>,
    return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
)
prompt_embeds = pipe.text_encoder(prompt_tokens.input_ids.to(device))[<span class="hljs-number">0</span>]


<span class="hljs-comment"># Tokenizing and encoding the negative prompt into embeddings.</span>
<span class="hljs-keyword">if</span> negative_prompt <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
    negative_prompt = [<span class="hljs-string">&quot;&quot;</span>]

negative_prompt_tokens = pipe.tokenizer(
    negative_prompt,
    padding=<span class="hljs-string">&quot;max_length&quot;</span>,
    max_length=pipe.tokenizer.model_max_length,
    truncation=<span class="hljs-literal">True</span>,
    return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
)
negative_prompt_embeds = pipe.text_encoder(negative_prompt_tokens.input_ids.to(device))[<span class="hljs-number">0</span>]`,wrap:!1}}),O=new m({props:{code:"JTIzJTIwR2VuZXJhdGluZyUyMGluaXRpYWwlMjBsYXRlbnQlMjB2ZWN0b3JzJTIwZnJvbSUyMGElMjByYW5kb20lMjBub3JtYWwlMjBkaXN0cmlidXRpb24lMkMlMjB3aXRoJTIwdGhlJTIwb3B0aW9uJTIwdG8lMjB1c2UlMjBhJTIwZ2VuZXJhdG9yJTIwZm9yJTIwcmVwcm9kdWNpYmlsaXR5LiUwQWxhdGVudHMlMjAlM0QlMjB0b3JjaC5yYW5kbiglMEElMjAlMjAlMjAlMjAoMSUyQyUyMHBpcGUudW5ldC5jb25maWcuaW5fY2hhbm5lbHMlMkMlMjBoZWlnaHQlMjAlMkYlMkYlMjA4JTJDJTIwd2lkdGglMjAlMkYlMkYlMjA4KSUyQyUwQSUyMCUyMCUyMCUyMGdlbmVyYXRvciUzRGdlbmVyYXRvciUyQyUwQSklMEElMEF3YWxrZWRfZW1iZWRkaW5ncyUyMCUzRCUyMCU1QiU1RCUwQSUwQSUyMyUyMEludGVycG9sYXRpbmclMjBiZXR3ZWVuJTIwZW1iZWRkaW5ncyUyMGZvciUyMHRoZSUyMGdpdmVuJTIwbnVtYmVyJTIwb2YlMjBpbnRlcnBvbGF0aW9uJTIwc3RlcHMuJTBBZm9yJTIwaSUyMGluJTIwcmFuZ2UobnVtX2ludGVycG9sYXRpb25fc3RlcHMpJTNBJTBBJTIwJTIwJTIwJTIwd2Fsa2VkX2VtYmVkZGluZ3MuYXBwZW5kKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCU1QnByb21wdF9lbWJlZHMlMjAlMkIlMjBzdGVwX3NpemUlMjAqJTIwaSUyQyUyMG5lZ2F0aXZlX3Byb21wdF9lbWJlZHMlMjAlMkIlMjBzdGVwX3NpemUlMjAqJTIwaSU1RCUwQSUyMCUyMCUyMCUyMCk=",highlighted:`<span class="hljs-comment"># Generating initial latent vectors from a random normal distribution, with the option to use a generator for reproducibility.</span>
latents = torch.randn(
    (<span class="hljs-number">1</span>, pipe.unet.config.in_channels, height // <span class="hljs-number">8</span>, width // <span class="hljs-number">8</span>),
    generator=generator,
)

walked_embeddings = []

<span class="hljs-comment"># Interpolating between embeddings for the given number of interpolation steps.</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num_interpolation_steps):
    walked_embeddings.append(
        [prompt_embeds + step_size * i, negative_prompt_embeds + step_size * i]
    )`,wrap:!1}}),Ml=new m({props:{code:"JTIzJTIwR2VuZXJhdGluZyUyMGltYWdlcyUyMHVzaW5nJTIwdGhlJTIwaW50ZXJwb2xhdGVkJTIwZW1iZWRkaW5ncy4lMEFpbWFnZXMlMjAlM0QlMjAlNUIlNUQlMEFmb3IlMjBsYXRlbnQlMjBpbiUyMHRxZG0od2Fsa2VkX2VtYmVkZGluZ3MpJTNBJTBBJTIwJTIwJTIwJTIwaW1hZ2VzLmFwcGVuZCglMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwaXBlKCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGhlaWdodCUzRGhlaWdodCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHdpZHRoJTNEd2lkdGglMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1faW1hZ2VzX3Blcl9wcm9tcHQlM0QxJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJvbXB0X2VtYmVkcyUzRGxhdGVudCU1QjAlNUQlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBuZWdhdGl2ZV9wcm9tcHRfZW1iZWRzJTNEbGF0ZW50JTVCMSU1RCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0RudW1faW5mZXJlbmNlX3N0ZXBzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ3VpZGFuY2Vfc2NhbGUlM0RndWlkYW5jZV9zY2FsZSUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGdlbmVyYXRvciUzRGdlbmVyYXRvciUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhdGVudHMlM0RsYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKS5pbWFnZXMlMEElMjAlMjAlMjAlMjApJTBBJTBBJTIzJTIwRGlzcGxheSUyMG9mJTIwc2F2ZWQlMjBnZW5lcmF0ZWQlMjBpbWFnZXMuJTBBZGlzcGxheV9pbWFnZXMoaW1hZ2VzJTJDJTIwc2F2ZV9wYXRoKQ==",highlighted:`<span class="hljs-comment"># Generating images using the interpolated embeddings.</span>
images = []
<span class="hljs-keyword">for</span> latent <span class="hljs-keyword">in</span> tqdm(walked_embeddings):
    images.append(
        pipe(
            height=height,
            width=width,
            num_images_per_prompt=<span class="hljs-number">1</span>,
            prompt_embeds=latent[<span class="hljs-number">0</span>],
            negative_prompt_embeds=latent[<span class="hljs-number">1</span>],
            num_inference_steps=num_inference_steps,
            guidance_scale=guidance_scale,
            generator=generator,
            latents=latents,
        ).images
    )

<span class="hljs-comment"># Display of saved generated images.</span>
display_images(images, save_path)`,wrap:!1}}),el=new o({props:{title:"示例 2：针对单个提示的扩散潜在插值",local:"示例-2针对单个提示的扩散潜在插值",headingTag:"h3"}}),yl=new m({props:{code:"ZGVmJTIwc2xlcnAodjAlMkMlMjB2MSUyQyUyMG51bSUyQyUyMHQwJTNEMCUyQyUyMHQxJTNEMSklM0ElMEElMjAlMjAlMjAlMjB2MCUyMCUzRCUyMHYwLmRldGFj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ElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBzaW5fdGhldGFfdCUyMCUzRCUyMG5wLnNpbih0aGV0YV90KSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHMwJTIwJTNEJTIwbnAuc2luKHRoZXRhXzAlMjAtJTIwdGhldGFfdCklMjAlMkYlMjBzaW5fdGhldGFfMCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHMxJTIwJTNEJTIwc2luX3RoZXRhX3QlMjAlMkYlMjBzaW5fdGhldGFfMCUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHYyJTIwJTNEJTIwczAlMjAqJTIwdjAlMjAlMkIlMjBzMSUyMColMjB2MSUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMHJldHVybiUyMHYyJTBBJTBBJTIwJTIwJTIwJTIwdCUyMCUzRCUyMG5wLmxpbnNwYWNlKHQwJTJDJTIwdDElMkMlMjBudW0pJTBBJTBBJTIwJTIwJTIwJTIwdjMlMjAlM0QlMjB0b3JjaC50ZW5zb3IobnAuYXJyYXkoJTVCaW50ZXJwb2xhdGlvbih0JTVCaSU1RCUyQyUyMHYwJTJDJTIwdjEpJTIwZm9yJTIwaSUyMGluJTIwcmFuZ2UobnVtKSU1RCkpJTBBJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwdjM=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">slerp</span>(<span class="hljs-params">v0, v1, num, t0=<span class="hljs-number">0</span>, t1=<span class="hljs-number">1</span></span>):
    v0 = v0.detach().cpu().numpy()
    v1 = v1.detach().cpu().numpy()

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">interpolation</span>(<span class="hljs-params">t, v0, v1, DOT_THRESHOLD=<span class="hljs-number">0.9995</span></span>):
        <span class="hljs-string">&quot;&quot;&quot;helper function to spherically interpolate two arrays v1 v2&quot;&quot;&quot;</span>
        dot = np.<span class="hljs-built_in">sum</span>(v0 * v1 / (np.linalg.norm(v0) * np.linalg.norm(v1)))
        <span class="hljs-keyword">if</span> np.<span class="hljs-built_in">abs</span>(dot) &gt; DOT_THRESHOLD:
            v2 = (<span class="hljs-number">1</span> - t) * v0 + t * v1
        <span class="hljs-keyword">else</span>:
            theta_0 = np.arccos(dot)
            sin_theta_0 = np.sin(theta_0)
            theta_t = theta_0 * t
            sin_theta_t = np.sin(theta_t)
            s0 = np.sin(theta_0 - theta_t) / sin_theta_0
            s1 = sin_theta_t / sin_theta_0
            v2 = s0 * v0 + s1 * v1
        <span class="hljs-keyword">return</span> v2

    t = np.linspace(t0, t1, num)

    v3 = torch.tensor(np.array([interpolation(t[i], v0, v1) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(num)]))

    <span class="hljs-keyword">return</span> v3`,wrap:!1}}),Jl=new m({props:{code:"JTIzJTIwVGhlJTIwdGV4dCUyMHByb21wdCUyMHRoYXQlMjBkZXNjcmliZXMlMjB0aGUlMjBkZXNpcmVkJTIwb3V0cHV0JTIwaW1hZ2UuJTBBcHJvbXB0JTIwJTNEJTIwJTIyU2NpLWZpJTIwZGlnaXRhbCUyMHBhaW50aW5nJTIwb2YlMjBhbiUyMGFsaWVuJTIwbGFuZHNjYXBlJTIwd2l0aCUyMG90aGVyd29ybGRseSUyMHBsYW50cyUyQyUyMHN0cmFuZ2UlMjBjcmVhdHVyZXMlMkMlMjBhbmQlMjBkaXN0YW50JTIwcGxhbmV0cy4lMjIlMEElMjMlMjBBJTIwbmVnYXRpdmUlMjBwcm9tcHQlMjB0aGF0JTIwY2FuJTIwYmUlMjB1c2VkJTIwdG8lMjBzdGVlciUyMHRoZSUyMGdlbmVyYXRpb24lMjBhd2F5JTIwZnJvbSUyMGNlcnRhaW4lMjBmZWF0dXJlcy4lMEFuZWdhdGl2ZV9wcm9tcHQlMjAlM0QlMjAlMj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JDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwbGF0ZW50cyUzRGxhdGVudF92ZWN0b3IlNUJOb25lJTJDJTIwLi4uJTVEJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKS5pbWFnZXMlMEElMjAlMjAlMjAlMjApJTBBJTBBJTIzJTIwRGlzcGxheSUyMG9mJTIwc2F2ZWQlMjBnZW5lcmF0ZWQlMjBpbWFnZXMuJTBBZGlzcGxheV9pbWFnZXMoaW1hZ2VzJTJDJTIwc2F2ZV9wYXRoKQ==",highlighted:`<span class="hljs-comment"># The text prompt that describes the desired output image.</span>
prompt = <span class="hljs-string">&quot;Sci-fi digital painting of an alien landscape with otherworldly plants, strange creatures, and distant planets.&quot;</span>
<span class="hljs-comment"># A negative prompt that can be used to steer the generation away from certain features.</span>
negative_prompt = <span class="hljs-string">&quot;poorly drawn,cartoon, 3d, disfigured, bad art, deformed, poorly drawn, extra limbs, close up, b&amp;w, weird colors, blurry&quot;</span>

<span class="hljs-comment"># Generating initial latent vectors from a random normal distribution. In this example two latent vectors are generated, which will serve as start and end points for the interpolation.</span>
<span class="hljs-comment"># These vectors are shaped to fit the input requirements of the diffusion model&#x27;s U-Net architecture.</span>
latents = torch.randn(
    (<span class="hljs-number">2</span>, pipe.unet.config.in_channels, height // <span class="hljs-number">8</span>, width // <span class="hljs-number">8</span>),
    generator=generator,
)

<span class="hljs-comment"># Getting our latent embeddings</span>
interpolated_latents = slerp(latents[<span class="hljs-number">0</span>], latents[<span class="hljs-number">1</span>], num_interpolation_steps)

<span class="hljs-comment"># Generating images using the interpolated embeddings.</span>
images = []
<span class="hljs-keyword">for</span> latent_vector <span class="hljs-keyword">in</span> tqdm(interpolated_latents):
    images.append(
        pipe(
            prompt,
            height=height,
            width=width,
            negative_prompt=negative_prompt,
            num_images_per_prompt=<span class="hljs-number">1</span>,
            num_inference_steps=num_inference_steps,
            guidance_scale=guidance_scale,
            generator=generator,
            latents=latent_vector[<span class="hljs-literal">None</span>, ...],
        ).images
    )

<span class="hljs-comment"># Display of saved generated images.</span>
display_images(images, save_path)`,wrap:!1}}),pl=new o({props:{title:"示例 3：多个提示之间的插值",local:"示例-3多个提示之间的插值",headingTag:"h3"}}),Tl=new m({props:{code:"JTIzJTIwVGV4dCUyMHByb21wdHMlMjB0aGF0JTIwZGVzY3JpYmVzJTIwdGhlJTIwZGVzaXJlZCUyMG91dHB1dCUyMGltYWdlLiUwQXByb21wdHMlMjAlM0QlMjAlNUIlMEElMjAlMjAlMjAlMjAlMjJBJTIwY3V0ZSUyMGRvZyUyMGluJTIwYSUyMGJlYXV0aWZ1bCUyMGZpZWxkJTIwb2YlMjBsYXZhbmRlciUyMGNvbG9yZnVsJTIwZmxvd2VycyUyMGV2ZXJ5d2hlcmUlMkMlMjBwZXJmZWN0JTIwbGlnaHRpbmclMkMlMjBsZWljYSUyMHN1bW1pY3JvbiUyMDM1bW0lMjBmMi4wJTJDJTIwa29kYWslMjBwb3J0cmElMjA0MDAlMkMlMjBmaWxtJTIwZ3JhaW4lMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJBJTIwY3V0ZSUyMGNhdCUyMGluJTIwYSUyMGJlYXV0aWZ1bCUyMGZpZWxkJTIwb2YlMjBsYXZhbmRlciUyMGNvbG9yZnVsJTIwZmxvd2VycyUyMGV2ZXJ5d2hlcmUlMkMlMjBwZXJmZWN0JTIwbGlnaHRpbmclMkMlMjBsZWljYSUyMHN1bW1pY3JvbiUyMDM1bW0lMjBmMi4wJTJDJTIwa29kYWslMjBwb3J0cmElMjA0MDAlMkMlMjBmaWxtJTIwZ3JhaW4lMjIlMkMlMEElNUQlMEElMjMlMjBOZWdhdGl2ZSUyMHByb21wdHMlMjB0aGF0JTIwY2FuJTIwYmUlMjB1c2VkJTIwd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EElMjAlMjAlMjAlMjByZXR1cm5fdGVuc29ycyUzRCUyMnB0JTIyJTJDJTBBKSUwQW5lZ2F0aXZlX3Byb21wdHNfZW1iZWRzJTIwJTNEJTIwcGlwZS50ZXh0X2VuY29kZXIoJTBBJTIwJTIwJTIwJTIwbmVnYXRpdmVfcHJvbXB0c190b2tlbnMuaW5wdXRfaWRzLnRvKGRldmljZSklMEEpJTVCMCU1RA==",highlighted:`<span class="hljs-comment"># Text prompts that describes the desired output image.</span>
prompts = [
    <span class="hljs-string">&quot;A cute dog in a beautiful field of lavander colorful flowers everywhere, perfect lighting, leica summicron 35mm f2.0, kodak portra 400, film grain&quot;</span>,
    <span class="hljs-string">&quot;A cute cat in a beautiful field of lavander colorful flowers everywhere, perfect lighting, leica summicron 35mm f2.0, kodak portra 400, film grain&quot;</span>,
]
<span class="hljs-comment"># Negative prompts that can be used to steer the generation away from certain features.</span>
negative_prompts = [
    <span class="hljs-string">&quot;poorly drawn,cartoon, 2d, sketch, cartoon, drawing, anime, disfigured, bad art, deformed, poorly drawn, extra limbs, close up, b&amp;w, weird colors, blurry&quot;</span>,
    <span class="hljs-string">&quot;poorly drawn,cartoon, 2d, sketch, cartoon, drawing, anime, disfigured, bad art, deformed, poorly drawn, extra limbs, close up, b&amp;w, weird colors, blurry&quot;</span>,
]

<span class="hljs-comment"># <span class="hljs-doctag">NOTE:</span> The number of prompts must match the number of negative prompts</span>

batch_size = <span class="hljs-built_in">len</span>(prompts)

<span class="hljs-comment"># Tokenizing and encoding prompts into embeddings.</span>
prompts_tokens = pipe.tokenizer(
    prompts,
    padding=<span class="hljs-string">&quot;max_length&quot;</span>,
    max_length=pipe.tokenizer.model_max_length,
    truncation=<span class="hljs-literal">True</span>,
    return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
)
prompts_embeds = pipe.text_encoder(
    prompts_tokens.input_ids.to(device)
)[<span class="hljs-number">0</span>]

<span class="hljs-comment"># Tokenizing and encoding negative prompts into embeddings.</span>
<span class="hljs-keyword">if</span> negative_prompts <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:
    negative_prompts = [<span class="hljs-string">&quot;&quot;</span>] * batch_size

negative_prompts_tokens = pipe.tokenizer(
    negative_prompts,
    padding=<span class="hljs-string">&quot;max_length&quot;</span>,
    max_length=pipe.tokenizer.model_max_length,
    truncation=<span class="hljs-literal">True</span>,
    return_tensors=<span class="hljs-string">&quot;pt&quot;</span>,
)
negative_prompts_embeds = pipe.text_encoder(
    negative_prompts_tokens.input_ids.to(device)
)[<span class="hljs-number">0</span>]`,wrap:!1}}),ml=new m({props:{code:"JTIzJTIwR2VuZXJhdGluZyUyMGluaXRpYWwlMjBVLU5ldCUyMGxhdGVudCUyMHZlY3RvcnMlMjBmcm9tJTIwYSUyMHJhbmRvbSUyMG5vcm1hbCUyMGRpc3RyaWJ1dGlvbi4lMEFsYXRlbnRzJTIwJTNEJTIwdG9yY2gucmFuZG4oJTBBJTIwJTIwJTIwJTIwKDElMkMlMjBwaXBlLnVuZXQuY29uZmlnLmluX2NoYW5uZWxzJTJDJTIwaGVpZ2h0JTIwJTJGJTJGJTIwOCUyQyUyMHdpZHRoJTIwJTJGJTJGJTIwOCklMkMlMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMEEpJTBBJTBBJTIzJTIwSW50ZXJwb2xhdGluZyUyMGJldHdlZW4lMjBlbWJlZGRpbmdzJTIwcGFpcnMlMjBmb3IlMjB0aGUlMjBnaXZlbiUyMG51bWJlciUyMG9mJTIwaW50ZXJwb2xhdGlvbiUyMHN0ZXBzLiUwQWludGVycG9sYXRlZF9wcm9tcHRfZW1iZWRzJTIwJTNEJTIwJTVCJTVEJTBBaW50ZXJwb2xhdGVkX25lZ2F0aXZlX3Byb21wdHNfZW1iZWRzJTIwJTNEJTIwJTVCJTVEJTBBZm9yJTIwaSUyMGluJTIwcmFuZ2UoYmF0Y2hfc2l6ZSUyMC0lMjAxKSUzQSUwQSUyMCUyMCUy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ZSklMEElMEFpbnRlcnBvbGF0ZWRfbmVnYXRpdmVfcHJvbXB0c19lbWJlZHMlMjAlM0QlMjB0b3JjaC5jYXQoJTBBJTIwJTIwJTIwJTIwaW50ZXJwb2xhdGVkX25lZ2F0aXZlX3Byb21wdHNfZW1iZWRzJTJDJTIwZGltJTNEMCUwQSkudG8oZGV2aWNlKQ==",highlighted:`<span class="hljs-comment"># Generating initial U-Net latent vectors from a random normal distribution.</span>
latents = torch.randn(
    (<span class="hljs-number">1</span>, pipe.unet.config.in_channels, height // <span class="hljs-number">8</span>, width // <span class="hljs-number">8</span>),
    generator=generator,
)

<span class="hljs-comment"># Interpolating between embeddings pairs for the given number of interpolation steps.</span>
interpolated_prompt_embeds = []
interpolated_negative_prompts_embeds = []
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(batch_size - <span class="hljs-number">1</span>):
    interpolated_prompt_embeds.append(
        slerp(
            prompts_embeds[i],
            prompts_embeds[i + <span class="hljs-number">1</span>],
            num_interpolation_steps
        )
    )
    interpolated_negative_prompts_embeds.append(
        slerp(
            negative_prompts_embeds[i],
            negative_prompts_embeds[i + <span class="hljs-number">1</span>],
            num_interpolation_steps,
        )
    )

interpolated_prompt_embeds = torch.cat(
    interpolated_prompt_embeds, dim=<span class="hljs-number">0</span>
).to(device)

interpolated_negative_prompts_embeds = torch.cat(
    interpolated_negative_prompts_embeds, dim=<span class="hljs-number">0</span>
).to(device)`,wrap:!1}}),ol=new m({props:{code:"JTIzJTIwR2VuZXJhdGluZyUyMGltYWdlcyUyMHVzaW5nJTIwdGhlJTIwaW50ZXJwb2xhdGVkJTIwZW1iZWRkaW5ncy4lMEFpbWFnZXMlMjAlM0QlMjAlNUIlNUQlMEFmb3IlMjBwcm9tcHRfZW1iZWRzJTJDJTIwbmVnYXRpdmVfcHJvbXB0X2VtYmVkcyUyMGluJTIwdHFkbSglMEElMjAlMjAlMjAlMjB6aXAoaW50ZXJwb2xhdGVkX3Byb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yQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGxhdGVudHMlM0RsYXRlbnRzJTJDJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwKS5pbWFnZXMlMEElMjAlMjAlMjAlMjApJTBBJTBBJTIzJTIwRGlzcGxheSUyMG9mJTIwc2F2ZWQlMjBnZW5lcmF0ZWQlMjBpbWFnZXMuJTBBZGlzcGxheV9pbWFnZXMoaW1hZ2VzJTJDJTIwc2F2ZV9wYXRoKQ==",highlighted:`<span class="hljs-comment"># Generating images using the interpolated embeddings.</span>
images = []
<span class="hljs-keyword">for</span> prompt_embeds, negative_prompt_embeds <span class="hljs-keyword">in</span> tqdm(
    <span class="hljs-built_in">zip</span>(interpolated_prompt_embeds, interpolated_negative_prompts_embeds),
    total=<span class="hljs-built_in">len</span>(interpolated_prompt_embeds),
):
    images.append(
        pipe(
            height=height,
            width=width,
            num_images_per_prompt=<span class="hljs-number">1</span>,
            prompt_embeds=prompt_embeds[<span class="hljs-literal">None</span>, ...],
            negative_prompt_embeds=negative_prompt_embeds[<span class="hljs-literal">None</span>, ...],
            num_inference_steps=num_inference_steps,
            guidance_scale=guidance_scale,
            generator=generator,
            latents=latents,
        ).images
    )

<span class="hljs-comment"># Display of saved generated images.</span>
display_images(images, save_path)`,wrap:!1}}),dl=new o({props:{title:"示例 4：针对单个提示在扩散潜在空间中的循环行走",local:"示例-4针对单个提示在扩散潜在空间中的循环行走",headingTag:"h3"}}),hl=new m({props:{code:"JTIzJTIwVGhlJTIwdGV4dCUyMHByb21wdCUyMHRoYXQlMjBkZXNjcmliZXMlMjB0aGUlMjBkZXNpcmVkJTIwb3V0cHV0JTIwaW1hZ2UuJTBBcHJvbXB0JTIwJTNEJTIwJTIyQmVhdXRpZnVsJTIwc2VhJTIwc3Vuc2V0JTJDJTIwd2FybSUyMGxpZ2h0JTJDJTIwQWl2YXpvdnNreSUyMHN0eWxlJTIyJTBBJTIzJTIwQSUy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dGglM0R3aWR0aCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG5lZ2F0aXZlX3Byb21wdCUzRG5lZ2F0aXZlX3Byb21wdCUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMG51bV9pbWFnZXNfcGVyX3Byb21wdCUzRDElMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEbnVtX2luZmVyZW5jZV9zdGVwcyUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMGd1aWRhbmNlX3NjYWxlJTNEZ3VpZGFuY2Vfc2NhbGUlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBsYXRlbnRzJTNEbGF0ZW50X3ZlY3RvciUyQyUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCkuaW1hZ2VzJTBBJTIwJTIwJTIwJTIwKSUwQSUwQSUyMyUyMERpc3BsYXklMjBvZiUyMHNhdmVkJTIwZ2VuZXJhdGVkJTIwaW1hZ2VzLiUwQWRpc3BsYXlfaW1hZ2VzKGltYWdlcyUyQyUyMHNhdmVfcGF0aCk=",highlighted:`<span class="hljs-comment"># The text prompt that describes the desired output image.</span>
prompt = <span class="hljs-string">&quot;Beautiful sea sunset, warm light, Aivazovsky style&quot;</span>
<span class="hljs-comment"># A negative prompt that can be used to steer the generation away from certain features</span>
negative_prompt = <span class="hljs-string">&quot;picture frames&quot;</span>

<span class="hljs-comment"># Generating initial latent vectors from a random normal distribution to create a loop interpolation between them.</span>
latents = torch.randn(
    (<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, pipe.unet.config.in_channels, height // <span class="hljs-number">8</span>, width // <span class="hljs-number">8</span>),
    generator=generator,
)


<span class="hljs-comment"># Calculation of looped embeddings</span>
walk_noise_x = latents[<span class="hljs-number">0</span>].to(device)
walk_noise_y = latents[<span class="hljs-number">1</span>].to(device)

<span class="hljs-comment"># Walking on a trigonometric circle</span>
walk_scale_x = torch.cos(torch.linspace(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, num_interpolation_steps) * np.pi).to(
    device
)
walk_scale_y = torch.sin(torch.linspace(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>, num_interpolation_steps) * np.pi).to(
    device
)

<span class="hljs-comment"># Applying interpolation to noise</span>
noise_x = torch.tensordot(walk_scale_x, walk_noise_x, dims=<span class="hljs-number">0</span>)
noise_y = torch.tensordot(walk_scale_y, walk_noise_y, dims=<span class="hljs-number">0</span>)

circular_latents = noise_x + noise_y

<span class="hljs-comment"># Generating images using the interpolated embeddings.</span>
images = []
<span class="hljs-keyword">for</span> latent_vector <span class="hljs-keyword">in</span> tqdm(circular_latents):
    images.append(
        pipe(
            prompt,
            height=height,
            width=width,
            negative_prompt=negative_prompt,
            num_images_per_prompt=<span class="hljs-number">1</span>,
            num_inference_steps=num_inference_steps,
            guidance_scale=guidance_scale,
            generator=generator,
            latents=latent_vector,
        ).images
    )

<span class="hljs-comment"># Display of saved generated images.</span>
display_images(images, save_path)`,wrap:!1}}),Zl=new o({props:{title:"下一步",local:"下一步",headingTag:"h2"}}),Bl=new Xe({props:{source:"https://github.com/huggingface/cookbook/blob/main/notebooks/zh-CN/stable_diffusion_interpolation.md"}}),{c(){c=n("meta"),Wl=t(),Cl=n("p"),fl=t(),p(d.$$.fragment),Vl=t(),p(I.$$.fragment),Xl=t(),b=n("p"),b.innerHTML=YM,Al=t(),r=n("p"),r.textContent=QM,gl=t(),h=n("p"),h.textContent=SM,Rl=t(),Z=n("ul"),Z.innerHTML=NM,kl=t(),u=n("p"),u.textContent=FM,vl=t(),B=n("p"),B.textContent=xM,El=t(),C=n("p"),C.textContent=zM,_l=t(),G=n("p"),G.textContent=$M,Hl=t(),p(W.$$.fragment),Yl=t(),f=n("p"),f.textContent=DM,Ql=t(),p(V.$$.fragment),Sl=t(),X=n("p"),X.textContent=LM,Nl=t(),p(A.$$.fragment),Fl=t(),g=n("p"),g.textContent=qM,xl=t(),R=n("p"),R.innerHTML=KM,zl=t(),p(k.$$.fragment),$l=t(),p(v.$$.fragment),Dl=t(),E=n("p"),E.innerHTML=PM,Ll=t(),p(_.$$.fragment),ql=t(),H=n("p"),H.textContent=OM,Kl=t(),Y=n("p"),Y.innerHTML=le,Pl=t(),p(Q.$$.fragment),Ol=t(),S=n("p"),S.innerHTML=Me,lM=t(),p(N.$$.fragment),MM=t(),p(F.$$.fragment),eM=t(),x=n("ul"),x.innerHTML=ee,sM=t(),p(z.$$.fragment),tM=t(),p($.$$.fragment),aM=t(),D=n("p"),D.textContent=se,nM=t(),L=n("p"),L.innerHTML=te,yM=t(),q=n("p"),q.textContent=ae,JM=t(),p(K.$$.fragment),pM=t(),P=n("p"),P.textContent=ne,wM=t(),p(O.$$.fragment),UM=t(),ll=n("p"),ll.innerHTML=ye,iM=t(),p(Ml.$$.fragment),TM=t(),p(el.$$.fragment),jM=t(),sl=n("p"),sl.textContent=Je,mM=t(),tl=n("p"),tl.innerHTML=pe,cM=t(),al=n("p"),al.textContent=we,oM=t(),nl=n("p"),nl.innerHTML=Ue,dM=t(),p(yl.$$.fragment),IM=t(),p(Jl.$$.fragment),bM=t(),p(pl.$$.fragment),rM=t(),wl=n("p"),wl.textContent=ie,hM=t(),Ul=n("p"),Ul.innerHTML=Te,ZM=t(),il=n("p"),il.textContent=je,uM=t(),p(Tl.$$.fragment),BM=t(),jl=n("p"),jl.innerHTML=me,CM=t(),p(ml.$$.fragment),GM=t(),cl=n("p"),cl.textContent=ce,WM=t(),p(ol.$$.fragment),fM=t(),p(dl.$$.fragment),VM=t(),Il=n("p"),Il.innerHTML=oe,XM=t(),bl=n("p"),bl.textContent=de,AM=t(),rl=n("p"),rl.innerHTML=Ie,gM=t(),p(hl.$$.fragment),RM=t(),p(Zl.$$.fragment),kM=t(),ul=n("p"),ul.innerHTML=be,vM=t(),p(Bl.$$.fragment),EM=t(),Gl=n("p"),this.h()},l(l){const M=We("svelte-u9bgzb",document.head);c=y(M,"META",{name:!0,content:!0}),M.forEach(e),Wl=a(l),Cl=y(l,"P",{}),re(Cl).forEach(e),fl=a(l),w(d.$$.fragment,l),Vl=a(l),w(I.$$.fragment,l),Xl=a(l),b=y(l,"P",{"data-svelte-h":!0}),J(b)!=="svelte-l1zus2"&&(b.innerHTML=YM),Al=a(l),r=y(l,"P",{"data-svelte-h":!0}),J(r)!=="svelte-vl3vu"&&(r.textContent=QM),gl=a(l),h=y(l,"P",{"data-svelte-h":!0}),J(h)!=="svelte-3yjhy9"&&(h.textContent=SM),Rl=a(l),Z=y(l,"UL",{"data-svelte-h":!0}),J(Z)!=="svelte-x06y5u"&&(Z.innerHTML=NM),kl=a(l),u=y(l,"P",{"data-svelte-h":!0}),J(u)!=="svelte-1amlnbc"&&(u.textContent=FM),vl=a(l),B=y(l,"P",{"data-svelte-h":!0}),J(B)!=="svelte-80jdxw"&&(B.textContent=xM),El=a(l),C=y(l,"P",{"data-svelte-h":!0}),J(C)!=="svelte-1s0jexb"&&(C.textContent=zM),_l=a(l),G=y(l,"P",{"data-svelte-h":!0}),J(G)!=="svelte-90kp52"&&(G.textContent=$M),Hl=a(l),w(W.$$.fragment,l),Yl=a(l),f=y(l,"P",{"data-svelte-h":!0}),J(f)!=="svelte-1cpgku1"&&(f.textContent=DM),Ql=a(l),w(V.$$.fragment,l),Sl=a(l),X=y(l,"P",{"data-svelte-h":!0}),J(X)!=="svelte-kiqgoo"&&(X.textContent=LM),Nl=a(l),w(A.$$.fragment,l),Fl=a(l),g=y(l,"P",{"data-svelte-h":!0}),J(g)!=="svelte-1xivm34"&&(g.textContent=qM),xl=a(l),R=y(l,"P",{"data-svelte-h":!0}),J(R)!=="svelte-10ww4iw"&&(R.innerHTML=KM),zl=a(l),w(k.$$.fragment,l),$l=a(l),w(v.$$.fragment,l),Dl=a(l),E=y(l,"P",{"data-svelte-h":!0}),J(E)!=="svelte-cjrc4k"&&(E.innerHTML=PM),Ll=a(l),w(_.$$.fragment,l),ql=a(l),H=y(l,"P",{"data-svelte-h":!0}),J(H)!=="svelte-d699bz"&&(H.textContent=OM),Kl=a(l),Y=y(l,"P",{"data-svelte-h":!0}),J(Y)!=="svelte-16msx7m"&&(Y.innerHTML=le),Pl=a(l),w(Q.$$.fragment,l),Ol=a(l),S=y(l,"P",{"data-svelte-h":!0}),J(S)!=="svelte-kaqcjf"&&(S.innerHTML=Me),lM=a(l),w(N.$$.fragment,l),MM=a(l),w(F.$$.fragment,l),eM=a(l),x=y(l,"UL",{"data-svelte-h":!0}),J(x)!=="svelte-1960fzq"&&(x.innerHTML=ee),sM=a(l),w(z.$$.fragment,l),tM=a(l),w($.$$.fragment,l),aM=a(l),D=y(l,"P",{"data-svelte-h":!0}),J(D)!=="svelte-1547xx2"&&(D.textContent=se),nM=a(l),L=y(l,"P",{"data-svelte-h":!0}),J(L)!=="svelte-1x05mg4"&&(L.innerHTML=te),yM=a(l),q=y(l,"P",{"data-svelte-h":!0}),J(q)!=="svelte-mpab18"&&(q.textContent=ae),JM=a(l),w(K.$$.fragment,l),pM=a(l),P=y(l,"P",{"data-svelte-h":!0}),J(P)!=="svelte-1loead7"&&(P.textContent=ne),wM=a(l),w(O.$$.fragment,l),UM=a(l),ll=y(l,"P",{"data-svelte-h":!0}),J(ll)!=="svelte-qyojnk"&&(ll.innerHTML=ye),iM=a(l),w(Ml.$$.fragment,l),TM=a(l),w(el.$$.fragment,l),jM=a(l),sl=y(l,"P",{"data-svelte-h":!0}),J(sl)!=="svelte-1n1zuo4"&&(sl.textContent=Je),mM=a(l),tl=y(l,"P",{"data-svelte-h":!0}),J(tl)!=="svelte-zqtywg"&&(tl.innerHTML=pe),cM=a(l),al=y(l,"P",{"data-svelte-h":!0}),J(al)!=="svelte-dfsbxo"&&(al.textContent=we),oM=a(l),nl=y(l,"P",{"data-svelte-h":!0}),J(nl)!=="svelte-ghr9ym"&&(nl.innerHTML=Ue),dM=a(l),w(yl.$$.fragment,l),IM=a(l),w(Jl.$$.fragment,l),bM=a(l),w(pl.$$.fragment,l),rM=a(l),wl=y(l,"P",{"data-svelte-h":!0}),J(wl)!=="svelte-11iwlsu"&&(wl.textContent=ie),hM=a(l),Ul=y(l,"P",{"data-svelte-h":!0}),J(Ul)!=="svelte-1uv5js0"&&(Ul.innerHTML=Te),ZM=a(l),il=y(l,"P",{"data-svelte-h":!0}),J(il)!=="svelte-1v61gi9"&&(il.textContent=je),uM=a(l),w(Tl.$$.fragment,l),BM=a(l),jl=y(l,"P",{"data-svelte-h":!0}),J(jl)!=="svelte-hd1991"&&(jl.innerHTML=me),CM=a(l),w(ml.$$.fragment,l),GM=a(l),cl=y(l,"P",{"data-svelte-h":!0}),J(cl)!=="svelte-1edtf72"&&(cl.textContent=ce),WM=a(l),w(ol.$$.fragment,l),fM=a(l),w(dl.$$.fragment,l),VM=a(l),Il=y(l,"P",{"data-svelte-h":!0}),J(Il)!=="svelte-1awlctq"&&(Il.innerHTML=oe),XM=a(l),bl=y(l,"P",{"data-svelte-h":!0}),J(bl)!=="svelte-jtjlcu"&&(bl.textContent=de),AM=a(l),rl=y(l,"P",{"data-svelte-h":!0}),J(rl)!=="svelte-1h51p8s"&&(rl.innerHTML=Ie),gM=a(l),w(hl.$$.fragment,l),RM=a(l),w(Zl.$$.fragment,l),kM=a(l),ul=y(l,"P",{"data-svelte-h":!0}),J(ul)!=="svelte-zjdioo"&&(ul.innerHTML=be),vM=a(l),w(Bl.$$.fragment,l),EM=a(l),Gl=y(l,"P",{}),re(Gl).forEach(e),this.h()},h(){he(c,"name","hf:doc:metadata"),he(c,"content",ge)},m(l,M){fe(document.head,c),s(l,Wl,M),s(l,Cl,M),s(l,fl,M),U(d,l,M),s(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s(l,RM,M),U(Zl,l,M),s(l,kM,M),s(l,ul,M),s(l,vM,M),U(Bl,l,M),s(l,EM,M),s(l,Gl,M),_M=!0},p:ue,i(l){_M||(i(d.$$.fragment,l),i(I.$$.fragment,l),i(W.$$.fragment,l),i(V.$$.fragment,l),i(A.$$.fragment,l),i(k.$$.fragment,l),i(v.$$.fragment,l),i(_.$$.fragment,l),i(Q.$$.fragment,l),i(N.$$.fragment,l),i(F.$$.fragment,l),i(z.$$.fragment,l),i($.$$.fragment,l),i(K.$$.fragment,l),i(O.$$.fragment,l),i(Ml.$$.fragment,l),i(el.$$.fragment,l),i(yl.$$.fragment,l),i(Jl.$$.fragment,l),i(pl.$$.fragment,l),i(Tl.$$.fragment,l),i(ml.$$.fragment,l),i(ol.$$.fragment,l),i(dl.$$.fragment,l),i(hl.$$.fragment,l),i(Zl.$$.fragment,l),i(Bl.$$.fragment,l),_M=!0)},o(l){T(d.$$.fragment,l),T(I.$$.fragment,l),T(W.$$.fragment,l),T(V.$$.fragment,l),T(A.$$.fragment,l),T(k.$$.fragment,l),T(v.$$.fragment,l),T(_.$$.fragment,l),T(Q.$$.fragment,l),T(N.$$.fragment,l),T(F.$$.fragment,l),T(z.$$.fragment,l),T($.$$.fragment,l),T(K.$$.fragment,l),T(O.$$.fragment,l),T(Ml.$$.fragment,l),T(el.$$.fragment,l),T(yl.$$.fragment,l),T(Jl.$$.fragment,l),T(pl.$$.fragment,l),T(Tl.$$.fragment,l),T(ml.$$.fragment,l),T(ol.$$.fragment,l),T(dl.$$.fragment,l),T(hl.$$.fragment,l),T(Zl.$$.fragment,l),T(Bl.$$.fragment,l),_M=!1},d(l){l&&(e(Wl),e(Cl),e(fl),e(Vl),e(Xl),e(b),e(Al),e(r),e(gl),e(h),e(Rl),e(Z),e(kl),e(u),e(vl),e(B),e(El),e(C),e(_l),e(G),e(Hl),e(Yl),e(f),e(Ql),e(Sl),e(X),e(Nl),e(Fl),e(g),e(xl),e(R),e(zl),e($l),e(Dl),e(E),e(Ll),e(ql),e(H),e(Kl),e(Y),e(Pl),e(Ol),e(S),e(lM),e(MM),e(eM),e(x),e(sM),e(tM),e(aM),e(D),e(nM),e(L),e(yM),e(q),e(JM),e(pM),e(P),e(wM),e(UM),e(ll),e(iM),e(TM),e(jM),e(sl),e(mM),e(tl),e(cM),e(al),e(oM),e(nl),e(dM),e(IM),e(bM),e(rM),e(wl),e(hM),e(Ul),e(ZM),e(il),e(uM),e(BM),e(jl),e(CM),e(GM),e(cl),e(WM),e(fM),e(VM),e(Il),e(XM),e(bl),e(AM),e(rl),e(gM),e(RM),e(kM),e(ul),e(vM),e(EM),e(Gl)),e(c),j(d,l),j(I,l),j(W,l),j(V,l),j(A,l),j(k,l),j(v,l),j(_,l),j(Q,l),j(N,l),j(F,l),j(z,l),j($,l),j(K,l),j(O,l),j(Ml,l),j(el,l),j(yl,l),j(Jl,l),j(pl,l),j(Tl,l),j(ml,l),j(ol,l),j(dl,l),j(hl,l),j(Zl,l),j(Bl,l)}}}const ge='{"title":"使用 Stable Diffusion 进行图像插值","local":"使用-stable-diffusion-进行图像插值","sections":[{"title":"模型","local":"模型","sections":[],"depth":3},{"title":"生成参数","local":"生成参数","sections":[],"depth":3},{"title":"示例 1：提示插值","local":"示例-1提示插值","sections":[],"depth":3},{"title":"示例 2：针对单个提示的扩散潜在插值","local":"示例-2针对单个提示的扩散潜在插值","sections":[],"depth":3},{"title":"示例 3：多个提示之间的插值","local":"示例-3多个提示之间的插值","sections":[],"depth":3},{"title":"示例 4：针对单个提示在扩散潜在空间中的循环行走","local":"示例-4针对单个提示在扩散潜在空间中的循环行走","sections":[],"depth":3}],"depth":2}';function Re(HM){return Be(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class He extends Ce{constructor(c){super(),Ge(this,c,Re,Ae,Ze,{})}}export{He as component};
