"vscode:/vscode.git/clone" did not exist on "40c16ed2f01c5c95105b17fdfbfb9e3b778d2e66"
__init__.py 3.43 KB
Newer Older
1
from dataclasses import dataclass
2
from typing import List, Optional, Union
3
4
5
6
7
8

import numpy as np

import PIL
from PIL import Image

9
10
11
from ...utils import (
    BaseOutput,
    is_flax_available,
12
    is_k_diffusion_available,
13
14
15
16
17
    is_onnx_available,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)
18
19
20
21
22
23
24
25
26
27
28
29
30


@dataclass
class StableDiffusionPipelineOutput(BaseOutput):
    """
    Output class for Stable Diffusion pipelines.

    Args:
        images (`List[PIL.Image.Image]` or `np.ndarray`)
            List of denoised PIL images of length `batch_size` or numpy array of shape `(batch_size, height, width,
            num_channels)`. PIL images or numpy array present the denoised images of the diffusion pipeline.
        nsfw_content_detected (`List[bool]`)
            List of flags denoting whether the corresponding generated image likely represents "not-safe-for-work"
31
            (nsfw) content, or `None` if safety checking could not be performed.
32
33
34
    """

    images: Union[List[PIL.Image.Image], np.ndarray]
35
    nsfw_content_detected: Optional[List[bool]]
Suraj Patil's avatar
Suraj Patil committed
36
37


38
if is_transformers_available() and is_torch_available():
39
    from .pipeline_cycle_diffusion import CycleDiffusionPipeline
40
41
42
    from .pipeline_stable_diffusion import StableDiffusionPipeline
    from .pipeline_stable_diffusion_img2img import StableDiffusionImg2ImgPipeline
    from .pipeline_stable_diffusion_inpaint import StableDiffusionInpaintPipeline
43
    from .pipeline_stable_diffusion_inpaint_legacy import StableDiffusionInpaintPipelineLegacy
44
    from .pipeline_stable_diffusion_upscale import StableDiffusionUpscalePipeline
45
    from .safety_checker import StableDiffusionSafetyChecker
46

Patrick von Platen's avatar
Patrick von Platen committed
47
if is_transformers_available() and is_torch_available() and is_transformers_version(">=", "4.25.0.dev0"):
48
49
50
51
    from .pipeline_stable_diffusion_image_variation import StableDiffusionImageVariationPipeline
else:
    from ...utils.dummy_torch_and_transformers_objects import StableDiffusionImageVariationPipeline

52
53
54
if is_transformers_available() and is_torch_available() and is_k_diffusion_available():
    from .pipeline_stable_diffusion_k_diffusion import StableDiffusionKDiffusionPipeline

55
if is_transformers_available() and is_onnx_available():
56
    from .pipeline_onnx_stable_diffusion import OnnxStableDiffusionPipeline, StableDiffusionOnnxPipeline
57
58
    from .pipeline_onnx_stable_diffusion_img2img import OnnxStableDiffusionImg2ImgPipeline
    from .pipeline_onnx_stable_diffusion_inpaint import OnnxStableDiffusionInpaintPipeline
59
    from .pipeline_onnx_stable_diffusion_inpaint_legacy import OnnxStableDiffusionInpaintPipelineLegacy
60
61
62
63
64
65
66
67
68
69

if is_transformers_available() and is_flax_available():
    import flax

    @flax.struct.dataclass
    class FlaxStableDiffusionPipelineOutput(BaseOutput):
        """
        Output class for Stable Diffusion pipelines.

        Args:
70
71
            images (`np.ndarray`)
                Array of shape `(batch_size, height, width, num_channels)` with images from the diffusion pipeline.
72
73
74
75
76
            nsfw_content_detected (`List[bool]`)
                List of flags denoting whether the corresponding generated image likely represents "not-safe-for-work"
                (nsfw) content.
        """

77
        images: np.ndarray
78
79
80
81
82
        nsfw_content_detected: List[bool]

    from ...schedulers.scheduling_pndm_flax import PNDMSchedulerState
    from .pipeline_flax_stable_diffusion import FlaxStableDiffusionPipeline
    from .safety_checker_flax import FlaxStableDiffusionSafetyChecker