
import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


__magic_name__            =  get_logger(__name__)




class 					_SCREAMING_SNAKE_CASE  (      enum.Enum ):
      _A						:		Tuple    	=     'all_checks'
      _A						:		Any    	=     'basic_checks'
      _A						:		str    	=     'no_checks'





class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





def 	SCREAMING_SNAKE_CASE__    (      __lowerCAmelCase    ,		__lowerCAmelCase    ,		__lowerCAmelCase=None							):
    if expected_checksums is None:
        logger.info("Unable to verify checksums."							)
        return
    if len(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							) > 0:
        raise ExpectedMoreDownloadedFiles(str(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							)							)
    if len(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							) > 0:
        raise UnexpectedDownloadedFile(str(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							)							)
    snake_case__						=				[url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
    snake_case__						=				" for " + verification_name if verification_name is not None else ""
    if len(__lowerCAmelCase							) > 0:
        raise NonMatchingChecksumError(
            F"""Checksums didn't match{for_verification_name}:\n"""
            F"""{bad_urls}\n"""
            "Set `verification_mode='no_checks'` to skip checksums verification and ignore this error"							)
    logger.info("All the checksums matched successfully" + for_verification_name							)




class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





class 					_SCREAMING_SNAKE_CASE  (      __UpperCamelCase ):
      pass





def 	SCREAMING_SNAKE_CASE__    (      __lowerCAmelCase    ,		__lowerCAmelCase							):
    if expected_splits is None:
        logger.info("Unable to verify splits sizes."							)
        return
    if len(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							) > 0:
        raise ExpectedMoreSplits(str(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							)							)
    if len(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							) > 0:
        raise UnexpectedSplits(str(set(__lowerCAmelCase							) - set(__lowerCAmelCase							)							)							)
    snake_case__						=				[
        {"expected": expected_splits[name], "recorded": recorded_splits[name]}
        for name in expected_splits
        if expected_splits[name].num_examples != recorded_splits[name].num_examples
    ]
    if len(__lowerCAmelCase							) > 0:
        raise NonMatchingSplitsSizesError(str(__lowerCAmelCase							)							)
    logger.info("All the splits matched successfully."							)





def 	SCREAMING_SNAKE_CASE__    (      __lowerCAmelCase    ,		__lowerCAmelCase = True							):
    if record_checksum:
        snake_case__						=				shaaaa()
        with open(__lowerCAmelCase    ,		"rb"							) as f:
            for chunk in iter(lambda: f.read(1 << 20							)    ,		B""							):
                m.update(__lowerCAmelCase							)
            snake_case__						=				m.hexdigest()
    else:
        snake_case__						=				None
    return {"num_bytes": os.path.getsize(__lowerCAmelCase							), "checksum": checksum}





def 	SCREAMING_SNAKE_CASE__    (      __lowerCAmelCase							):
    if dataset_size and config.IN_MEMORY_MAX_SIZE:
        return dataset_size < config.IN_MEMORY_MAX_SIZE
    else:
        return False





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


__magic_name__            =  {
    '''configuration_clip''': [
        '''CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''CLIPConfig''',
        '''CLIPOnnxConfig''',
        '''CLIPTextConfig''',
        '''CLIPVisionConfig''',
    ],
    '''processing_clip''': ['''CLIPProcessor'''],
    '''tokenization_clip''': ['''CLIPTokenizer'''],
}

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __magic_name__            =  ['''CLIPTokenizerFast''']

try:
     if not is_vision_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __magic_name__            =  ['''CLIPFeatureExtractor''']
     __magic_name__            =  ['''CLIPImageProcessor''']

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __magic_name__            =  [
         '''CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''CLIPModel''',
         '''CLIPPreTrainedModel''',
         '''CLIPTextModel''',
         '''CLIPTextModelWithProjection''',
         '''CLIPVisionModel''',
         '''CLIPVisionModelWithProjection''',
     ]

try:
     if not is_tf_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __magic_name__            =  [
         '''TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''TFCLIPModel''',
         '''TFCLIPPreTrainedModel''',
         '''TFCLIPTextModel''',
         '''TFCLIPVisionModel''',
     ]

try:
     if not is_flax_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __magic_name__            =  [
         '''FlaxCLIPModel''',
         '''FlaxCLIPPreTrainedModel''',
         '''FlaxCLIPTextModel''',
         '''FlaxCLIPTextPreTrainedModel''',
         '''FlaxCLIPVisionModel''',
         '''FlaxCLIPVisionPreTrainedModel''',
     ]


if TYPE_CHECKING:
     from .configuration_clip import (
         CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
         CLIPConfig,
         CLIPOnnxConfig,
         CLIPTextConfig,
         CLIPVisionConfig,
     )
     from .processing_clip import CLIPProcessor
     from .tokenization_clip import CLIPTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_clip_fast import CLIPTokenizerFast

     try:
          if not is_vision_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .feature_extraction_clip import CLIPFeatureExtractor
          from .image_processing_clip import CLIPImageProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_clip import (
              CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
              CLIPModel,
              CLIPPreTrainedModel,
              CLIPTextModel,
              CLIPTextModelWithProjection,
              CLIPVisionModel,
              CLIPVisionModelWithProjection,
          )

     try:
          if not is_tf_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_tf_clip import (
              TF_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
              TFCLIPModel,
              TFCLIPPreTrainedModel,
              TFCLIPTextModel,
              TFCLIPVisionModel,
          )

     try:
          if not is_flax_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_flax_clip import (
              FlaxCLIPModel,
              FlaxCLIPPreTrainedModel,
              FlaxCLIPTextModel,
              FlaxCLIPTextPreTrainedModel,
              FlaxCLIPVisionModel,
              FlaxCLIPVisionPreTrainedModel,
          )


else:
     import sys

     __magic_name__            =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



