




import warnings

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




class       _A				(		__UpperCAmelCase     ):
		__a					    =       ["""image_processor""", """tokenizer"""]
		__a					    =       """ChineseCLIPImageProcessor"""
		__a					    =       ("""BertTokenizer""", """BertTokenizerFast""")






		def __init__(    self						,		_SCREAMING_SNAKE_CASE=None						,		_SCREAMING_SNAKE_CASE=None						,		**_SCREAMING_SNAKE_CASE			):
								_UpperCAmelCase      =			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						,		)
														_UpperCAmelCase      =			kwargs.pop("""feature_extractor"""			)

								_UpperCAmelCase      =			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			)
								_UpperCAmelCase      =			self.image_processor






		def __call__(    self						,		_SCREAMING_SNAKE_CASE=None						,		_SCREAMING_SNAKE_CASE=None						,		_SCREAMING_SNAKE_CASE=None						,		**_SCREAMING_SNAKE_CASE			):

								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:
														_UpperCAmelCase      =			self.tokenizer(_SCREAMING_SNAKE_CASE						,		return_tensors=_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			)

								if images is not None:
														_UpperCAmelCase      =			self.image_processor(_SCREAMING_SNAKE_CASE						,		return_tensors=_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			)

								if text is not None and images is not None:
														_UpperCAmelCase      =			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			):
								return self.tokenizer.batch_decode(*_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			)






		def 				UpperCAmelCase (    self						,		*_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			):
								return self.tokenizer.decode(*_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			)






		@property
		def 				UpperCAmelCase (    self			):
								_UpperCAmelCase      =			self.tokenizer.model_input_names
								_UpperCAmelCase      =			self.image_processor.model_input_names
								return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names			)			)






		@property
		def 				UpperCAmelCase (    self			):
								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





from typing import Dict

from .base import GenericTensor, Pipeline




class       _A				(		__lowercase     ):






		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE=None						,		_SCREAMING_SNAKE_CASE=None						,		_SCREAMING_SNAKE_CASE=None						,		**_SCREAMING_SNAKE_CASE			):
								if tokenize_kwargs is None:
														_UpperCAmelCase      =			{}

								if truncation is not None:
														if "truncation" in tokenize_kwargs:
																				raise ValueError(
																				    """truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)"""			)
														_UpperCAmelCase      =			truncation

								_UpperCAmelCase      =			tokenize_kwargs

								_UpperCAmelCase      =			{}
								if return_tensors is not None:
														_UpperCAmelCase      =			return_tensors

								return preprocess_params, {}, postprocess_params






		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			):
								_UpperCAmelCase      =			self.framework
								_UpperCAmelCase      =			self.tokenizer(_SCREAMING_SNAKE_CASE						,		return_tensors=_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			)
								return model_inputs






		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE			):
								_UpperCAmelCase      =			self.model(**_SCREAMING_SNAKE_CASE			)
								return model_outputs






		def 				UpperCAmelCase (    self						,		_SCREAMING_SNAKE_CASE						,		_SCREAMING_SNAKE_CASE=False			):
								# [0] is the first available tensor, logits or last_hidden_state.
								if return_tensors:
														return model_outputs[0]
								if self.framework == "pt":
														return model_outputs[0].tolist()
								elif self.framework == "tf":
														return model_outputs[0].numpy().tolist()






		def __call__(    self						,		*_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			):
								return super().__call__(*_SCREAMING_SNAKE_CASE						,		**_SCREAMING_SNAKE_CASE			)