





import warnings

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

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							snake_case  :   Any      =							["""image_processor""", """tokenizer"""]
							snake_case  :   Optional[int]      =							"""CLIPImageProcessor"""
							snake_case  :   Union[str, Any]      =							("""CLIPTokenizer""", """CLIPTokenizerFast""")






							def __init__(    self	,			__lowerCAmelCase=None	,			__lowerCAmelCase=None	,			**__lowerCAmelCase	):
														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."""	,			__lowerCAmelCase	,			)
																					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__(__lowerCAmelCase	,			__lowerCAmelCase	)






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

														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(__lowerCAmelCase	,			return_tensors=__lowerCAmelCase	,			**__lowerCAmelCase	)

														if images is not None:
																					UpperCamelCase__					  =      self.image_processor(__lowerCAmelCase	,			return_tensors=__lowerCAmelCase	,			**__lowerCAmelCase	)

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






							def 					_lowerCamelCase		(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														return self.tokenizer.batch_decode(*__lowerCAmelCase	,			**__lowerCAmelCase	)






							def 					_lowerCamelCase		(    self	,			*__lowerCAmelCase	,			**__lowerCAmelCase	):
														return self.tokenizer.decode(*__lowerCAmelCase	,			**__lowerCAmelCase	)






							@property
							def 					_lowerCamelCase		(    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 					_lowerCamelCase		(    self	):
														warnings.warn(
														    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""	,			__lowerCAmelCase	,			)
														return self.image_processor_class







							@property
							def 					_lowerCamelCase		(    self	):
														warnings.warn(
														    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""	,			__lowerCAmelCase	,			)
														return self.image_processor











import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase__           =			logging.get_logger(__name__)

class 							__SCREAMING_SNAKE_CASE       (  _a							):
							snake_case  :   Optional[Any]      =							"""encoder-decoder"""
							snake_case  :   Optional[int]      =							True






							def __init__(    self	,			**__lowerCAmelCase	):
														super().__init__(**__lowerCAmelCase	)
														assert (
														    "encoder" in kwargs and "decoder" in kwargs
														), "Config has to be initialized with encoder and decoder config"
														UpperCamelCase__					  =      kwargs.pop("""encoder"""	)
														UpperCamelCase__					  =      encoder_config.pop("""model_type"""	)
														UpperCamelCase__					  =      kwargs.pop("""decoder"""	)
														UpperCamelCase__					  =      decoder_config.pop("""model_type"""	)

														from ..auto.configuration_auto import AutoConfig

														UpperCamelCase__					  =      AutoConfig.for_model(__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      AutoConfig.for_model(__lowerCAmelCase	,			**__lowerCAmelCase	)
														UpperCamelCase__					  =      True






							@classmethod
							def 					_lowerCamelCase		(    cls	,			__lowerCAmelCase	,			__lowerCAmelCase	,			**__lowerCAmelCase	):
														logger.info("""Set `config.is_decoder=True` and `config.add_cross_attention=True` for decoder_config"""	)
														UpperCamelCase__					  =      True
														UpperCamelCase__					  =      True

														return cls(encoder=encoder_config.to_dict()	,			decoder=decoder_config.to_dict()	,			**__lowerCAmelCase	)







							def 					_lowerCamelCase		(    self	):
														UpperCamelCase__					  =      copy.deepcopy(self.__dict__	)
														UpperCamelCase__					  =      self.encoder.to_dict()
														UpperCamelCase__					  =      self.decoder.to_dict()
														UpperCamelCase__					  =      self.__class__.model_type
														return output




