





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


snake_case_           =      logging.get_logger(__name__)


if is_vision_available():
    import PIL

class 		SCREAMING_SNAKE_CASE__    (	_UpperCAmelCase  ):
      A_						:    List[Any]							=   ['pixel_values']


      def __init__(self	:				List[str]    ,      a__	:				bool = True    ,      a__	:				Dict[str, int] = None    ,      a__	:				PILImageResampling = PILImageResampling.BICUBIC    ,      a__	:				bool = True    ,      a__	:				Dict[str, int] = None    ,      a__	:				bool = True    ,      a__	:				Union[int, float] = 1 / 255    ,      a__	:				bool = True    ,      a__	:				Optional[Union[float, List[float]]] = None    ,      a__	:				Optional[Union[float, List[float]]] = None    ,      a__	:				bool = True    ,      **a__	:				List[Any]    ,      ):





         """simple docstring"""



         super().__init__(**a__				)
         __snake_case								=       size if size is not None else {'''shortest_edge''': 224}
         __snake_case								=       get_size_dict(a__    ,      default_to_square=a__				)
         __snake_case								=       crop_size if crop_size is not None else {'''height''': 224, '''width''': 224}
         __snake_case								=       get_size_dict(a__    ,      default_to_square=a__    ,      param_name='''crop_size'''				)

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


      def        a			(self	:				Tuple    ,      a__	:				np.ndarray    ,      a__	:				Dict[str, int]    ,      a__	:				PILImageResampling = PILImageResampling.BICUBIC    ,      a__	:				Optional[Union[str, ChannelDimension]] = None    ,      **a__	:				Optional[Any]    ,      ):





         """simple docstring"""



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


      def        a			(self	:				Optional[int]    ,      a__	:				np.ndarray    ,      a__	:				Dict[str, int]    ,      a__	:				Optional[Union[str, ChannelDimension]] = None    ,      **a__	:				Union[str, Any]    ,      ):





         """simple docstring"""



         __snake_case								=       get_size_dict(a__				)
         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(a__    ,      size=(size['''height'''], size['''width'''])    ,      data_format=a__    ,      **a__				)


      def        a			(self	:				Dict    ,      a__	:				np.ndarray    ,      a__	:				Union[int, float]    ,      a__	:				Optional[Union[str, ChannelDimension]] = None    ,      **a__	:				str    ,      ):





         """simple docstring"""



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


      def        a			(self	:				List[Any]    ,      a__	:				np.ndarray    ,      a__	:				Union[float, List[float]]    ,      a__	:				Union[float, List[float]]    ,      a__	:				Optional[Union[str, ChannelDimension]] = None    ,      **a__	:				Union[str, Any]    ,      ):





         """simple docstring"""



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


      def        a			(self	:				str    ,      a__	:				ImageInput    ,      a__	:				bool = None    ,      a__	:				Dict[str, int] = None    ,      a__	:				PILImageResampling = None    ,      a__	:				bool = None    ,      a__	:				int = None    ,      a__	:				bool = None    ,      a__	:				float = None    ,      a__	:				bool = None    ,      a__	:				Optional[Union[float, List[float]]] = None    ,      a__	:				Optional[Union[float, List[float]]] = None    ,      a__	:				bool = None    ,      a__	:				Optional[Union[str, TensorType]] = None    ,      a__	:				Optional[ChannelDimension] = ChannelDimension.FIRST    ,      **a__	:				Union[str, Any]    ,      ):





         """simple docstring"""



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

         __snake_case								=       make_list_of_images(a__				)

         if not valid_images(a__				):
            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:
            __snake_case								=       [convert_to_rgb(a__				) for image in images]

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

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

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

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

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

         __snake_case								=       [to_channel_dimension_format(a__    ,      a__				) for image in images]

         __snake_case								=       {'''pixel_values''': images}
         return BatchFeature(data=a__    ,      tensor_type=a__				)








from typing import TYPE_CHECKING

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


snake_case_           =      {}

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

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    snake_case_           =      ['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

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

