


lowerCamelCase__							:						List[Any]							     =   """0.18.2"""

from .configuration_utils import ConfigMixin
from .utils import (
    OptionalDependencyNotAvailable,
    is_flax_available,
    is_inflect_available,
    is_invisible_watermark_available,
    is_k_diffusion_available,
    is_k_diffusion_version,
    is_librosa_available,
    is_note_seq_available,
    is_onnx_available,
    is_scipy_available,
    is_torch_available,
    is_torchsde_available,
    is_transformers_available,
    is_transformers_version,
    is_unidecode_available,
    logging,
)


try:
   if not is_onnx_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_onnx_objects import *  # noqa F403
else:
   from .pipelines import OnnxRuntimeModel

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_pt_objects import *  # noqa F403
else:
   from .models import (
       AutoencoderKL,
       ControlNetModel,
       ModelMixin,
       PriorTransformer,
       TaFilmDecoder,
       TransformeraDModel,
       UNetaDModel,
       UNetaDConditionModel,
       UNetaDModel,
       UNetaDConditionModel,
       VQModel,
   )
   from .optimization import (
       get_constant_schedule,
       get_constant_schedule_with_warmup,
       get_cosine_schedule_with_warmup,
       get_cosine_with_hard_restarts_schedule_with_warmup,
       get_linear_schedule_with_warmup,
       get_polynomial_decay_schedule_with_warmup,
       get_scheduler,
   )
   from .pipelines import (
       AudioPipelineOutput,
       ConsistencyModelPipeline,
       DanceDiffusionPipeline,
       DDIMPipeline,
       DDPMPipeline,
       DiffusionPipeline,
       DiTPipeline,
       ImagePipelineOutput,
       KarrasVePipeline,
       LDMPipeline,
       LDMSuperResolutionPipeline,
       PNDMPipeline,
       RePaintPipeline,
       ScoreSdeVePipeline,
   )
   from .schedulers import (
       CMStochasticIterativeScheduler,
       DDIMInverseScheduler,
       DDIMParallelScheduler,
       DDIMScheduler,
       DDPMParallelScheduler,
       DDPMScheduler,
       DEISMultistepScheduler,
       DPMSolverMultistepInverseScheduler,
       DPMSolverMultistepScheduler,
       DPMSolverSinglestepScheduler,
       EulerAncestralDiscreteScheduler,
       EulerDiscreteScheduler,
       HeunDiscreteScheduler,
       IPNDMScheduler,
       KarrasVeScheduler,
       KDPMaAncestralDiscreteScheduler,
       KDPMaDiscreteScheduler,
       PNDMScheduler,
       RePaintScheduler,
       SchedulerMixin,
       ScoreSdeVeScheduler,
       UnCLIPScheduler,
       UniPCMultistepScheduler,
       VQDiffusionScheduler,
   )
   from .training_utils import EMAModel

