



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

from .. import config
from .logging import get_logger


a_      :      Union[str, Any]    =     get_logger(__name__)
class    __UpperCamelCase			(       enum.Enum				):

 """simple docstring"""



 _lowercase   :    Dict      						=					'''all_checks'''
 _lowercase   :    List[Any]      						=					'''basic_checks'''
 _lowercase   :    List[Any]      						=					'''no_checks'''





class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""








class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""








class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""








class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""









def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase							,  __UpperCAmelCase=None       ):
 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       )       )       )
 a__												= [url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
 a__												= ''' 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    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""








class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""








class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""








class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""









def     __a					(		__UpperCAmelCase							,  __UpperCAmelCase       ):
 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       )       )       )
 a__												= [
     {'''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     __a					(		__UpperCAmelCase							,  __UpperCAmelCase = True       ):
 if record_checksum:
  a__												= shaaaa()
  with open(__UpperCAmelCase							,  '''rb'''       ) as f:
   for chunk in iter(lambda: f.read(1 << 20       )							,  B''''''       ):
    m.update(__UpperCAmelCase       )
   a__												= m.hexdigest()
 else:
  a__												= None
 return {"num_bytes": os.path.getsize(__UpperCAmelCase       ), "checksum": checksum}






def     __a					(		__UpperCAmelCase       ):
 if dataset_size and config.IN_MEMORY_MAX_SIZE:
  return dataset_size < config.IN_MEMORY_MAX_SIZE
 else:
  return False










import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
class    __UpperCamelCase			(       _lowercase				):

 """simple docstring"""



 _lowercase   :    Optional[Any]      						=					['''image_processor''', '''tokenizer''']
 _lowercase   :    Optional[int]      						=					'''ChineseCLIPImageProcessor'''
 _lowercase   :    List[Any]      						=					('''BertTokenizer''', '''BertTokenizerFast''')

 def __init__(	self		,				SCREAMING_SNAKE_CASE=None		,				SCREAMING_SNAKE_CASE=None		,				**SCREAMING_SNAKE_CASE      ) ->			Union[str, Any]:
  a__												= None
  if "feature_extractor" in kwargs:
   warnings.warn(
       '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
       ''' instead.'''		,				SCREAMING_SNAKE_CASE		,				)
   a__												= kwargs.pop('''feature_extractor'''      )

  a__												= image_processor if image_processor is not None else feature_extractor
  if image_processor is None:
   raise ValueError('''You need to specify an `image_processor`.'''      )
  if tokenizer is None:
   raise ValueError('''You need to specify a `tokenizer`.'''      )

  super().__init__(SCREAMING_SNAKE_CASE		,				SCREAMING_SNAKE_CASE      )
  a__												= self.image_processor

 def __call__(	self		,				SCREAMING_SNAKE_CASE=None		,				SCREAMING_SNAKE_CASE=None		,				SCREAMING_SNAKE_CASE=None		,				**SCREAMING_SNAKE_CASE      ) ->			List[str]:

  if text is None and images is None:
   raise ValueError('''You have to specify either text or images. Both cannot be none.'''      )

  if text is not None:
   a__												= self.tokenizer(SCREAMING_SNAKE_CASE		,				return_tensors=SCREAMING_SNAKE_CASE		,				**SCREAMING_SNAKE_CASE      )

  if images is not None:
   a__												= self.image_processor(SCREAMING_SNAKE_CASE		,				return_tensors=SCREAMING_SNAKE_CASE		,				**SCREAMING_SNAKE_CASE      )

  if text is not None and images is not None:
   a__												= image_features.pixel_values
   return encoding
  elif text is not None:
   return encoding
  else:
   return BatchEncoding(data=dict(**SCREAMING_SNAKE_CASE      )		,				tensor_type=SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self		,				*SCREAMING_SNAKE_CASE		,				**SCREAMING_SNAKE_CASE      ) ->			List[str]:
  return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE		,				**SCREAMING_SNAKE_CASE      )

 def 						_UpperCAmelCase       (	self		,				*SCREAMING_SNAKE_CASE		,				**SCREAMING_SNAKE_CASE      ) ->			int:
  return self.tokenizer.decode(*SCREAMING_SNAKE_CASE		,				**SCREAMING_SNAKE_CASE      )

 @property
 def 						_UpperCAmelCase       (	self      ) ->			List[str]:
  a__												= self.tokenizer.model_input_names
  a__												= self.image_processor.model_input_names
  return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names      )      )



 @property
 def 						_UpperCAmelCase       (	self      ) ->			Optional[int]:
  warnings.warn(
      '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''		,				SCREAMING_SNAKE_CASE		,				)
  return self.image_processor_class





