


"""simple docstring"""






import importlib.metadata
import operator
import re
import sys
from typing import Optional

from packaging import version


__snake_case		=       {
    '''<''': operator.lt,
    '''<=''': operator.le,
    '''==''': operator.eq,
    '''!=''': operator.ne,
    '''>=''': operator.ge,
    '''>''': operator.gt,
}
def       A_   (   _lowerCAmelCase     :					List[str],     _lowerCAmelCase     :					str,     _lowerCAmelCase     :					Union[str, Any],     _lowerCAmelCase     :					List[str],     _lowerCAmelCase     :					str,     _lowerCAmelCase     :					Dict       ):






     """simple docstring"""

     if got_ver is None or want_ver is None:
          raise ValueError(
              f'Unable to compare versions for {requirement}: need={want_ver} found={got_ver}. This is unusual. Consider'
              f' reinstalling {pkg}.'       )
     if not ops[op](version.parse(_lowerCAmelCase       ),     version.parse(_lowerCAmelCase       )       ):
          raise ImportError(
              f'{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}'       )
def       A_   (   _lowerCAmelCase     :					str,     _lowerCAmelCase     :					Optional[str] = None       ):






     """simple docstring"""

     _a    	=				f'\n{hint}' if hint is not None else ''''''

     # non-versioned check
     if re.match(R'''^[\w_\-\d]+$''',     _lowerCAmelCase       ):
          _a	,      _a	,      _a    	=				requirement, None, None
     else:
          _a    	=				re.findall(R'''^([^!=<>\s]+)([\s!=<>]{1,2}.+)''',     _lowerCAmelCase       )
          if not match:
               raise ValueError(
                   '''requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but'''
                   f' got {requirement}'       )
          _a	,      _a    	=				match[0]
          _a    	=				want_full.split(''','''       )  # there could be multiple requirements
          _a    	=				{}
          for w in want_range:
               _a    	=				re.findall(R'''^([\s!=<>]{1,2})(.+)''',     _lowerCAmelCase       )
               if not match:
                    raise ValueError(
                        '''requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23,'''
                        f' but got {requirement}'       )
               _a	,      _a    	=				match[0]
               _a    	=				want_ver
               if op not in ops:
                    raise ValueError(f'{requirement}: need one of {list(ops.keys()       )}, but got {op}'       )

    # special case
     if pkg == "python":
          _a    	=				'''.'''.join([str(_lowerCAmelCase       ) for x in sys.version_info[:3]]       )
          for op, want_ver in wanted.items():
               _compare_versions(_lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase       )
          return

     # check if any version is installed
     try:
          _a    	=				importlib.metadata.version(_lowerCAmelCase       )
     except importlib.metadata.PackageNotFoundError:
          raise importlib.metadata.PackageNotFoundError(
              f'The \'{requirement}\' distribution was not found and is required by this application. {hint}'       )

     # check that the right version is installed if version number or a range was provided
     if want_ver is not None:
          for op, want_ver in wanted.items():
               _compare_versions(_lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase,     _lowerCAmelCase       )

def       A_   (   _lowerCAmelCase     :					Dict       ):






     """simple docstring"""

     _a    	=				'''Try: pip install transformers -U or pip install -e \'.[dev]\' if you\'re working with git main'''
     return require_version(_lowerCAmelCase,     _lowerCAmelCase       )



"""simple docstring"""






import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding


class     __lowerCamelCase  (					a__				):

     '''simple docstring'''
     A_       :	Optional[int]    =		['image_processor', 'tokenizer']
     A_       :	Union[str, Any]    =		'ChineseCLIPImageProcessor'
     A_       :	Union[str, Any]    =		('BertTokenizer', 'BertTokenizerFast')


     def __init__(      self    ,				__UpperCAmelCase=None    ,				__UpperCAmelCase=None    ,				**__UpperCAmelCase							)       ->							List[str]:
          _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.'''    ,				__UpperCAmelCase    ,				)
               _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__(__UpperCAmelCase    ,				__UpperCAmelCase							)
          _a    	=				self.image_processor


     def __call__(      self    ,				__UpperCAmelCase=None    ,				__UpperCAmelCase=None    ,				__UpperCAmelCase=None    ,				**__UpperCAmelCase							)       ->							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(__UpperCAmelCase    ,				return_tensors=__UpperCAmelCase    ,				**__UpperCAmelCase							)

          if images is not None:
               _a    	=				self.image_processor(__UpperCAmelCase    ,				return_tensors=__UpperCAmelCase    ,				**__UpperCAmelCase							)

          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(**__UpperCAmelCase							)    ,				tensor_type=__UpperCAmelCase							)


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


     def 							_UpperCAmelCase      (      self    ,				*__UpperCAmelCase    ,				**__UpperCAmelCase							)       ->							Optional[int]:
          return self.tokenizer.decode(*__UpperCAmelCase    ,				**__UpperCAmelCase							)


     @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							)       ->							Tuple:
          warnings.warn(
              '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''    ,				__UpperCAmelCase    ,				)
          return self.image_processor_class