try:
   if not (is_torch_available() and is_scipy_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_torch_and_scipy_objects import *  # noqa F403
else:
   from .schedulers import LMSDiscreteScheduler

try:
   if not (is_torch_available() and is_torchsde_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_torch_and_torchsde_objects import *  # noqa F403
else:
   from .schedulers import DPMSolverSDEScheduler

try:
   if not (is_torch_available() and is_transformers_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
   from .pipelines import (
       AltDiffusionImgaImgPipeline,
       AltDiffusionPipeline,
       AudioLDMPipeline,
       CycleDiffusionPipeline,
       IFImgaImgPipeline,
       IFImgaImgSuperResolutionPipeline,
       IFInpaintingPipeline,
       IFInpaintingSuperResolutionPipeline,
       IFPipeline,
       IFSuperResolutionPipeline,
       ImageTextPipelineOutput,
       KandinskyImgaImgPipeline,
       KandinskyInpaintPipeline,
       KandinskyPipeline,
       KandinskyPriorPipeline,
       KandinskyVaaControlnetImgaImgPipeline,
       KandinskyVaaControlnetPipeline,
       KandinskyVaaImgaImgPipeline,
       KandinskyVaaInpaintPipeline,
       KandinskyVaaPipeline,
       KandinskyVaaPriorEmbaEmbPipeline,
       KandinskyVaaPriorPipeline,
       LDMTextToImagePipeline,
       PaintByExamplePipeline,
       SemanticStableDiffusionPipeline,
       ShapEImgaImgPipeline,
       ShapEPipeline,
       StableDiffusionAttendAndExcitePipeline,
       StableDiffusionControlNetImgaImgPipeline,
       StableDiffusionControlNetInpaintPipeline,
       StableDiffusionControlNetPipeline,
       StableDiffusionDepthaImgPipeline,
       StableDiffusionDiffEditPipeline,
       StableDiffusionImageVariationPipeline,
       StableDiffusionImgaImgPipeline,
       StableDiffusionInpaintPipeline,
       StableDiffusionInpaintPipelineLegacy,
       StableDiffusionInstructPixaPixPipeline,
       StableDiffusionLatentUpscalePipeline,
       StableDiffusionLDMaDPipeline,
       StableDiffusionModelEditingPipeline,
       StableDiffusionPanoramaPipeline,
       StableDiffusionParadigmsPipeline,
       StableDiffusionPipeline,
       StableDiffusionPipelineSafe,
       StableDiffusionPixaPixZeroPipeline,
       StableDiffusionSAGPipeline,
       StableDiffusionUpscalePipeline,
       StableUnCLIPImgaImgPipeline,
       StableUnCLIPPipeline,
       TextToVideoSDPipeline,
       TextToVideoZeroPipeline,
       UnCLIPImageVariationPipeline,
       UnCLIPPipeline,
       UniDiffuserModel,
       UniDiffuserPipeline,
       UniDiffuserTextDecoder,
       VersatileDiffusionDualGuidedPipeline,
       VersatileDiffusionImageVariationPipeline,
       VersatileDiffusionPipeline,
       VersatileDiffusionTextToImagePipeline,
       VideoToVideoSDPipeline,
       VQDiffusionPipeline,
   )

try:
   if not (is_torch_available() and is_transformers_available() and is_invisible_watermark_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_torch_and_transformers_and_invisible_watermark_objects import *  # noqa F403
else:
   from .pipelines import StableDiffusionXLImgaImgPipeline, StableDiffusionXLPipeline

try:
   if not (is_torch_available() and is_transformers_available() and is_k_diffusion_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_torch_and_transformers_and_k_diffusion_objects import *  # noqa F403
else:
   from .pipelines import StableDiffusionKDiffusionPipeline

try:
   if not (is_torch_available() and is_transformers_available() and is_onnx_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_torch_and_transformers_and_onnx_objects import *  # noqa F403
else:
   from .pipelines import (
       OnnxStableDiffusionImgaImgPipeline,
       OnnxStableDiffusionInpaintPipeline,
       OnnxStableDiffusionInpaintPipelineLegacy,
       OnnxStableDiffusionPipeline,
       OnnxStableDiffusionUpscalePipeline,
       StableDiffusionOnnxPipeline,
   )

try:
   if not (is_torch_available() and is_librosa_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_torch_and_librosa_objects import *  # noqa F403
else:
   from .pipelines import AudioDiffusionPipeline, Mel

try:
   if not (is_transformers_available() and is_torch_available() and is_note_seq_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_transformers_and_torch_and_note_seq_objects import *  # noqa F403
else:
   from .pipelines import SpectrogramDiffusionPipeline

try:
   if not is_flax_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_flax_objects import *  # noqa F403
else:
   from .models.controlnet_flax import FlaxControlNetModel
   from .models.modeling_flax_utils import FlaxModelMixin
   from .models.unet_ad_condition_flax import FlaxUNetaDConditionModel
   from .models.vae_flax import FlaxAutoencoderKL
   from .pipelines import FlaxDiffusionPipeline
   from .schedulers import (
       FlaxDDIMScheduler,
       FlaxDDPMScheduler,
       FlaxDPMSolverMultistepScheduler,
       FlaxKarrasVeScheduler,
       FlaxLMSDiscreteScheduler,
       FlaxPNDMScheduler,
       FlaxSchedulerMixin,
       FlaxScoreSdeVeScheduler,
   )


try:
   if not (is_flax_available() and is_transformers_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_flax_and_transformers_objects import *  # noqa F403
else:
   from .pipelines import (
       FlaxStableDiffusionControlNetPipeline,
       FlaxStableDiffusionImgaImgPipeline,
       FlaxStableDiffusionInpaintPipeline,
       FlaxStableDiffusionPipeline,
   )

try:
   if not (is_note_seq_available()):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from .utils.dummy_note_seq_objects import *  # noqa F403
else:
   from .pipelines import MidiProcessor




import datetime
import platform
import subprocess
from typing import Optional, Tuple, Union

import numpy as np



def   __UpperCAmelCase					(      __a :     bytes						,__a :     int      )     ->	np.array:

					"""simple docstring"""

					_a      :       int   =						F"""{sampling_rate}"""
					_a      :       str   =						'''1'''
					_a      :       Optional[int]   =						'''f32le'''
					_a      :       Optional[Any]   =						[
					    '''ffmpeg''',
					    '''-i''',
					    '''pipe:0''',
					    '''-ac''',
					    ac,
					    '''-ar''',
					    ar,
					    '''-f''',
					    format_for_conversion,
					    '''-hide_banner''',
					    '''-loglevel''',
					    '''quiet''',
					    '''pipe:1''',
					]

					try:
										with subprocess.Popen(__a						,stdin=subprocess.PIPE						,stdout=subprocess.PIPE      ) as ffmpeg_process:
															_a      :       Any   =						ffmpeg_process.communicate(__a      )
					except FileNotFoundError as error:
										raise ValueError('''ffmpeg was not found but is required to load audio files from filename'''      ) from error
					_a      :       Optional[Any]   =						output_stream[0]
					_a      :       Optional[int]   =						np.frombuffer(__a						,np.floataa      )
					if audio.shape[0] == 0:
										raise ValueError('''Malformed soundfile'''      )
					return audio



def   __UpperCAmelCase					(      __a :     int						,__a :     float						,__a :     str = "f32le"						,)     ->	str:

					"""simple docstring"""

					_a      :       Dict   =						F"""{sampling_rate}"""
					_a      :       Optional[Any]   =						'''1'''
					if format_for_conversion == "s16le":
										_a      :       Dict   =						2
					elif format_for_conversion == "f32le":
										_a      :       Optional[Any]   =						4
					else:
										raise ValueError(F"""Unhandled format `{format_for_conversion}`. Please use `s16le` or `f32le`"""      )

					_a      :       Dict   =						platform.system()
					if system == "Linux":
										_a      :       Dict   =						'''alsa'''
										_a      :       Union[str, Any]   =						'''default'''
					elif system == "Darwin":
										_a      :       Union[str, Any]   =						'''avfoundation'''
										_a      :       List[str]   =						''':0'''
					elif system == "Windows":
										_a      :       Optional[int]   =						'''dshow'''
										_a      :       str   =						'''default'''

					_a      :       Tuple   =						[
					    '''ffmpeg''',
					    '''-f''',
					    format_,
					    '''-i''',
					    input_,
					    '''-ac''',
					    ac,
					    '''-ar''',
					    ar,
					    '''-f''',
					    format_for_conversion,
					    '''-fflags''',
					    '''nobuffer''',
					    '''-hide_banner''',
					    '''-loglevel''',
					    '''quiet''',
					    '''pipe:1''',
					]
					_a      :       Any   =						int(round(sampling_rate * chunk_length_s      )      ) * size_of_sample
					_a      :       str   =						_ffmpeg_stream(__a						,__a      )
					for item in iterator:
										yield item



def   __UpperCAmelCase					(      __a :     int						,__a :     float						,__a :     Optional[int] = None						,__a :     Optional[Union[Tuple[float, float], float]] = None						,__a :     str = "f32le"						,)     ->	Optional[int]:

					"""simple docstring"""

					if stream_chunk_s is not None:
										_a      :       Tuple   =						stream_chunk_s
					else:
										_a      :       Tuple   =						chunk_length_s

					_a      :       Tuple   =						ffmpeg_microphone(__a						,__a						,format_for_conversion=__a      )
					if format_for_conversion == "s16le":
										_a      :       Any   =						np.intaa
										_a      :       Optional[int]   =						2
					elif format_for_conversion == "f32le":
										_a      :       Dict   =						np.floataa
										_a      :       List[Any]   =						4
					else:
										raise ValueError(F"""Unhandled format `{format_for_conversion}`. Please use `s16le` or `f32le`"""      )

					if stride_length_s is None:
										_a      :       List[Any]   =						chunk_length_s / 6
					_a      :       Optional[int]   =						int(round(sampling_rate * chunk_length_s      )      ) * size_of_sample
					if isinstance(__a						,(int, float)      ):
										_a      :       Optional[Any]   =						[stride_length_s, stride_length_s]

					_a      :       Optional[Any]   =						int(round(sampling_rate * stride_length_s[0]      )      ) * size_of_sample
					_a      :       str   =						int(round(sampling_rate * stride_length_s[1]      )      ) * size_of_sample
					_a      :       Optional[Any]   =						datetime.datetime.now()
					_a      :       Tuple   =						datetime.timedelta(seconds=__a      )
					for item in chunk_bytes_iter(__a						,__a						,stride=(stride_left, stride_right)						,stream=__a      ):
										# Put everything back in numpy scale
										_a      :       Dict   =						np.frombuffer(item['''raw''']						,dtype=__a      )
										_a      :       Dict   =						(
										    item['''stride'''][0] // size_of_sample,
										    item['''stride'''][1] // size_of_sample,
										)
										_a      :       str   =						sampling_rate
										audio_time += delta
										if datetime.datetime.now() > audio_time + 10 * delta:
															# We're late !! SKIP
															continue
										yield item



def   __UpperCAmelCase					(      __a :     Optional[int]						,__a :     int						,__a :     Tuple[int, int]						,__a :     bool = False      )     ->	Optional[int]:

					"""simple docstring"""

					_a      :       Any   =						b''''''
					_a ,   _a      :       List[str]   =						stride
					if stride_left + stride_right >= chunk_len:
										raise ValueError(
										    F"""Stride needs to be strictly smaller than chunk_len: ({stride_left}, {stride_right}) vs {chunk_len}"""      )
					_a      :       List[str]   =						0
					for raw in iterator:
										acc += raw
										if stream and len(__a      ) < chunk_len:
															_a      :       Dict   =						(_stride_left, 0)
															yield {"raw": acc[:chunk_len], "stride": stride, "partial": True}
										else:
															while len(__a      ) >= chunk_len:
																				# We are flushing the accumulator
																				_a      :       List[str]   =						(_stride_left, stride_right)
																				_a      :       List[Any]   =						{'''raw''': acc[:chunk_len], '''stride''': stride}
																				if stream:
																									_a      :       List[Any]   =						False
																				yield item
																				_a      :       Optional[Any]   =						stride_left
																				_a      :       Optional[Any]   =						acc[chunk_len - stride_left - stride_right :]
    # Last chunk
					if len(__a      ) > stride_left:
										_a      :       Optional[Any]   =						{'''raw''': acc, '''stride''': (_stride_left, 0)}
										if stream:
															_a      :       Dict   =						False
										yield item







def   __UpperCAmelCase					(      __a :     int						,__a :     int      )     ->	Tuple:

					"""simple docstring"""

					_a      :       Dict   =						2**24  # 16Mo
					try:
										with subprocess.Popen(__a						,stdout=subprocess.PIPE						,bufsize=__a      ) as ffmpeg_process:
															while True:
																				_a      :       int   =						ffmpeg_process.stdout.read(__a      )
																				if raw == b"":
																									break
																				yield raw
					except FileNotFoundError as error:
										raise ValueError('''ffmpeg was not found but is required to stream audio files from filename'''      ) from error



