





import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if TYPE_CHECKING:
		from transformers.pipelines.conversational import Conversation


_lowercase		:  Tuple			       =logging.get_logger(__name__)

_lowercase		:  Union[str, Any]			       ={"""tokenizer_file""": """tokenizer.json"""}

_lowercase		:  List[str]			       ={
    """tokenizer_file""": {
        """bigscience/tokenizer""": """https://huggingface.co/bigscience/tokenizer/blob/main/tokenizer.json""",
        """bigscience/bloom-560m""": """https://huggingface.co/bigscience/bloom-560m/blob/main/tokenizer.json""",
        """bigscience/bloom-1b1""": """https://huggingface.co/bigscience/bloom-1b1/blob/main/tokenizer.json""",
        """bigscience/bloom-1b7""": """https://huggingface.co/bigscience/bloom-1b7/blob/main/tokenizer.json""",
        """bigscience/bloom-3b""": """https://huggingface.co/bigscience/bloom-3b/blob/main/tokenizer.json""",
        """bigscience/bloom-7b1""": """https://huggingface.co/bigscience/bloom-7b1/blob/main/tokenizer.json""",
        """bigscience/bloom""": """https://huggingface.co/bigscience/bloom/blob/main/tokenizer.json""",
    },
}






class 						UpperCamelCase_  (  snake_case__							):
					_a      :						List[Any]						    =					VOCAB_FILES_NAMES
					_a      :						str						    =					PRETRAINED_VOCAB_FILES_MAP
					_a      :						Optional[int]						    =					['input_ids', 'attention_mask']
					_a      :						Optional[int]						    =					None



					def __init__(		self     :     Optional[Any]       ,      lowerCamelCase     :     Optional[int]=None       ,      lowerCamelCase     :     Tuple=None       ,      lowerCamelCase     :     Optional[Any]=None       ,      lowerCamelCase     :     Optional[Any]="<unk>"       ,      lowerCamelCase     :     Tuple="<s>"       ,      lowerCamelCase     :     int="</s>"       ,      lowerCamelCase     :     Tuple="<pad>"       ,      lowerCamelCase     :     List[Any]=False       ,      lowerCamelCase     :     Optional[int]=False       ,      **lowerCamelCase     :     int       ,      ):
							super().__init__(
							    lowerCamelCase       ,      lowerCamelCase       ,      tokenizer_file=lowerCamelCase       ,      unk_token=lowerCamelCase       ,      bos_token=lowerCamelCase       ,      eos_token=lowerCamelCase       ,      pad_token=lowerCamelCase       ,      add_prefix_space=lowerCamelCase       ,      clean_up_tokenization_spaces=lowerCamelCase       ,      **lowerCamelCase       ,      )
							lowerCamelCase_	:     Union[str, Any] 						=      json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()						)
							if pre_tok_state.get('add_prefix_space'       ,      lowerCamelCase						) != add_prefix_space:
									lowerCamelCase_	:     int 						=      getattr(lowerCamelCase       ,      pre_tok_state.pop('type'						)						)
									lowerCamelCase_	:     Optional[int] 						=      add_prefix_space
									lowerCamelCase_	:     Optional[Any] 						=      pre_tok_class(**lowerCamelCase						)

							lowerCamelCase_	:     Any 						=      add_prefix_space



					def   __a     (		self     :     Optional[Any]       ,      *lowerCamelCase     :     str       ,      **lowerCamelCase     :     List[str]						):
							lowerCamelCase_	:     Optional[int] 						=      kwargs.get('is_split_into_words'       ,      lowerCamelCase						)
							if not (self.add_prefix_space or not is_split_into_words):
									raise Exception(
									    F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"
									    ' pretokenized inputs.'						)

							return super()._batch_encode_plus(*lowerCamelCase       ,      **lowerCamelCase						)



					def   __a     (		self     :     Union[str, Any]       ,      *lowerCamelCase     :     Dict       ,      **lowerCamelCase     :     Dict						):
							lowerCamelCase_	:     int 						=      kwargs.get('is_split_into_words'       ,      lowerCamelCase						)

							if not (self.add_prefix_space or not is_split_into_words):
									raise Exception(
									    F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"
									    ' pretokenized inputs.'						)

							return super()._encode_plus(*lowerCamelCase       ,      **lowerCamelCase						)



					def   __a     (		self     :     List[str]       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     Optional[str] = None						):
							lowerCamelCase_	:     List[Any] 						=      self._tokenizer.model.save(lowerCamelCase       ,      name=lowerCamelCase						)
							return tuple(lowerCamelCase						)





					def   __a     (		self     :     Any       ,      lowerCamelCase     :     "Conversation"						):
							lowerCamelCase_	:     Optional[Any] 						=      []
							for is_user, text in conversation.iter_texts():
									input_ids.extend(self.encode(lowerCamelCase       ,      add_special_tokens=lowerCamelCase						) + [self.eos_token_id]						)

							if len(lowerCamelCase						) > self.model_max_length:
									lowerCamelCase_	:     Union[str, Any] 						=      input_ids[-self.model_max_length :]
							return input_ids







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


_lowercase		:  Tuple			       =logging.get_logger(__name__)






