





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 (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    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


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


if is_vision_available():
					import PIL


class   A      (SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''




			__lowerCamelCase     :	Any          =   ['''pixel_values''']






			def __init__(      self       :   Union[str, Any]							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Dict[str, int] = None							,     __lowerCAmelCase       :   PILImageResampling = PILImageResampling.BICUBIC							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Dict[str, int] = None							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Union[int, float] = 1 / 2_55							,     __lowerCAmelCase       :   bool = True							,     __lowerCAmelCase       :   Optional[Union[float, List[float]]] = None							,     __lowerCAmelCase       :   Optional[Union[float, List[float]]] = None							,     __lowerCAmelCase       :   bool = True							,     **__lowerCAmelCase       :   str							,     )     ->     None:







					"""simple docstring"""






					super().__init__(**__lowerCAmelCase       )
					A__  				=       size if size is not None else {"""shortest_edge""": 2_24}
					A__  				=       get_size_dict(__lowerCAmelCase							,     default_to_square=__lowerCAmelCase       )
					A__  				=       crop_size if crop_size is not None else {"""height""": 2_24, """width""": 2_24}
					A__  				=       get_size_dict(__lowerCAmelCase							,     default_to_square=__lowerCAmelCase							,     param_name="""crop_size"""       )

					A__  				=       do_resize
					A__  				=       size
					A__  				=       resample
					A__  				=       do_center_crop
					A__  				=       crop_size
					A__  				=       do_rescale
					A__  				=       rescale_factor
					A__  				=       do_normalize
					A__  				=       image_mean if image_mean is not None else OPENAI_CLIP_MEAN
					A__  				=       image_std if image_std is not None else OPENAI_CLIP_STD
					A__  				=       do_convert_rgb






			def        a_	(      self       :   Optional[int]							,     __lowerCAmelCase       :   np.ndarray							,     __lowerCAmelCase       :   Dict[str, int]							,     __lowerCAmelCase       :   PILImageResampling = PILImageResampling.BICUBIC							,     __lowerCAmelCase       :   Optional[Union[str, ChannelDimension]] = None							,     **__lowerCAmelCase       :   Union[str, Any]							,     )     ->     np.ndarray:







					"""simple docstring"""






					A__  				=       get_size_dict(__lowerCAmelCase							,     default_to_square=__lowerCAmelCase       )
					if "shortest_edge" not in size:
							raise ValueError(f'The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'       )
					A__  				=       get_resize_output_image_size(__lowerCAmelCase							,     size=size["""shortest_edge"""]							,     default_to_square=__lowerCAmelCase       )
					return resize(__lowerCAmelCase							,     size=__lowerCAmelCase							,     resample=__lowerCAmelCase							,     data_format=__lowerCAmelCase							,     **__lowerCAmelCase       )






			def        a_	(      self       :   str							,     __lowerCAmelCase       :   np.ndarray							,     __lowerCAmelCase       :   Dict[str, int]							,     __lowerCAmelCase       :   Optional[Union[str, ChannelDimension]] = None							,     **__lowerCAmelCase       :   List[Any]							,     )     ->     np.ndarray:







					"""simple docstring"""






					A__  				=       get_size_dict(__lowerCAmelCase       )
					if "height" not in size or "width" not in size:
							raise ValueError(f'The `size` parameter must contain the keys (height, width). Got {size.keys()}'       )
					return center_crop(__lowerCAmelCase							,     size=(size["""height"""], size["""width"""])							,     data_format=__lowerCAmelCase							,     **__lowerCAmelCase       )






			def        a_	(      self       :   Tuple							,     __lowerCAmelCase       :   np.ndarray							,     __lowerCAmelCase       :   Union[int, float]							,     __lowerCAmelCase       :   Optional[Union[str, ChannelDimension]] = None							,     **__lowerCAmelCase       :   Union[str, Any]							,     )     ->     Union[str, Any]:







					"""simple docstring"""






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






			def        a_	(      self       :   int							,     __lowerCAmelCase       :   np.ndarray							,     __lowerCAmelCase       :   Union[float, List[float]]							,     __lowerCAmelCase       :   Union[float, List[float]]							,     __lowerCAmelCase       :   Optional[Union[str, ChannelDimension]] = None							,     **__lowerCAmelCase       :   List[Any]							,     )     ->     np.ndarray:







					"""simple docstring"""






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







			def        a_	(      self       :   Tuple							,     __lowerCAmelCase       :   ImageInput							,     __lowerCAmelCase       :   bool = None							,     __lowerCAmelCase       :   Dict[str, int] = None							,     __lowerCAmelCase       :   PILImageResampling = None							,     __lowerCAmelCase       :   bool = None							,     __lowerCAmelCase       :   int = None							,     __lowerCAmelCase       :   bool = None							,     __lowerCAmelCase       :   float = None							,     __lowerCAmelCase       :   bool = None							,     __lowerCAmelCase       :   Optional[Union[float, List[float]]] = None							,     __lowerCAmelCase       :   Optional[Union[float, List[float]]] = None							,     __lowerCAmelCase       :   bool = None							,     __lowerCAmelCase       :   Optional[Union[str, TensorType]] = None							,     __lowerCAmelCase       :   Optional[ChannelDimension] = ChannelDimension.FIRST							,     **__lowerCAmelCase       :   Optional[Any]							,     )     ->     PIL.Image.Image:







					"""simple docstring"""






					A__  				=       do_resize if do_resize is not None else self.do_resize
					A__  				=       size if size is not None else self.size
					A__  				=       get_size_dict(__lowerCAmelCase							,     param_name="""size"""							,     default_to_square=__lowerCAmelCase       )
					A__  				=       resample if resample is not None else self.resample
					A__  				=       do_center_crop if do_center_crop is not None else self.do_center_crop
					A__  				=       crop_size if crop_size is not None else self.crop_size
					A__  				=       get_size_dict(__lowerCAmelCase							,     param_name="""crop_size"""							,     default_to_square=__lowerCAmelCase       )
					A__  				=       do_rescale if do_rescale is not None else self.do_rescale
					A__  				=       rescale_factor if rescale_factor is not None else self.rescale_factor
					A__  				=       do_normalize if do_normalize is not None else self.do_normalize
					A__  				=       image_mean if image_mean is not None else self.image_mean
					A__  				=       image_std if image_std is not None else self.image_std
					A__  				=       do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

					A__  				=       make_list_of_images(__lowerCAmelCase       )

					if not valid_images(__lowerCAmelCase       ):
							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:
							raise ValueError("""Size must be specified if do_resize is True."""       )

					if do_center_crop and crop_size is None:
							raise ValueError("""Crop size must be specified if do_center_crop 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__  				=       [convert_to_rgb(__lowerCAmelCase       ) for image in images]

					# All transformations expect numpy arrays.
					A__  				=       [to_numpy_array(__lowerCAmelCase       ) for image in images]

					if do_resize:
							A__  				=       [self.resize(image=__lowerCAmelCase							,     size=__lowerCAmelCase							,     resample=__lowerCAmelCase       ) for image in images]

					if do_center_crop:
							A__  				=       [self.center_crop(image=__lowerCAmelCase							,     size=__lowerCAmelCase       ) for image in images]

					if do_rescale:
							A__  				=       [self.rescale(image=__lowerCAmelCase							,     scale=__lowerCAmelCase       ) for image in images]

					if do_normalize:
							A__  				=       [self.normalize(image=__lowerCAmelCase							,     mean=__lowerCAmelCase							,     std=__lowerCAmelCase       ) for image in images]

					A__  				=       [to_channel_dimension_format(__lowerCAmelCase							,     __lowerCAmelCase       ) for image in images]

					A__  				=       {"""pixel_values""": images}
					return BatchFeature(data=__lowerCAmelCase							,     tensor_type=__lowerCAmelCase       )










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


A   : Dict			=				logging.get_logger(__name__)

A   : Dict			=				{
    '''google/pegasus-large''': '''https://huggingface.co/google/pegasus-large/resolve/main/config.json''',
    # See all PEGASUS models at https://huggingface.co/models?filter=pegasus
}


class   A      (SCREAMING_SNAKE_CASE   ):
			'''simple docstring'''




			__lowerCamelCase     :	Tuple          =   '''pegasus'''
			__lowerCamelCase     :	Any          =   ['''past_key_values''']
			__lowerCamelCase     :	List[str]          =   {'''num_attention_heads''': '''encoder_attention_heads''', '''hidden_size''': '''d_model'''}






			def __init__(      self       :   List[Any]							,     __lowerCAmelCase       :   str=5_02_65							,     __lowerCAmelCase       :   Dict=10_24							,     __lowerCAmelCase       :   Union[str, Any]=12							,     __lowerCAmelCase       :   Any=40_96							,     __lowerCAmelCase       :   Optional[Any]=16							,     __lowerCAmelCase       :   Dict=12							,     __lowerCAmelCase       :   Optional[int]=40_96							,     __lowerCAmelCase       :   Dict=16							,     __lowerCAmelCase       :   Optional[int]=0.0							,     __lowerCAmelCase       :   Optional[Any]=0.0							,     __lowerCAmelCase       :   Union[str, Any]=True							,     __lowerCAmelCase       :   List[str]=True							,     __lowerCAmelCase       :   str="gelu"							,     __lowerCAmelCase       :   Union[str, Any]=10_24							,     __lowerCAmelCase       :   Union[str, Any]=0.1							,     __lowerCAmelCase       :   Dict=0.0							,     __lowerCAmelCase       :   Union[str, Any]=0.0							,     __lowerCAmelCase       :   Union[str, Any]=0.0_2							,     __lowerCAmelCase       :   List[Any]=0							,     __lowerCAmelCase       :   str=False							,     __lowerCAmelCase       :   int=0							,     __lowerCAmelCase       :   Optional[Any]=1							,     __lowerCAmelCase       :   Optional[int]=1							,     **__lowerCAmelCase       :   Dict							,     )     ->     Dict:







					"""simple docstring"""






					A__  				=       vocab_size
					A__  				=       max_position_embeddings
					A__  				=       d_model
					A__  				=       encoder_ffn_dim
					A__  				=       encoder_layers
					A__  				=       encoder_attention_heads
					A__  				=       decoder_ffn_dim
					A__  				=       decoder_layers
					A__  				=       decoder_attention_heads
					A__  				=       dropout
					A__  				=       attention_dropout
					A__  				=       activation_dropout
					A__  				=       activation_function
					A__  				=       init_std
					A__  				=       encoder_layerdrop
					A__  				=       decoder_layerdrop
					A__  				=       use_cache
					A__  				=       encoder_layers
					A__  				=       scale_embedding  # scale factor will be sqrt(d_model) if True
					super().__init__(
					    pad_token_id=__lowerCAmelCase							,     eos_token_id=__lowerCAmelCase							,     is_encoder_decoder=__lowerCAmelCase							,     decoder_start_token_id=__lowerCAmelCase							,     forced_eos_token_id=__lowerCAmelCase							,     **__lowerCAmelCase							,     )






			@property
			def        a_	(      self       :   Dict       )     ->     int:







					"""simple docstring"""






					return self.encoder_attention_heads







			@property
			def        a_	(      self       :   Optional[Any]       )     ->     int:







					"""simple docstring"""






					return self.d_model



