





'''simple docstring'''







from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType


class 					__a      (_lowerCAmelCase     ):
							__a					:   List[str]									=       ['image_processor', 'tokenizer']
							__a					:   List[Any]									=       'BlipImageProcessor'
							__a					:   Tuple									=       'AutoTokenizer'

							def __init__(							self							:     Tuple       ,     __magic_name__							:     Union[str, Any]       ,     __magic_name__							:     int   )					->       List[str]:







													"""simple docstring"""
													UpperCAmelCase_			:      List[str]     						=  False
													super().__init__(_lowerCAmelCase       ,     _lowerCAmelCase   )
													UpperCAmelCase_			:      Union[str, Any]     						=  self.image_processor

							def __call__(							self							:     List[str]       ,     __magic_name__							:     ImageInput = None       ,     __magic_name__							:     Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Union[bool, str, PaddingStrategy] = False       ,     __magic_name__							:     Union[bool, str, TruncationStrategy] = None       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     int = 0       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     Optional[bool] = None       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = False       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     Optional[Union[str, TensorType]] = None       ,     **__magic_name__							:     Tuple       ,     )					->       BatchEncoding:







													"""simple docstring"""







													if images is None and text is None:
																			raise ValueError('''You have to specify either images or text.'''   )

													# Get only text
													if images is None:
																			UpperCAmelCase_			:      Any     						=  self.tokenizer
																			UpperCAmelCase_			:      Tuple     						=  self.tokenizer(
																			    text=_lowerCAmelCase       ,     add_special_tokens=_lowerCAmelCase       ,     padding=_lowerCAmelCase       ,     truncation=_lowerCAmelCase       ,     max_length=_lowerCAmelCase       ,     stride=_lowerCAmelCase       ,     pad_to_multiple_of=_lowerCAmelCase       ,     return_attention_mask=_lowerCAmelCase       ,     return_overflowing_tokens=_lowerCAmelCase       ,     return_special_tokens_mask=_lowerCAmelCase       ,     return_offsets_mapping=_lowerCAmelCase       ,     return_token_type_ids=_lowerCAmelCase       ,     return_length=_lowerCAmelCase       ,     verbose=_lowerCAmelCase       ,     return_tensors=_lowerCAmelCase       ,     **_lowerCAmelCase       ,     )
																			return text_encoding

													# add pixel_values
													UpperCAmelCase_			:      Tuple     						=  self.image_processor(_lowerCAmelCase       ,     return_tensors=_lowerCAmelCase   )

													if text is not None:
																			UpperCAmelCase_			:      Any     						=  self.tokenizer(
																			    text=_lowerCAmelCase       ,     add_special_tokens=_lowerCAmelCase       ,     padding=_lowerCAmelCase       ,     truncation=_lowerCAmelCase       ,     max_length=_lowerCAmelCase       ,     stride=_lowerCAmelCase       ,     pad_to_multiple_of=_lowerCAmelCase       ,     return_attention_mask=_lowerCAmelCase       ,     return_overflowing_tokens=_lowerCAmelCase       ,     return_special_tokens_mask=_lowerCAmelCase       ,     return_offsets_mapping=_lowerCAmelCase       ,     return_token_type_ids=_lowerCAmelCase       ,     return_length=_lowerCAmelCase       ,     verbose=_lowerCAmelCase       ,     return_tensors=_lowerCAmelCase       ,     **_lowerCAmelCase       ,     )
													else:
																			UpperCAmelCase_			:      Dict     						=  None

													if text_encoding is not None:
																			encoding_image_processor.update(_lowerCAmelCase   )

													return encoding_image_processor

							def     UpperCAmelCase__	(							self							:     Optional[int]       ,     *__magic_name__							:     Union[str, Any]       ,     **__magic_name__							:     Any   )					->       str:







													"""simple docstring"""
													return self.tokenizer.batch_decode(*_lowerCAmelCase       ,     **_lowerCAmelCase   )

							def     UpperCAmelCase__	(							self							:     Union[str, Any]       ,     *__magic_name__							:     Any       ,     **__magic_name__							:     Dict   )					->       Optional[Any]:







													"""simple docstring"""
													return self.tokenizer.decode(*_lowerCAmelCase       ,     **_lowerCAmelCase   )



							@property
							# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
							def     UpperCAmelCase__	(							self							:     List[str]   )					->       Tuple:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  self.tokenizer.model_input_names
													UpperCAmelCase_			:      Tuple     						=  self.image_processor.model_input_names
													return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names   )   )












