import{S as va,i as wa,s as Da,e as n,k as d,w as v,t as o,M as Pa,c as i,d as a,m as c,a as s,x as w,h as r,b as u,G as t,g as f,y as D,q as P,o as M,B as $,v as Ma,L as $a}from"../../../../chunks/vendor-hf-doc-builder.js";import{T as xa}from"../../../../chunks/Tip-hf-doc-builder.js";import{D as Ke}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as Xt}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as et}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Ta}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function ka(ie){let m,x,h,g,b;return{c(){m=n("p"),x=o("Make sure to check out the Stable Diffusion "),h=n("a"),g=o("Tips"),b=o(" section to learn how to explore the tradeoff between scheduler speed and quality, and how to reuse pipeline components efficiently!"),this.h()},l(p){m=i(p,"P",{});var _=s(m);x=r(_,"Make sure to check out the Stable Diffusion "),h=i(_,"A",{href:!0});var N=s(h);g=r(N,"Tips"),N.forEach(a),b=r(_," section to learn how to explore the tradeoff between scheduler speed and quality, and how to reuse pipeline components efficiently!"),_.forEach(a),this.h()},h(){u(h,"href","overview#tips")},m(p,_){f(p,m,_),t(m,x),t(m,h),t(h,g),t(m,b)},d(p){p&&a(m)}}}function Ia(ie){let m,x,h,g,b;return g=new Xt({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmVTYWZlJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25QaXBlbGluZVNhZmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMkFJTUwtVFVEQSUyRnN0YWJsZS1kaWZmdXNpb24tc2FmZSUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUwQSklMEFwcm9tcHQlMjAlM0QlMjAlMjJ0aGUlMjBmb3VyJTIwaG9yc2V3b21lbiUyMG9mJTIwdGhlJTIwYXBvY2FseXBzZSUyQyUyMHBhaW50aW5nJTIwYnklMjB0b20lMjBvZiUyMGZpbmxhbmQlMkMlMjBnYXN0b24lMjBidXNzaWVyZSUyQyUyMGNyYWlnJTIwbXVsbGlucyUyQyUyMGouJTIwYy4lMjBsZXllbmRlY2tlciUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0JTNEcHJvbXB0JTJDJTIwKipTYWZldHlDb25maWcuTUVESVVNKS5pbWFnZXMlNUIwJTVE",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipelineSafe

pipeline = StableDiffusionPipelineSafe.from_pretrained(
    <span class="hljs-string">&quot;AIML-TUDA/stable-diffusion-safe&quot;</span>, torch_dtype=torch.float16
)
prompt = <span class="hljs-string">&quot;the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c. leyendecker&quot;</span>
image = pipeline(prompt=prompt, **SafetyConfig.MEDIUM).images[<span class="hljs-number">0</span>]`}}),{c(){m=n("p"),x=o("Examples:"),h=d(),v(g.$$.fragment)},l(p){m=i(p,"P",{});var _=s(m);x=r(_,"Examples:"),_.forEach(a),h=c(p),w(g.$$.fragment,p)},m(p,_){f(p,m,_),t(m,x),f(p,h,_),D(g,p,_),b=!0},p:$a,i(p){b||(P(g.$$.fragment,p),b=!0)},o(p){M(g.$$.fragment,p),b=!1},d(p){p&&a(m),p&&a(h),$(g,p)}}}function Ua(ie){let m,x,h,g,b,p,_,N,tt,Ie,G,at,q,nt,it,Ue,se,st,Ee,oe,ue,ot,Ze,E,C,me,F,rt,he,lt,Le,k,ft,ge,pt,dt,re,ct,ut,Ne,X,Ge,J,mt,_e,ht,gt,Ce,y,_t,be,bt,yt,ye,St,vt,Se,wt,Dt,ve,Pt,Mt,Je,z,je,j,We,Z,W,we,Y,$t,De,xt,Ae,S,Q,Tt,R,kt,le,It,Ut,Et,H,Zt,fe,Lt,Nt,Gt,I,K,Ct,Pe,Jt,jt,A,Ve,L,V,Me,ee,Wt,$e,At,Oe,T,te,Vt,xe,Ot,Bt,O,ae,qt,Te,Ft,Be;return p=new et({}),F=new et({}),X=new Xt({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lU2FmZSUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmVTYWZlLmZyb21fcHJldHJhaW5lZCglMjJBSU1MLVRVREElMkZzdGFibGUtZGlmZnVzaW9uLXNhZmUlMjIpJTBBcGlwZWxpbmUuc2FmZXR5X2NvbmNlcHQ=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipelineSafe

<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPipelineSafe.from_pretrained(<span class="hljs-string">&quot;AIML-TUDA/stable-diffusion-safe&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline.safety_concept
<span class="hljs-string">&#x27;an image showing hate, harassment, violence, suffering, humiliation, harm, suicide, sexual, nudity, bodily fluids, blood, obscene gestures, illegal activity, drug use, theft, vandalism, weapons, child abuse, brutality, cruelty&#x27;</span>`}}),z=new Xt({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lU2FmZSUwQWZyb20lMjBkaWZmdXNlcnMucGlwZWxpbmVzLnN0YWJsZV9kaWZmdXNpb25fc2FmZSUyMGltcG9ydCUyMFNhZmV0eUNvbmZpZyUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmVTYWZlLmZyb21fcHJldHJhaW5lZCglMjJBSU1MLVRVREElMkZzdGFibGUtZGlmZnVzaW9uLXNhZmUlMjIpJTBBcHJvbXB0JTIwJTNEJTIwJTIydGhlJTIwZm91ciUyMGhvcnNld29tZW4lMjBvZiUyMHRoZSUyMGFwb2NhbHlwc2UlMkMlMjBwYWludGluZyUyMGJ5JTIwdG9tJTIwb2YlMjBmaW5sYW5kJTJDJTIwZ2FzdG9uJTIwYnVzc2llcmUlMkMlMjBjcmFpZyUyMG11bGxpbnMlMkMlMjBqLiUyMGMuJTIwbGV5ZW5kZWNrZXIlMjIlMEFvdXQlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlM0Rwcm9tcHQlMkMlMjAqKlNhZmV0eUNvbmZpZy5NQVgp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipelineSafe
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers.pipelines.stable_diffusion_safe <span class="hljs-keyword">import</span> SafetyConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>pipeline = StableDiffusionPipelineSafe.from_pretrained(<span class="hljs-string">&quot;AIML-TUDA/stable-diffusion-safe&quot;</span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;the four horsewomen of the apocalypse, painting by tom of finland, gaston bussiere, craig mullins, j. c. leyendecker&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>out = pipeline(prompt=prompt, **SafetyConfig.MAX)`}}),j=new xa({props:{$$slots:{default:[ka]},$$scope:{ctx:ie}}}),Y=new et({}),Q=new Ke({props:{name:"class diffusers.StableDiffusionPipelineSafe",anchor:"diffusers.StableDiffusionPipelineSafe",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": KarrasDiffusionSchedulers"},{name:"safety_checker",val:": SafeStableDiffusionSafetyChecker"},{name:"feature_extractor",val:": CLIPImageProcessor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPipelineSafe.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/en/api/models/autoencoderkl#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionPipelineSafe.text_encoder",description:`<strong>text_encoder</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIPTextModel</a>) &#x2014;
Frozen text-encoder (<a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a>).`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionPipelineSafe.tokenizer",description:`<strong>tokenizer</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>) &#x2014;
A <code>CLIPTokenizer</code> to tokenize text.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionPipelineSafe.unet",description:`<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014;
A <code>UNet2DConditionModel</code> to denoise the encoded image latents.`,name:"unet"},{anchor:"diffusers.StableDiffusionPipelineSafe.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents. Can be one of
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/main/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/main/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionPipelineSafe.safety_checker",description:`<strong>safety_checker</strong> (<code>StableDiffusionSafetyChecker</code>) &#x2014;
Classification module that estimates whether generated images could be considered offensive or harmful.
Please refer to the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow">model card</a> for more details
about a model&#x2019;s potential harms.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionPipelineSafe.feature_extractor",description:`<strong>feature_extractor</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPImageProcessor" rel="nofollow">CLIPImageProcessor</a>) &#x2014;
A <code>CLIPImageProcessor</code> to extract features from generated images; used as inputs to the <code>safety_checker</code>.`,name:"feature_extractor"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py#L22"}}),K=new Ke({props:{name:"__call__",anchor:"diffusers.StableDiffusionPipelineSafe.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]]"},{name:"height",val:": typing.Optional[int] = None"},{name:"width",val:": typing.Optional[int] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 7.5"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": int = 1"},{name:"sld_guidance_scale",val:": typing.Optional[float] = 1000"},{name:"sld_warmup_steps",val:": typing.Optional[int] = 10"},{name:"sld_threshold",val:": typing.Optional[float] = 0.01"},{name:"sld_momentum_scale",val:": typing.Optional[float] = 0.3"},{name:"sld_mom_beta",val:": typing.Optional[float] = 0.4"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>) &#x2014;
The prompt or prompts to guide image generation. If not defined, you need to pass <code>prompt_embeds</code>.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
A higher guidance scale value encourages the model to generate images closely linked to the text
<code>prompt</code> at the expense of lower image quality. Guidance scale is enabled when <code>guidance_scale &gt; 1</code>.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide what to not include in image generation. If not defined, you need to
pass <code>negative_prompt_embeds</code> instead. Ignored when not using guidance (<code>guidance_scale &lt; 1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) from the <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">DDIM</a> paper. Only applies
to the <a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, and is ignored in other schedulers.`,name:"eta"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
A <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow"><code>torch.Generator</code></a> to make
generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor is generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generated image. Choose between <code>PIL.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/upscale#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that calls every <code>callback_steps</code> steps during inference. The function is called with the
following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function is called. If not specified, the callback is called at
every step.`,name:"callback_steps"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.sld_guidance_scale",description:`<strong>sld_guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 1000) &#x2014;
If <code>sld_guidance_scale &lt; 1</code>, safety guidance is disabled.`,name:"sld_guidance_scale"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.sld_warmup_steps",description:`<strong>sld_warmup_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 10) &#x2014;
Number of warmup steps for safety guidance. SLD is only be applied for diffusion steps greater than
<code>sld_warmup_steps</code>.`,name:"sld_warmup_steps"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.sld_threshold",description:`<strong>sld_threshold</strong> (<code>float</code>, <em>optional</em>, defaults to 0.01) &#x2014;
Threshold that separates the hyperplane between appropriate and inappropriate images.`,name:"sld_threshold"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.sld_momentum_scale",description:`<strong>sld_momentum_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 0.3) &#x2014;
Scale of the SLD momentum to be added to the safety guidance at each diffusion step. If set to 0.0,
momentum is disabled. Momentum is built up during warmup for diffusion steps smaller than
<code>sld_warmup_steps</code>.`,name:"sld_momentum_scale"},{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.sld_mom_beta",description:`<strong>sld_mom_beta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.4) &#x2014;
Defines how safety guidance momentum builds up. <code>sld_mom_beta</code> indicates how much of the previous
momentum is kept. Momentum is built up during warmup for diffusion steps smaller than
<code>sld_warmup_steps</code>.`,name:"sld_mom_beta"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion_safe/pipeline_stable_diffusion_safe.py#L465",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/upscale#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> is returned,
otherwise a <code>tuple</code> is returned where the first element is a list with the generated images and the
second element is a list of <code>bool</code>s indicating whether the corresponding generated image contains
\u201Cnot-safe-for-work\u201D (nsfw) content.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/upscale#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),A=new Ta({props:{anchor:"diffusers.StableDiffusionPipelineSafe.__call__.example",$$slots:{default:[Ia]},$$scope:{ctx:ie}}}),ee=new et({}),te=new Ke({props:{name:"class diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput",anchor:"diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput",parameters:[{name:"images",val:": typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]"},{name:"nsfw_content_detected",val:": typing.Optional[typing.List[bool]]"},{name:"unsafe_images",val:": typing.Union[typing.List[PIL.Image.Image], numpy.ndarray, NoneType]"},{name:"applied_safety_concept",val:": typing.Optional[str]"}],parametersDescription:[{anchor:"diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput.images",description:`<strong>images</strong> (<code>List[PIL.Image.Image]</code> or <code>np.ndarray</code>) &#x2014;
List of denoised PIL images of length <code>batch_size</code> or numpy array of shape <code>(batch_size, height, width, num_channels)</code>. PIL images or numpy array present the denoised images of the diffusion pipeline.`,name:"images"},{anchor:"diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput.nsfw_content_detected",description:`<strong>nsfw_content_detected</strong> (<code>List[bool]</code>) &#x2014;
List of flags denoting whether the corresponding generated image likely represents &#x201C;not-safe-for-work&#x201D;
(nsfw) content, or <code>None</code> if safety checking could not be performed.`,name:"nsfw_content_detected"},{anchor:"diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput.images",description:`<strong>images</strong> (<code>List[PIL.Image.Image]</code> or <code>np.ndarray</code>) &#x2014;
List of denoised PIL images that were flagged by the safety checker any may contain &#x201C;not-safe-for-work&#x201D;
(nsfw) content, or <code>None</code> if no safety check was performed or no images were flagged.`,name:"images"},{anchor:"diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput.applied_safety_concept",description:`<strong>applied_safety_concept</strong> (<code>str</code>) &#x2014;
The safety concept that was applied for safety guidance, or <code>None</code> if safety guidance was disabled`,name:"applied_safety_concept"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion_safe/__init__.py#L45"}}),ae=new Ke({props:{name:"__call__",anchor:"diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput.__call__",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}]}}),{c(){m=n("meta"),x=d(),h=n("h1"),g=n("a"),b=n("span"),v(p.$$.fragment),_=d(),N=n("span"),tt=o("Safe Stable Diffusion"),Ie=d(),G=n("p"),at=o("Safe Stable Diffusion was proposed in "),q=n("a"),nt=o("Safe Latent Diffusion: Mitigating Inappropriate Degeneration in Diffusion Models"),it=o(" and mitigates inappropriate degeneration from Stable Diffusion models because they\u2019re trained on unfiltered web-crawled datasets. For instance Stable Diffusion may unexpectedly generate nudity, violence, images depicting self-harm, and otherwise offensive content. Safe Stable Diffusion is an extension of Stable Diffusion that drastically reduces this type of content."),Ue=d(),se=n("p"),st=o("The abstract from the paper is:"),Ee=d(),oe=n("p"),ue=n("em"),ot=o("Text-conditioned image generation models have recently achieved astonishing results in image quality and text alignment and are consequently employed in a fast-growing number of applications. Since they are highly data-driven, relying on billion-sized datasets randomly scraped from the internet, they also suffer, as we demonstrate, from degenerated and biased human behavior. In turn, they may even reinforce such biases. To help combat these undesired side effects, we present safe latent diffusion (SLD). Specifically, to measure the inappropriate degeneration due to unfiltered and imbalanced training sets, we establish a novel image generation test bed-inappropriate image prompts (I2P)-containing dedicated, real-world image-to-text prompts covering concepts such as nudity and violence. As our exhaustive empirical evaluation demonstrates, the introduced SLD removes and suppresses inappropriate image parts during the diffusion process, with no additional training required and no adverse effect on overall image quality or text alignment."),Ze=d(),E=n("h2"),C=n("a"),me=n("span"),v(F.$$.fragment),rt=d(),he=n("span"),lt=o("Tips"),Le=d(),k=n("p"),ft=o("Use the "),ge=n("code"),pt=o("safety_concept"),dt=o(" property of "),re=n("a"),ct=o("StableDiffusionPipelineSafe"),ut=o(" to check and edit the current safety concept:"),Ne=d(),v(X.$$.fragment),Ge=d(),J=n("p"),mt=o("For each image generation the active concept is also contained in "),_e=n("code"),ht=o("StableDiffusionSafePipelineOutput"),gt=o("."),Ce=d(),y=n("p"),_t=o("There are 4 configurations ("),be=n("code"),bt=o("SafetyConfig.WEAK"),yt=o(", "),ye=n("code"),St=o("SafetyConfig.MEDIUM"),vt=o(", "),Se=n("code"),wt=o("SafetyConfig.STRONG"),Dt=o(", and "),ve=n("code"),Pt=o("SafetyConfig.MAX"),Mt=o(") that can be applied:"),Je=d(),v(z.$$.fragment),je=d(),v(j.$$.fragment),We=d(),Z=n("h2"),W=n("a"),we=n("span"),v(Y.$$.fragment),$t=d(),De=n("span"),xt=o("StableDiffusionPipelineSafe"),Ae=d(),S=n("div"),v(Q.$$.fragment),Tt=d(),R=n("p"),kt=o("Pipeline based on the "),le=n("a"),It=o("StableDiffusionPipeline"),Ut=o(" for text-to-image generation using Safe Latent Diffusion."),Et=d(),H=n("p"),Zt=o("This model inherits from "),fe=n("a"),Lt=o("DiffusionPipeline"),Nt=o(`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Gt=d(),I=n("div"),v(K.$$.fragment),Ct=d(),Pe=n("p"),Jt=o("The call function to the pipeline for generation."),jt=d(),v(A.$$.fragment),Ve=d(),L=n("h2"),V=n("a"),Me=n("span"),v(ee.$$.fragment),Wt=d(),$e=n("span"),At=o("StableDiffusionSafePipelineOutput"),Oe=d(),T=n("div"),v(te.$$.fragment),Vt=d(),xe=n("p"),Ot=o("Output class for Safe Stable Diffusion pipelines."),Bt=d(),O=n("div"),v(ae.$$.fragment),qt=d(),Te=n("p"),Ft=o("Call self as a function."),this.h()},l(e){const l=Pa('[data-svelte="svelte-1phssyn"]',document.head);m=i(l,"META",{name:!0,content:!0}),l.forEach(a),x=c(e),h=i(e,"H1",{class:!0});var ne=s(h);g=i(ne,"A",{id:!0,class:!0,href:!0});var ke=s(g);b=i(ke,"SPAN",{});var zt=s(b);w(p.$$.fragment,zt),zt.forEach(a),ke.forEach(a),_=c(ne),N=i(ne,"SPAN",{});var Yt=s(N);tt=r(Yt,"Safe Stable Diffusion"),Yt.forEach(a),ne.forEach(a),Ie=c(e),G=i(e,"P",{});var qe=s(G);at=r(qe,"Safe Stable Diffusion was proposed in "),q=i(qe,"A",{href:!0,rel:!0});var Qt=s(q);nt=r(Qt,"Safe Latent Diffusion: Mitigating Inappropriate Degeneration in Diffusion Models"),Qt.forEach(a),it=r(qe," and mitigates inappropriate degeneration from Stable Diffusion models because they\u2019re trained on unfiltered web-crawled datasets. For instance Stable Diffusion may unexpectedly generate nudity, violence, images depicting self-harm, and otherwise offensive content. Safe Stable Diffusion is an extension of Stable Diffusion that drastically reduces this type of content."),qe.forEach(a),Ue=c(e),se=i(e,"P",{});var Rt=s(se);st=r(Rt,"The abstract from the paper is:"),Rt.forEach(a),Ee=c(e),oe=i(e,"P",{});var Ht=s(oe);ue=i(Ht,"EM",{});var Kt=s(ue);ot=r(Kt,"Text-conditioned image generation models have recently achieved astonishing results in image quality and text alignment and are consequently employed in a fast-growing number of applications. Since they are highly data-driven, relying on billion-sized datasets randomly scraped from the internet, they also suffer, as we demonstrate, from degenerated and biased human behavior. In turn, they may even reinforce such biases. To help combat these undesired side effects, we present safe latent diffusion (SLD). Specifically, to measure the inappropriate degeneration due to unfiltered and imbalanced training sets, we establish a novel image generation test bed-inappropriate image prompts (I2P)-containing dedicated, real-world image-to-text prompts covering concepts such as nudity and violence. As our exhaustive empirical evaluation demonstrates, the introduced SLD removes and suppresses inappropriate image parts during the diffusion process, with no additional training required and no adverse effect on overall image quality or text alignment."),Kt.forEach(a),Ht.forEach(a),Ze=c(e),E=i(e,"H2",{class:!0});var Fe=s(E);C=i(Fe,"A",{id:!0,class:!0,href:!0});var ea=s(C);me=i(ea,"SPAN",{});var ta=s(me);w(F.$$.fragment,ta),ta.forEach(a),ea.forEach(a),rt=c(Fe),he=i(Fe,"SPAN",{});var aa=s(he);lt=r(aa,"Tips"),aa.forEach(a),Fe.forEach(a),Le=c(e),k=i(e,"P",{});var pe=s(k);ft=r(pe,"Use the "),ge=i(pe,"CODE",{});var na=s(ge);pt=r(na,"safety_concept"),na.forEach(a),dt=r(pe," property of "),re=i(pe,"A",{href:!0});var ia=s(re);ct=r(ia,"StableDiffusionPipelineSafe"),ia.forEach(a),ut=r(pe," to check and edit the current safety concept:"),pe.forEach(a),Ne=c(e),w(X.$$.fragment,e),Ge=c(e),J=i(e,"P",{});var Xe=s(J);mt=r(Xe,"For each image generation the active concept is also contained in "),_e=i(Xe,"CODE",{});var sa=s(_e);ht=r(sa,"StableDiffusionSafePipelineOutput"),sa.forEach(a),gt=r(Xe,"."),Xe.forEach(a),Ce=c(e),y=i(e,"P",{});var U=s(y);_t=r(U,"There are 4 configurations ("),be=i(U,"CODE",{});var oa=s(be);bt=r(oa,"SafetyConfig.WEAK"),oa.forEach(a),yt=r(U,", "),ye=i(U,"CODE",{});var ra=s(ye);St=r(ra,"SafetyConfig.MEDIUM"),ra.forEach(a),vt=r(U,", "),Se=i(U,"CODE",{});var la=s(Se);wt=r(la,"SafetyConfig.STRONG"),la.forEach(a),Dt=r(U,", and "),ve=i(U,"CODE",{});var fa=s(ve);Pt=r(fa,"SafetyConfig.MAX"),fa.forEach(a),Mt=r(U,") that can be applied:"),U.forEach(a),Je=c(e),w(z.$$.fragment,e),je=c(e),w(j.$$.fragment,e),We=c(e),Z=i(e,"H2",{class:!0});var ze=s(Z);W=i(ze,"A",{id:!0,class:!0,href:!0});var pa=s(W);we=i(pa,"SPAN",{});var da=s(we);w(Y.$$.fragment,da),da.forEach(a),pa.forEach(a),$t=c(ze),De=i(ze,"SPAN",{});var ca=s(De);xt=r(ca,"StableDiffusionPipelineSafe"),ca.forEach(a),ze.forEach(a),Ae=c(e),S=i(e,"DIV",{class:!0});var B=s(S);w(Q.$$.fragment,B),Tt=c(B),R=i(B,"P",{});var Ye=s(R);kt=r(Ye,"Pipeline based on the "),le=i(Ye,"A",{href:!0});var ua=s(le);It=r(ua,"StableDiffusionPipeline"),ua.forEach(a),Ut=r(Ye," for text-to-image generation using Safe Latent Diffusion."),Ye.forEach(a),Et=c(B),H=i(B,"P",{});var Qe=s(H);Zt=r(Qe,"This model inherits from "),fe=i(Qe,"A",{href:!0});var ma=s(fe);Lt=r(ma,"DiffusionPipeline"),ma.forEach(a),Nt=r(Qe,`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Qe.forEach(a),Gt=c(B),I=i(B,"DIV",{class:!0});var de=s(I);w(K.$$.fragment,de),Ct=c(de),Pe=i(de,"P",{});var ha=s(Pe);Jt=r(ha,"The call function to the pipeline for generation."),ha.forEach(a),jt=c(de),w(A.$$.fragment,de),de.forEach(a),B.forEach(a),Ve=c(e),L=i(e,"H2",{class:!0});var Re=s(L);V=i(Re,"A",{id:!0,class:!0,href:!0});var ga=s(V);Me=i(ga,"SPAN",{});var _a=s(Me);w(ee.$$.fragment,_a),_a.forEach(a),ga.forEach(a),Wt=c(Re),$e=i(Re,"SPAN",{});var ba=s($e);At=r(ba,"StableDiffusionSafePipelineOutput"),ba.forEach(a),Re.forEach(a),Oe=c(e),T=i(e,"DIV",{class:!0});var ce=s(T);w(te.$$.fragment,ce),Vt=c(ce),xe=i(ce,"P",{});var ya=s(xe);Ot=r(ya,"Output class for Safe Stable Diffusion pipelines."),ya.forEach(a),Bt=c(ce),O=i(ce,"DIV",{class:!0});var He=s(O);w(ae.$$.fragment,He),qt=c(He),Te=i(He,"P",{});var Sa=s(Te);Ft=r(Sa,"Call self as a function."),Sa.forEach(a),He.forEach(a),ce.forEach(a),this.h()},h(){u(m,"name","hf:doc:metadata"),u(m,"content",JSON.stringify(Ea)),u(g,"id","safe-stable-diffusion"),u(g,"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"),u(g,"href","#safe-stable-diffusion"),u(h,"class","relative group"),u(q,"href","https://huggingface.co/papers/2211.05105"),u(q,"rel","nofollow"),u(C,"id","tips"),u(C,"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"),u(C,"href","#tips"),u(E,"class","relative group"),u(re,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/stable_diffusion_safe#diffusers.StableDiffusionPipelineSafe"),u(W,"id","diffusers.StableDiffusionPipelineSafe"),u(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"),u(W,"href","#diffusers.StableDiffusionPipelineSafe"),u(Z,"class","relative group"),u(le,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),u(fe,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),u(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(S,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(V,"id","diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput"),u(V,"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"),u(V,"href","#diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput"),u(L,"class","relative group"),u(O,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),u(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,l){t(document.head,m),f(e,x,l),f(e,h,l),t(h,g),t(g,b),D(p,b,null),t(h,_),t(h,N),t(N,tt),f(e,Ie,l),f(e,G,l),t(G,at),t(G,q),t(q,nt),t(G,it),f(e,Ue,l),f(e,se,l),t(se,st),f(e,Ee,l),f(e,oe,l),t(oe,ue),t(ue,ot),f(e,Ze,l),f(e,E,l),t(E,C),t(C,me),D(F,me,null),t(E,rt),t(E,he),t(he,lt),f(e,Le,l),f(e,k,l),t(k,ft),t(k,ge),t(ge,pt),t(k,dt),t(k,re),t(re,ct),t(k,ut),f(e,Ne,l),D(X,e,l),f(e,Ge,l),f(e,J,l),t(J,mt),t(J,_e),t(_e,ht),t(J,gt),f(e,Ce,l),f(e,y,l),t(y,_t),t(y,be),t(be,bt),t(y,yt),t(y,ye),t(ye,St),t(y,vt),t(y,Se),t(Se,wt),t(y,Dt),t(y,ve),t(ve,Pt),t(y,Mt),f(e,Je,l),D(z,e,l),f(e,je,l),D(j,e,l),f(e,We,l),f(e,Z,l),t(Z,W),t(W,we),D(Y,we,null),t(Z,$t),t(Z,De),t(De,xt),f(e,Ae,l),f(e,S,l),D(Q,S,null),t(S,Tt),t(S,R),t(R,kt),t(R,le),t(le,It),t(R,Ut),t(S,Et),t(S,H),t(H,Zt),t(H,fe),t(fe,Lt),t(H,Nt),t(S,Gt),t(S,I),D(K,I,null),t(I,Ct),t(I,Pe),t(Pe,Jt),t(I,jt),D(A,I,null),f(e,Ve,l),f(e,L,l),t(L,V),t(V,Me),D(ee,Me,null),t(L,Wt),t(L,$e),t($e,At),f(e,Oe,l),f(e,T,l),D(te,T,null),t(T,Vt),t(T,xe),t(xe,Ot),t(T,Bt),t(T,O),D(ae,O,null),t(O,qt),t(O,Te),t(Te,Ft),Be=!0},p(e,[l]){const ne={};l&2&&(ne.$$scope={dirty:l,ctx:e}),j.$set(ne);const ke={};l&2&&(ke.$$scope={dirty:l,ctx:e}),A.$set(ke)},i(e){Be||(P(p.$$.fragment,e),P(F.$$.fragment,e),P(X.$$.fragment,e),P(z.$$.fragment,e),P(j.$$.fragment,e),P(Y.$$.fragment,e),P(Q.$$.fragment,e),P(K.$$.fragment,e),P(A.$$.fragment,e),P(ee.$$.fragment,e),P(te.$$.fragment,e),P(ae.$$.fragment,e),Be=!0)},o(e){M(p.$$.fragment,e),M(F.$$.fragment,e),M(X.$$.fragment,e),M(z.$$.fragment,e),M(j.$$.fragment,e),M(Y.$$.fragment,e),M(Q.$$.fragment,e),M(K.$$.fragment,e),M(A.$$.fragment,e),M(ee.$$.fragment,e),M(te.$$.fragment,e),M(ae.$$.fragment,e),Be=!1},d(e){a(m),e&&a(x),e&&a(h),$(p),e&&a(Ie),e&&a(G),e&&a(Ue),e&&a(se),e&&a(Ee),e&&a(oe),e&&a(Ze),e&&a(E),$(F),e&&a(Le),e&&a(k),e&&a(Ne),$(X,e),e&&a(Ge),e&&a(J),e&&a(Ce),e&&a(y),e&&a(Je),$(z,e),e&&a(je),$(j,e),e&&a(We),e&&a(Z),$(Y),e&&a(Ae),e&&a(S),$(Q),$(K),$(A),e&&a(Ve),e&&a(L),$(ee),e&&a(Oe),e&&a(T),$(te),$(ae)}}}const Ea={local:"safe-stable-diffusion",sections:[{local:"tips",title:"Tips"},{local:"diffusers.StableDiffusionPipelineSafe",title:"StableDiffusionPipelineSafe"},{local:"diffusers.pipelines.stable_diffusion_safe.StableDiffusionSafePipelineOutput",title:"StableDiffusionSafePipelineOutput"}],title:"Safe Stable Diffusion"};function Za(ie){return Ma(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Wa extends va{constructor(m){super();wa(this,m,Za,Ua,Da,{})}}export{Wa as default,Ea as metadata};
