





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

from .. import config
from .logging import get_logger


_UpperCAmelCase       : str			     =       get_logger(__name__)

class      lowerCAmelCase							(      enum.Enum    ):
 UpperCAmelCase__									=	"""all_checks"""
 UpperCAmelCase__									=	"""basic_checks"""
 UpperCAmelCase__									=	"""no_checks"""


class      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


class      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


class      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


class      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


def  SCREAMING_SNAKE_CASE   ( _UpperCAmelCase		,			_UpperCAmelCase		,			_UpperCAmelCase=None				)    ->  Optional[int]:
    if expected_checksums is None:
        logger.info('Unable to verify checksums.'				)
        return
    if len(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				) > 0:
        raise ExpectedMoreDownloadedFiles(str(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				)				)
    if len(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				) > 0:
        raise UnexpectedDownloadedFile(str(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				)				)
    lowerCamelCase__					:   Any      				=	[url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
    lowerCamelCase__					:   Optional[int]      				=	' for ' + verification_name if verification_name is not None else ''
    if len(_UpperCAmelCase				) > 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      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


class      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


class      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


class      lowerCAmelCase							(      __UpperCamelCase    ):
 pass


def  SCREAMING_SNAKE_CASE   ( _UpperCAmelCase		,			_UpperCAmelCase				)    ->  List[str]:
    if expected_splits is None:
        logger.info('Unable to verify splits sizes.'				)
        return
    if len(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				) > 0:
        raise ExpectedMoreSplits(str(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				)				)
    if len(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				) > 0:
        raise UnexpectedSplits(str(set(_UpperCAmelCase				) - set(_UpperCAmelCase				)				)				)
    lowerCamelCase__					:   Dict      				=	[
        {'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(_UpperCAmelCase				) > 0:
        raise NonMatchingSplitsSizesError(str(_UpperCAmelCase				)				)
    logger.info('All the splits matched successfully.'				)


def  SCREAMING_SNAKE_CASE   ( _UpperCAmelCase		,			_UpperCAmelCase = True				)    ->  dict:
    if record_checksum:
        lowerCamelCase__					:   Union[str, Any]      				=	shaaaa()
        with open(_UpperCAmelCase		,			'rb'				) as f:
            for chunk in iter(lambda: f.read(1 << 20				)		,			b''				):
                m.update(_UpperCAmelCase				)
            lowerCamelCase__					:   Tuple      				=	m.hexdigest()
    else:
        lowerCamelCase__					:   Any      				=	None
    return {"num_bytes": os.path.getsize(_UpperCAmelCase				), "checksum": checksum}


def  SCREAMING_SNAKE_CASE   ( _UpperCAmelCase				)    ->  List[str]:
    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,
)


_UpperCAmelCase       : Optional[Any]			     =       {
    """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:
    _UpperCAmelCase       : int			     =       ["""CLIPTokenizerFast"""]

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCAmelCase       : Optional[int]			     =       ["""CLIPFeatureExtractor"""]
    _UpperCAmelCase       : Union[str, Any]			     =       ["""CLIPImageProcessor"""]

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

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

try:
    if not is_flax_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    _UpperCAmelCase       : Optional[int]			     =       [
        """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

    _UpperCAmelCase       : Optional[Any]			     =       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