'''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


snake_case_     :       Union[str, Any]						=  logging.get_logger(__name__)


class 					__a      (lowerCamelCase     ):
							__a					:   Tuple									=       ["pixel_values"]

							def __init__(							self							:     List[Any]       ,     __magic_name__							:     bool = True       ,     __magic_name__							:     int = 32       ,     __magic_name__							:     Union[str, Any]=PILImageResampling.BILINEAR       ,     __magic_name__							:     bool = True       ,     **__magic_name__							:     List[str]       ,     )					->       None:







													"""simple docstring"""
													UpperCAmelCase_			:      int     						=  do_resize
													UpperCAmelCase_			:      Tuple     						=  do_rescale
													UpperCAmelCase_			:      List[Any]     						=  size_divisor
													UpperCAmelCase_			:      Any     						=  resample
													super().__init__(**__magic_name__   )

							def     UpperCAmelCase__	(							self							:     Optional[Any]       ,     __magic_name__							:     np.ndarray       ,     __magic_name__							:     int       ,     __magic_name__							:     str       ,     __magic_name__							:     Optional[ChannelDimension] = None       ,     **__magic_name__							:     Tuple   )					->       np.ndarray:







													"""simple docstring"""
													UpperCAmelCase_						,       UpperCAmelCase_			:      List[str]     						=  get_image_size(__magic_name__   )
													# Rounds the height and width down to the closest multiple of size_divisor
													UpperCAmelCase_			:      Dict     						=  height // size_divisor * size_divisor
													UpperCAmelCase_			:      Dict     						=  width // size_divisor * size_divisor
													UpperCAmelCase_			:      Any     						=  resize(__magic_name__       ,     (new_h, new_w)       ,     resample=__magic_name__       ,     data_format=__magic_name__       ,     **__magic_name__   )
													return image

							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     np.ndarray       ,     __magic_name__							:     float       ,     __magic_name__							:     Optional[ChannelDimension] = None       ,     **__magic_name__							:     Optional[Any]   )					->       np.ndarray:







													"""simple docstring"""
													return rescale(image=__magic_name__       ,     scale=__magic_name__       ,     data_format=__magic_name__       ,     **__magic_name__   )



							def     UpperCAmelCase__	(							self							:     str       ,     __magic_name__							:     Union["PIL.Image.Image", TensorType, List["PIL.Image.Image"], List[TensorType]]       ,     __magic_name__							:     Optional[bool] = None       ,     __magic_name__							:     Optional[int] = None       ,     __magic_name__							:     Any=None       ,     __magic_name__							:     Optional[bool] = None       ,     __magic_name__							:     Optional[Union[TensorType, str]] = None       ,     __magic_name__							:     ChannelDimension = ChannelDimension.FIRST       ,     **__magic_name__							:     Tuple       ,     )					->       BatchFeature:







													"""simple docstring"""
													UpperCAmelCase_			:      Dict     						=  do_resize if do_resize is not None else self.do_resize
													UpperCAmelCase_			:      str     						=  do_rescale if do_rescale is not None else self.do_rescale
													UpperCAmelCase_			:      Any     						=  size_divisor if size_divisor is not None else self.size_divisor
													UpperCAmelCase_			:      Dict     						=  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'''   )

													UpperCAmelCase_			:      Optional[int]     						=  make_list_of_images(__magic_name__   )

													if not valid_images(__magic_name__   ):
																			raise ValueError('''Invalid image(s)'''   )

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

													if do_resize:
																			UpperCAmelCase_			:      str     						=  [self.resize(__magic_name__       ,     size_divisor=__magic_name__       ,     resample=__magic_name__   ) for image in images]

													if do_rescale:
																			UpperCAmelCase_			:      Tuple     						=  [self.rescale(__magic_name__       ,     scale=1 / 2_55   ) for image in images]

													UpperCAmelCase_			:      Union[str, Any]     						=  [to_channel_dimension_format(__magic_name__       ,     __magic_name__   ) for image in images]

													UpperCAmelCase_			:      int     						=  {'''pixel_values''': images}
													return BatchFeature(data=__magic_name__       ,     tensor_type=__magic_name__   )





