



"""simple docstring"""

from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


a_			   =					logging.get_logger(__name__)







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Dict							       =		["""pixel_values"""]







						def __init__(self   ,		lowercase__ = True   ,		lowercase__ = 32   ,		lowercase__=PILImageResampling.BILINEAR   ,		lowercase__ = True   ,		**lowercase__   ,		):
											snake_case_					:		Union[str, Any] 					=					do_resize
											snake_case_					:		Dict 					=					do_rescale
											snake_case_					:		int 					=					size_divisor
											snake_case_					:		int 					=					resample
											super().__init__(**lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__   ,		lowercase__   ,		lowercase__ = None   ,		**lowercase__       ):
											snake_case_					:		Dict 					=					get_image_size(lowercase__       )
											# Rounds the height and width down to the closest multiple of size_divisor
											snake_case_					:		Optional[int] 					=					height // size_divisor * size_divisor
											snake_case_					:		int 					=					width // size_divisor * size_divisor
											snake_case_					:		str 					=					resize(lowercase__   ,		(new_h, new_w)   ,		resample=lowercase__   ,		data_format=lowercase__   ,		**lowercase__       )
											return image







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__   ,		lowercase__ = None   ,		**lowercase__       ):
											return rescale(image=lowercase__   ,		scale=lowercase__   ,		data_format=lowercase__   ,		**lowercase__       )







						def 						__UpperCamelCase							(self   ,		lowercase__   ,		lowercase__ = None   ,		lowercase__ = None   ,		lowercase__=None   ,		lowercase__ = None   ,		lowercase__ = None   ,		lowercase__ = ChannelDimension.FIRST   ,		**lowercase__   ,		):
											snake_case_					:		Optional[int] 					=					do_resize if do_resize is not None else self.do_resize
											snake_case_					:		List[Any] 					=					do_rescale if do_rescale is not None else self.do_rescale
											snake_case_					:		int 					=					size_divisor if size_divisor is not None else self.size_divisor
											snake_case_					:		List[str] 					=					resample if resample is not None else self.resample

											if do_resize and size_divisor is None:
																raise ValueError("""size_divisor is required for resizing"""       )

											snake_case_					:		int 					=					make_list_of_images(lowercase__       )

											if not valid_images(lowercase__       ):
																raise ValueError("""Invalid image(s)"""       )

											# All transformations expect numpy arrays.
											snake_case_					:		List[str] 					=					[to_numpy_array(lowercase__       ) for img in images]

											if do_resize:
																snake_case_					:		Any 					=					[self.resize(lowercase__   ,		size_divisor=lowercase__   ,		resample=lowercase__       ) for image in images]

											if do_rescale:
																snake_case_					:		Dict 					=					[self.rescale(lowercase__   ,		scale=1 / 2_55       ) for image in images]

											snake_case_					:		int 					=					[to_channel_dimension_format(lowercase__   ,		lowercase__       ) for image in images]

											snake_case_					:		int 					=					{"""pixel_values""": images}
											return BatchFeature(data=lowercase__   ,		tensor_type=lowercase__       )





"""simple docstring"""

import warnings

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







class    __lowercase     (					_UpperCAmelCase):







						"""simple docstring"""







						_A		:							Union[str, Any]							       =		["""image_processor""", """tokenizer"""]
						_A		:							str							       =		"""ChineseCLIPImageProcessor"""
						_A		:							Tuple							       =		("""BertTokenizer""", """BertTokenizerFast""")







						def __init__(self   ,		lowercase__=None   ,		lowercase__=None   ,		**lowercase__       ):
											snake_case_					:		Any 					=					None
											if "feature_extractor" in kwargs:
																warnings.warn(
																    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
																    """ instead."""   ,		lowercase__   ,		)
																snake_case_					:		Optional[Any] 					=					kwargs.pop("""feature_extractor"""       )

											snake_case_					:		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__(lowercase__   ,		lowercase__       )
											snake_case_					:		Union[str, Any] 					=					self.image_processor







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

											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:
																snake_case_					:		Any 					=					self.tokenizer(lowercase__   ,		return_tensors=lowercase__   ,		**lowercase__       )

											if images is not None:
																snake_case_					:		Tuple 					=					self.image_processor(lowercase__   ,		return_tensors=lowercase__   ,		**lowercase__       )

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







						def 						__UpperCamelCase							(self   ,		*lowercase__   ,		**lowercase__       ):
											return self.tokenizer.batch_decode(*lowercase__   ,		**lowercase__       )







						def 						__UpperCamelCase							(self   ,		*lowercase__   ,		**lowercase__       ):
											return self.tokenizer.decode(*lowercase__   ,		**lowercase__       )







						@property
						def 						__UpperCamelCase							(self       ):
											snake_case_					:		Optional[int] 					=					self.tokenizer.model_input_names
											snake_case_					:		Union[str, Any] 					=					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."""   ,		lowercase__   ,		)
											return self.image_processor_class




