


"""simple docstring"""






import pytest

import datasets


# Import fixture modules as plugins
__snake_case		=       ['''tests.fixtures.files''', '''tests.fixtures.hub''', '''tests.fixtures.fsspec''']
def       A_   (   _lowerCAmelCase     :					str,     _lowerCAmelCase     :					int       ):






     """simple docstring"""

     for item in items:
          if any(marker in item.keywords for marker in ['''integration''', '''unit''']       ):
               continue
          item.add_marker(pytest.mark.unit       )
def       A_   (   _lowerCAmelCase     :					Dict       ):






     """simple docstring"""

     config.addinivalue_line('''markers''',     '''torchaudio_latest: mark test to run with torchaudio>=0.12'''       )
@pytest.fixture(autouse=lowerCAmelCase__       )
def       A_   (   _lowerCAmelCase     :					List[Any],     _lowerCAmelCase     :					Optional[int]       ):






     """simple docstring"""

     _a    	=				tmp_path_factory.getbasetemp() / '''cache'''
     _a    	=				test_hf_cache_home / '''datasets'''
     _a    	=				test_hf_cache_home / '''metrics'''
     _a    	=				test_hf_cache_home / '''modules'''
     monkeypatch.setattr('''datasets.config.HF_DATASETS_CACHE''',     str(lowerCAmelCase__       )       )
     monkeypatch.setattr('''datasets.config.HF_METRICS_CACHE''',     str(lowerCAmelCase__       )       )
     monkeypatch.setattr('''datasets.config.HF_MODULES_CACHE''',     str(lowerCAmelCase__       )       )
     _a    	=				test_hf_datasets_cache / '''downloads'''
     monkeypatch.setattr('''datasets.config.DOWNLOADED_DATASETS_PATH''',     str(lowerCAmelCase__       )       )
     _a    	=				test_hf_datasets_cache / '''downloads''' / '''extracted'''
     monkeypatch.setattr('''datasets.config.EXTRACTED_DATASETS_PATH''',     str(lowerCAmelCase__       )       )
@pytest.fixture(autouse=lowerCAmelCase__,     scope='''session'''       )
def       A_   (   ):






     """simple docstring"""

     datasets.disable_progress_bar()
@pytest.fixture(autouse=lowerCAmelCase__       )
def       A_   (   _lowerCAmelCase     :					Dict       ):






     """simple docstring"""

     monkeypatch.setattr('''datasets.config.HF_UPDATE_DOWNLOAD_COUNTS''',     lowerCAmelCase__       )

@pytest.fixture
def       A_   (   _lowerCAmelCase     :					Any       ):






     """simple docstring"""

     monkeypatch.setattr('''sqlalchemy.util.deprecations.SILENCE_UBER_WARNING''',     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