






import warnings

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







class        lowercase__      (							snake_case__       ):
			_UpperCAmelCase		:Union[str, Any]             =			["image_processor", "tokenizer"]
			_UpperCAmelCase		:Optional[Any]             =			"ChineseCLIPImageProcessor"
			_UpperCAmelCase		:str             =			("BertTokenizer", "BertTokenizerFast")


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

										lowerCamelCase_	:							List[str]									=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__(snake_case__       ,	snake_case__ )
										lowerCamelCase_	:							List[Any]									=self.image_processor


			def __call__(				self					:  Dict       ,	snake_case__					:  Optional[Any]=None       ,	snake_case__					:  int=None       ,	snake_case__					:  Dict=None       ,	**snake_case__					:  Tuple ):

										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:
																	lowerCamelCase_	:							Optional[Any]									=self.tokenizer(snake_case__       ,	return_tensors=snake_case__       ,	**snake_case__ )

										if images is not None:
																	lowerCamelCase_	:							Optional[Any]									=self.image_processor(snake_case__       ,	return_tensors=snake_case__       ,	**snake_case__ )

										if text is not None and images is not None:
																	lowerCamelCase_	:							List[str]									=image_features.pixel_values
																	return encoding
										elif text is not None:
																	return encoding
										else:
																	return BatchEncoding(data=dict(**snake_case__ )       ,	tensor_type=snake_case__ )


			def      UpperCAmelCase__						(				self					:  Optional[Any]       ,	*snake_case__					:  Dict       ,	**snake_case__					:  Dict ):
										return self.tokenizer.batch_decode(*snake_case__       ,	**snake_case__ )


			def      UpperCAmelCase__						(				self					:  Optional[int]       ,	*snake_case__					:  List[Any]       ,	**snake_case__					:  Dict ):
										return self.tokenizer.decode(*snake_case__       ,	**snake_case__ )


			@property
			def      UpperCAmelCase__						(				self					:  int ):
										lowerCamelCase_	:							str									=self.tokenizer.model_input_names
										lowerCamelCase_	:							Optional[Any]									=self.image_processor.model_input_names
										return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names ) )


			@property
			def      UpperCAmelCase__						(				self					:  List[Any] ):
										warnings.warn(
										    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."       ,	snake_case__       ,	)
										return self.image_processor_class











"""simple docstring"""



import pytest

from datasets.parallel import ParallelBackendConfig, parallel_backend
from datasets.utils.py_utils import map_nested

from .utils import require_dill_gt_0_3_2, require_joblibspark, require_not_windows

def 			_snake_case    (					lowerCamelCase__     :   Any  )    ->     Union[str, Any]:  # picklable for multiprocessing
							return i + 1

@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
def 			_snake_case    (					)    ->     List[Any]:
							with parallel_backend("spark"  ):
														assert ParallelBackendConfig.backend_name == "spark"

							lowerCamelCase_	:							Optional[Any]									=[1, 2, 3]
							with pytest.raises(lowerCamelCase__  ):
														with parallel_backend("unsupported backend"  ):
																					map_nested(lowerCamelCase__    ,						lowerCamelCase__    ,						num_proc=2  )

							with pytest.raises(lowerCamelCase__  ):
														with parallel_backend("unsupported backend"  ):
																					map_nested(lowerCamelCase__    ,						lowerCamelCase__    ,						num_proc=-1  )

@require_dill_gt_0_3_2
@require_joblibspark
@require_not_windows
@pytest.mark.parametrize("num_proc"    ,						[2, -1]  )
def 			_snake_case    (					lowerCamelCase__     :   Tuple  )    ->     Optional[Any]:
							lowerCamelCase_	:							str									=[1, 2]
							lowerCamelCase_	:							List[str]									={"a": 1, "b": 2}
							lowerCamelCase_	:							List[str]									={"a": [1, 2], "b": [3, 4]}
							lowerCamelCase_	:							Optional[int]									={"a": {"1": 1}, "b": 2}
							lowerCamelCase_	:							int									={"a": 1, "b": 2, "c": 3, "d": 4}
							lowerCamelCase_	:							Optional[int]									=[2, 3]
							lowerCamelCase_	:							List[Any]									={"a": 2, "b": 3}
							lowerCamelCase_	:							int									={"a": [2, 3], "b": [4, 5]}
							lowerCamelCase_	:							str									={"a": {"1": 2}, "b": 3}
							lowerCamelCase_	:							Dict									={"a": 2, "b": 3, "c": 4, "d": 5}

							with parallel_backend("spark"  ):
														assert map_nested(lowerCamelCase__    ,						lowerCamelCase__    ,						num_proc=lowerCamelCase__  ) == expected_map_nested_sa
														assert map_nested(lowerCamelCase__    ,						lowerCamelCase__    ,						num_proc=lowerCamelCase__  ) == expected_map_nested_sa
														assert map_nested(lowerCamelCase__    ,						lowerCamelCase__    ,						num_proc=lowerCamelCase__  ) == expected_map_nested_sa
														assert map_nested(lowerCamelCase__    ,						lowerCamelCase__    ,						num_proc=lowerCamelCase__  ) == expected_map_nested_sa
														assert map_nested(lowerCamelCase__    ,						lowerCamelCase__    ,						num_proc=lowerCamelCase__  ) == expected_map_nested_sa