class 						UpperCamelCase_  (  snake_case__							):
					_a      :						List[str]						    =					['pixel_values']



					def __init__(		self     :     List[Any]       ,      lowerCamelCase     :     bool = True       ,      lowerCamelCase     :     Dict[str, int] = None       ,      lowerCamelCase     :     PILImageResampling = PILImageResampling.BICUBIC       ,      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     :     Optional[Any]       ,      ):
							super().__init__(**lowerCamelCase						)
							lowerCamelCase_	:     List[Any] 						=      size if size is not None else {'height': 3_84, 'width': 3_84}
							lowerCamelCase_	:     List[str] 						=      get_size_dict(lowerCamelCase       ,      default_to_square=lowerCamelCase						)

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



					def   __a     (		self     :     Tuple       ,      lowerCamelCase     :     np.ndarray       ,      lowerCamelCase     :     Dict[str, int]       ,      lowerCamelCase     :     PILImageResampling = PILImageResampling.BICUBIC       ,      lowerCamelCase     :     Optional[Union[str, ChannelDimension]] = None       ,      **lowerCamelCase     :     List[Any]       ,      ):
							lowerCamelCase_	:     List[Any] 						=      get_size_dict(lowerCamelCase       ,      default_to_square=lowerCamelCase						)
							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()}"						)
							lowerCamelCase_	:     Optional[Any] 						=      (size['height'], size['width'])
							return resize(lowerCamelCase       ,      size=lowerCamelCase       ,      resample=lowerCamelCase       ,      data_format=lowerCamelCase       ,      **lowerCamelCase						)



					def   __a     (		self     :     Union[str, Any]       ,      lowerCamelCase     :     np.ndarray       ,      lowerCamelCase     :     Union[int, float]       ,      lowerCamelCase     :     Optional[Union[str, ChannelDimension]] = None       ,      **lowerCamelCase     :     Union[str, Any]       ,      ):
							return rescale(lowerCamelCase       ,      scale=lowerCamelCase       ,      data_format=lowerCamelCase       ,      **lowerCamelCase						)



					def   __a     (		self     :     str       ,      lowerCamelCase     :     np.ndarray       ,      lowerCamelCase     :     Union[float, List[float]]       ,      lowerCamelCase     :     Union[float, List[float]]       ,      lowerCamelCase     :     Optional[Union[str, ChannelDimension]] = None       ,      **lowerCamelCase     :     Optional[int]       ,      ):
							return normalize(lowerCamelCase       ,      mean=lowerCamelCase       ,      std=lowerCamelCase       ,      data_format=lowerCamelCase       ,      **lowerCamelCase						)





					def   __a     (		self     :     List[Any]       ,      lowerCamelCase     :     ImageInput       ,      lowerCamelCase     :     Optional[bool] = None       ,      lowerCamelCase     :     Optional[Dict[str, int]] = None       ,      lowerCamelCase     :     PILImageResampling = None       ,      lowerCamelCase     :     Optional[bool] = None       ,      lowerCamelCase     :     Optional[float] = None       ,      lowerCamelCase     :     Optional[bool] = None       ,      lowerCamelCase     :     Optional[Union[float, List[float]]] = None       ,      lowerCamelCase     :     Optional[Union[float, List[float]]] = None       ,      lowerCamelCase     :     Optional[Union[str, TensorType]] = None       ,      lowerCamelCase     :     bool = None       ,      lowerCamelCase     :     ChannelDimension = ChannelDimension.FIRST       ,      **lowerCamelCase     :     Any       ,      ):
							lowerCamelCase_	:     Optional[Any] 						=      do_resize if do_resize is not None else self.do_resize
							lowerCamelCase_	:     int 						=      resample if resample is not None else self.resample
							lowerCamelCase_	:     Dict 						=      do_rescale if do_rescale is not None else self.do_rescale
							lowerCamelCase_	:     Any 						=      rescale_factor if rescale_factor is not None else self.rescale_factor
							lowerCamelCase_	:     str 						=      do_normalize if do_normalize is not None else self.do_normalize
							lowerCamelCase_	:     List[str] 						=      image_mean if image_mean is not None else self.image_mean
							lowerCamelCase_	:     str 						=      image_std if image_std is not None else self.image_std
							lowerCamelCase_	:     int 						=      do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

							lowerCamelCase_	:     Union[str, Any] 						=      size if size is not None else self.size
							lowerCamelCase_	:     Optional[int] 						=      get_size_dict(lowerCamelCase       ,      default_to_square=lowerCamelCase						)

							lowerCamelCase_	:     Dict 						=      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 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:
									lowerCamelCase_	:     int 						=      [convert_to_rgb(lowerCamelCase						) for image in images]

							# All transformations expect numpy arrays.
							lowerCamelCase_	:     List[Any] 						=      [to_numpy_array(lowerCamelCase						) for image in images]

							if do_resize:
									lowerCamelCase_	:     Optional[int] 						=      [self.resize(image=lowerCamelCase       ,      size=lowerCamelCase       ,      resample=lowerCamelCase						) for image in images]

							if do_rescale:
									lowerCamelCase_	:     Dict 						=      [self.rescale(image=lowerCamelCase       ,      scale=lowerCamelCase						) for image in images]

							if do_normalize:
									lowerCamelCase_	:     Optional[int] 						=      [self.normalize(image=lowerCamelCase       ,      mean=lowerCamelCase       ,      std=lowerCamelCase						) for image in images]

							lowerCamelCase_	:     Optional[int] 						=      [to_channel_dimension_format(lowerCamelCase       ,      lowerCamelCase						) for image in images]

							lowerCamelCase_	:     Optional[int] 						=      BatchFeature(data={'pixel_values': images}       ,      tensor_type=lowerCamelCase						)

							return encoded_outputs
