
'''simple docstring'''

from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import convert_to_rgb, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
    import PIL


__snake_case:	List[Any]										=      logging.get_logger(__name__)


class 			_UpperCAmelCase			(			a_     ):

     """simple docstring"""

     a_     						=       ["pixel_values"]


     def __init__(   self				,		lowerCAmelCase_ = True				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = PILImageResampling.BICUBIC				,		lowerCAmelCase_ = True				,		lowerCAmelCase_ = 1 / 2_55				,		lowerCAmelCase_ = True				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = True				,		**lowerCAmelCase_				,		):

       '''simple docstring'''

       super().__init__(**__SCREAMING_SNAKE_CASE			)
       a_   :						Union[str, Any]   =				size if size is not None else {"""height""": 3_84, """width""": 3_84}
       a_   :						Optional[int]   =				get_size_dict(__SCREAMING_SNAKE_CASE				,		default_to_square=__SCREAMING_SNAKE_CASE			)

       a_   :						Dict   =				do_resize
       a_   :						List[str]   =				size
       a_   :						str   =				resample
       a_   :						List[Any]   =				do_rescale
       a_   :						Dict   =				rescale_factor
       a_   :						Any   =				do_normalize
       a_   :						Tuple   =				image_mean if image_mean is not None else OPENAI_CLIP_MEAN
       a_   :						List[str]   =				image_std if image_std is not None else OPENAI_CLIP_STD
       a_   :						int   =				do_convert_rgb


     def 				_lowerCAmelCase	(   self				,		lowerCAmelCase_				,		lowerCAmelCase_				,		lowerCAmelCase_ = PILImageResampling.BICUBIC				,		lowerCAmelCase_ = None				,		**lowerCAmelCase_				,		):

       '''simple docstring'''

       a_   :						List[str]   =				get_size_dict(__SCREAMING_SNAKE_CASE				,		default_to_square=__SCREAMING_SNAKE_CASE			)
       if "height" not in size or "width" not in size:
         raise ValueError(f'''The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}'''			)
       a_   :						List[Any]   =				(size["""height"""], size["""width"""])
       return resize(__SCREAMING_SNAKE_CASE				,		size=__SCREAMING_SNAKE_CASE				,		resample=__SCREAMING_SNAKE_CASE				,		data_format=__SCREAMING_SNAKE_CASE				,		**__SCREAMING_SNAKE_CASE			)


     def 				_lowerCAmelCase	(   self				,		lowerCAmelCase_				,		lowerCAmelCase_				,		lowerCAmelCase_ = None				,		**lowerCAmelCase_				,		):

       '''simple docstring'''

       return rescale(__SCREAMING_SNAKE_CASE				,		scale=__SCREAMING_SNAKE_CASE				,		data_format=__SCREAMING_SNAKE_CASE				,		**__SCREAMING_SNAKE_CASE			)


     def 				_lowerCAmelCase	(   self				,		lowerCAmelCase_				,		lowerCAmelCase_				,		lowerCAmelCase_				,		lowerCAmelCase_ = None				,		**lowerCAmelCase_				,		):

       '''simple docstring'''

       return normalize(__SCREAMING_SNAKE_CASE				,		mean=__SCREAMING_SNAKE_CASE				,		std=__SCREAMING_SNAKE_CASE				,		data_format=__SCREAMING_SNAKE_CASE				,		**__SCREAMING_SNAKE_CASE			)






     def 				_lowerCAmelCase	(   self				,		lowerCAmelCase_				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = None				,		lowerCAmelCase_ = ChannelDimension.FIRST				,		**lowerCAmelCase_				,		):

       '''simple docstring'''

       a_   :						Tuple   =				do_resize if do_resize is not None else self.do_resize
       a_   :						Any   =				resample if resample is not None else self.resample
       a_   :						Tuple   =				do_rescale if do_rescale is not None else self.do_rescale
       a_   :						Tuple   =				rescale_factor if rescale_factor is not None else self.rescale_factor
       a_   :						List[Any]   =				do_normalize if do_normalize is not None else self.do_normalize
       a_   :						Union[str, Any]   =				image_mean if image_mean is not None else self.image_mean
       a_   :						Optional[Any]   =				image_std if image_std is not None else self.image_std
       a_   :						Optional[Any]   =				do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

       a_   :						Tuple   =				size if size is not None else self.size
       a_   :						Optional[int]   =				get_size_dict(__SCREAMING_SNAKE_CASE				,		default_to_square=__SCREAMING_SNAKE_CASE			)

       a_   :						List[str]   =				make_list_of_images(__SCREAMING_SNAKE_CASE			)

       if not valid_images(__SCREAMING_SNAKE_CASE			):
         raise ValueError(
             """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
             """torch.Tensor, tf.Tensor or jax.ndarray."""			)

       if do_resize and size is None or resample is None:
         raise ValueError("""Size and resample must be specified if do_resize is True."""			)

       if do_rescale and rescale_factor is None:
         raise ValueError("""Rescale factor must be specified if do_rescale is True."""			)

       if do_normalize and (image_mean is None or image_std is None):
         raise ValueError("""Image mean and std must be specified if do_normalize is True."""			)

       # PIL RGBA images are converted to RGB
       if do_convert_rgb:
         a_   :						Union[str, Any]   =				[convert_to_rgb(__SCREAMING_SNAKE_CASE			) for image in images]

       # All transformations expect numpy arrays.
       a_   :						Tuple   =				[to_numpy_array(__SCREAMING_SNAKE_CASE			) for image in images]

       if do_resize:
         a_   :						Dict   =				[self.resize(image=__SCREAMING_SNAKE_CASE				,		size=__SCREAMING_SNAKE_CASE				,		resample=__SCREAMING_SNAKE_CASE			) for image in images]

       if do_rescale:
         a_   :						Optional[Any]   =				[self.rescale(image=__SCREAMING_SNAKE_CASE				,		scale=__SCREAMING_SNAKE_CASE			) for image in images]

       if do_normalize:
         a_   :						Tuple   =				[self.normalize(image=__SCREAMING_SNAKE_CASE				,		mean=__SCREAMING_SNAKE_CASE				,		std=__SCREAMING_SNAKE_CASE			) for image in images]

       a_   :						Tuple   =				[to_channel_dimension_format(__SCREAMING_SNAKE_CASE				,		__SCREAMING_SNAKE_CASE			) for image in images]

       a_   :						int   =				BatchFeature(data={"""pixel_values""": images}				,		tensor_type=__SCREAMING_SNAKE_CASE			)

       return encoded_outputs



import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding
class  A_			(							a_			):
  _SCREAMING_SNAKE_CASE     					=      ["""image_processor""", """tokenizer"""]
  _SCREAMING_SNAKE_CASE     					=      """ChineseCLIPImageProcessor"""
  _SCREAMING_SNAKE_CASE     					=      ("""BertTokenizer""", """BertTokenizerFast""")

  def __init__(		self			:   List[str]  ,				__SCREAMING_SNAKE_CASE			:   Any=None  ,				__SCREAMING_SNAKE_CASE			:   Tuple=None  ,				**__SCREAMING_SNAKE_CASE			:   List[Any]							):
   __a							=	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  ,				)
    __a							=	kwargs.pop("feature_extractor"							)

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

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

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

   if images is not None:
    __a							=	self.image_processor(__SCREAMING_SNAKE_CASE  ,				return_tensors=__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

   if text is not None and images is not None:
    __a							=	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			:   int  ,				*__SCREAMING_SNAKE_CASE			:   Optional[Any]  ,				**__SCREAMING_SNAKE_CASE			:   str							):
   return self.tokenizer.batch_decode(*__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

  def 		_UpperCAmelCase (		self			:   List[Any]  ,				*__SCREAMING_SNAKE_CASE			:   Optional[int]  ,				**__SCREAMING_SNAKE_CASE			:   Optional[int]							):
   return self.tokenizer.decode(*__SCREAMING_SNAKE_CASE  ,				**__SCREAMING_SNAKE_CASE							)

  @property
  def 		_UpperCAmelCase (		self			:   Union[str, Any]							):
   __a							=	self.tokenizer.model_input_names
   __a							=	self.image_processor.model_input_names
   return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names							)							)

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


