

_lowerCamelCase      :					Optional[Any]					    =      '''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'''





def      A__					(			__A  :						bytes			)					->bytes:
      # Make sure the supplied data is a bytes-like object
      if not isinstance(__A     ,				__A			):
            __A    =F'''a bytes-like object is required, not \'{data.__class__.__name__}\''''
            raise TypeError(__A			)

      __A    =''''''.join(bin(__A			)[2:].zfill(8			) for byte in data			)

      __A    =len(__A			) % 6 != 0

      if padding_needed:
            # The padding that will be added later
            __A    =b'''=''' * ((6 - len(__A			) % 6) // 2)

            # Append binary_stream with arbitrary binary digits (0's by default) to make its
            # length a multiple of 6.
            binary_stream += "0" * (6 - len(__A			) % 6)
      else:
            __A    =b''''''

      # Encode every 6 binary digits to their corresponding Base64 character
      return (
          "".join(
              B64_CHARSET[int(binary_stream[index : index + 6]     ,				2			)]
              for index in range(0     ,				len(__A			)     ,				6			)			).encode()
          + padding
      )





def      A__					(			__A  :						str			)					->bytes:
      # Make sure encoded_data is either a string or a bytes-like object
      if not isinstance(__A     ,				__A			) and not isinstance(__A     ,				__A			):
            __A    =(
                '''argument should be a bytes-like object or ASCII string, '''
                F'''not \'{encoded_data.__class__.__name__}\''''
            )
            raise TypeError(__A			)

      # In case encoded_data is a bytes-like object, make sure it contains only
      # ASCII characters so we convert it to a string object
      if isinstance(__A     ,				__A			):
            try:
                  __A    =encoded_data.decode('''utf-8'''			)
            except UnicodeDecodeError:
                  raise ValueError('''base64 encoded data should only contain ASCII characters'''			)

      __A    =encoded_data.count('''='''			)

      # Check if the encoded string contains non base64 characters
      if padding:
            assert all(
                char in B64_CHARSET for char in encoded_data[:-padding]			), "Invalid base64 character(s) found."
      else:
            assert all(
                char in B64_CHARSET for char in encoded_data			), "Invalid base64 character(s) found."

      # Check the padding
      assert len(__A			) % 4 == 0 and padding < 3, "Incorrect padding"

      if padding:
            # Remove padding if there is one
            __A    =encoded_data[:-padding]

            __A    =''''''.join(
                bin(B64_CHARSET.index(__A			)			)[2:].zfill(6			) for char in encoded_data			)[: -padding * 2]
      else:
            __A    =''''''.join(
                bin(B64_CHARSET.index(__A			)			)[2:].zfill(6			) for char in encoded_data			)

      __A    =[
          int(binary_stream[index : index + 8]     ,				2			)
          for index in range(0     ,				len(__A			)     ,				8			)
      ]

      return bytes(__A			)


if __name__ == "__main__":
   import doctest

   doctest.testmod()





from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
   if not (is_transformers_available() and is_torch_available() and is_transformers_version('''>=''', '''4.25.0''')):
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   from ...utils.dummy_torch_and_transformers_objects import (
       VersatileDiffusionDualGuidedPipeline,
       VersatileDiffusionImageVariationPipeline,
       VersatileDiffusionPipeline,
       VersatileDiffusionTextToImagePipeline,
   )
else:
   from .modeling_text_unet import UNetFlatConditionModel
   from .pipeline_versatile_diffusion import VersatileDiffusionPipeline
   from .pipeline_versatile_diffusion_dual_guided import VersatileDiffusionDualGuidedPipeline
   from .pipeline_versatile_diffusion_image_variation import VersatileDiffusionImageVariationPipeline
   from .pipeline_versatile_diffusion_text_to_image import VersatileDiffusionTextToImagePipeline


