

'''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 (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_batched,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


a=  logging.get_logger(__name__)






class 			__lowercase		(						lowerCAmelCase__						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						["pixel_values"]







     def __init__(		self     ,			_lowerCamelCase = True     ,			_lowerCamelCase = None     ,			_lowerCamelCase = PILImageResampling.BICUBIC     ,			_lowerCamelCase = True     ,			_lowerCamelCase = True     ,			_lowerCamelCase = 1 / 2_5_5     ,			_lowerCamelCase = None     ,			_lowerCamelCase = True     ,			_lowerCamelCase = None     ,			_lowerCamelCase = None     ,			**_lowerCamelCase     ,			):
         super().__init__(**_lowerCamelCase    )
         __UpperCamelCase	:	int		    =  size if size is not None else {'height': 2_2_4, 'width': 2_2_4}
         __UpperCamelCase	:	Any		    =  get_size_dict(_lowerCamelCase    )
         __UpperCamelCase	:	Optional[Any]		    =  crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
         __UpperCamelCase	:	Optional[int]		    =  get_size_dict(_lowerCamelCase     ,			default_to_square=_lowerCamelCase     ,			param_name='crop_size'    )

         __UpperCamelCase	:	List[str]		    =  do_resize
         __UpperCamelCase	:	Dict		    =  do_rescale
         __UpperCamelCase	:	Union[str, Any]		    =  do_normalize
         __UpperCamelCase	:	Union[str, Any]		    =  do_center_crop
         __UpperCamelCase	:	List[str]		    =  crop_size
         __UpperCamelCase	:	int		    =  size
         __UpperCamelCase	:	Any		    =  resample
         __UpperCamelCase	:	Dict		    =  rescale_factor
         __UpperCamelCase	:	int		    =  image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
         __UpperCamelCase	:	str		    =  image_std if image_std is not None else IMAGENET_DEFAULT_STD







     def lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase     ,			_lowerCamelCase = PILImageResampling.BILINEAR     ,			_lowerCamelCase = None     ,			**_lowerCamelCase     ,			):
         __UpperCamelCase	:	List[Any]		    =  get_size_dict(_lowerCamelCase    )

         if "shortest_edge" in size:
             __UpperCamelCase	:	Tuple		    =  get_resize_output_image_size(_lowerCamelCase     ,			size=size['shortest_edge']     ,			default_to_square=_lowerCamelCase    )
             # size = get_resize_output_image_size(image, size["shortest_edge"], size["longest_edge"])
         elif "height" in size and "width" in size:
             __UpperCamelCase	:	Union[str, Any]		    =  (size['height'], size['width'])
         else:
             raise ValueError(f"""Size must contain 'height' and 'width' keys or 'shortest_edge' key. Got {size.keys()}"""    )
         return resize(_lowerCamelCase     ,			size=_lowerCamelCase     ,			resample=_lowerCamelCase     ,			data_format=_lowerCamelCase     ,			**_lowerCamelCase    )







     def lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase     ,			_lowerCamelCase = None     ,			**_lowerCamelCase     ,			):
         __UpperCamelCase	:	str		    =  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 lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase     ,			_lowerCamelCase = None     ,			**_lowerCamelCase    ):
         return rescale(_lowerCamelCase     ,			scale=_lowerCamelCase     ,			data_format=_lowerCamelCase     ,			**_lowerCamelCase    )







     def lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase     ,			_lowerCamelCase     ,			_lowerCamelCase = None     ,			**_lowerCamelCase     ,			):
         return normalize(_lowerCamelCase     ,			mean=_lowerCamelCase     ,			std=_lowerCamelCase     ,			data_format=_lowerCamelCase     ,			**_lowerCamelCase    )







     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 = None     ,			_lowerCamelCase = ChannelDimension.FIRST     ,			**_lowerCamelCase     ,			):
         __UpperCamelCase	:	int		    =  do_resize if do_resize is not None else self.do_resize
         __UpperCamelCase	:	Tuple		    =  do_rescale if do_rescale is not None else self.do_rescale
         __UpperCamelCase	:	int		    =  do_normalize if do_normalize is not None else self.do_normalize
         __UpperCamelCase	:	Dict		    =  do_center_crop if do_center_crop is not None else self.do_center_crop
         __UpperCamelCase	:	Union[str, Any]		    =  crop_size if crop_size is not None else self.crop_size
         __UpperCamelCase	:	List[str]		    =  get_size_dict(_lowerCamelCase     ,			param_name='crop_size'     ,			default_to_square=_lowerCamelCase    )
         __UpperCamelCase	:	Any		    =  resample if resample is not None else self.resample
         __UpperCamelCase	:	List[Any]		    =  rescale_factor if rescale_factor is not None else self.rescale_factor
         __UpperCamelCase	:	Optional[Any]		    =  image_mean if image_mean is not None else self.image_mean
         __UpperCamelCase	:	Any		    =  image_std if image_std is not None else self.image_std

         __UpperCamelCase	:	Tuple		    =  size if size is not None else self.size
         __UpperCamelCase	:	Tuple		    =  get_size_dict(_lowerCamelCase    )

         if not is_batched(_lowerCamelCase    ):
             __UpperCamelCase	:	List[Any]		    =  [images]

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

         # All transformations expect numpy arrays.
         __UpperCamelCase	:	Dict		    =  [to_numpy_array(_lowerCamelCase    ) for image in images]

         if do_resize:
             __UpperCamelCase	:	str		    =  [self.resize(image=_lowerCamelCase     ,			size=_lowerCamelCase     ,			resample=_lowerCamelCase    ) for image in images]

         if do_center_crop:
             __UpperCamelCase	:	Any		    =  [self.center_crop(image=_lowerCamelCase     ,			size=_lowerCamelCase    ) for image in images]

         if do_rescale:
             __UpperCamelCase	:	List[Any]		    =  [self.rescale(image=_lowerCamelCase     ,			scale=_lowerCamelCase    ) for image in images]

         if do_normalize:
             __UpperCamelCase	:	List[str]		    =  [self.normalize(image=_lowerCamelCase     ,			mean=_lowerCamelCase     ,			std=_lowerCamelCase    ) for image in images]

         __UpperCamelCase	:	int		    =  [to_channel_dimension_format(_lowerCamelCase     ,			_lowerCamelCase    ) for image in images]

         __UpperCamelCase	:	Dict		    =  {'pixel_values': images}
         return BatchFeature(data=_lowerCamelCase     ,			tensor_type=_lowerCamelCase    )




'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


a=  {}

try:
  if not is_sentencepiece_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a=  ['''NllbTokenizer''']

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  a=  ['''NllbTokenizerFast''']


if TYPE_CHECKING:
  try:
    if not is_sentencepiece_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_nllb import NllbTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_nllb_fast import NllbTokenizerFast

else:
  import sys

  a=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



