




from typing import Dict, List, Optional

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


__A						:							Optional[int]							=  logging.get_logger(__name__)


__A						:							List[Any]							=  {
    """nielsr/canine-s""": 2_0_4_8,
}

# Unicode defines 1,114,112 total “codepoints”
__A						:							Optional[Any]							=  1_1_1_4_1_1_2

# Below: Constants defining canonical codepoints for special, pseudo-characters.
# Copied from https://github.com/google-research/language/blob/master/language/canine/special_codepoints.py
__A						:							Union[str, Any]							=  0

__A						:							Optional[Any]							=  0Xe0_00
__A						:							List[str]							=  0Xe0_01
__A						:							Union[str, Any]							=  0Xe0_02
__A						:							Union[str, Any]							=  0Xe0_03
__A						:							Union[str, Any]							=  0Xe0_04

# Maps special codepoints to human-readable names.
__A						:							Dict[int, str]							=  {
    # Special symbols are represented using codepoints values that are valid,
    # but designated as "Private Use", meaning that they will never be assigned
    # characters by the Unicode Consortium, and are thus safe for use here.
    #
    # NOTE: Do *NOT* add any sort of [UNK_CHAR] here. They are explicitly
    # excluded and should fail with a hard error.
    CLS: "[CLS]",
    SEP: "[SEP]",
    BOS: "[BOS]",
    MASK: "[MASK]",
    PAD: "[PAD]",
    RESERVED: "[RESERVED]",
}

# Maps special codepoint human-readable names to their codepoint values.
__A						:							Dict[str, int]							=  {name: codepoint for codepoint, name in SPECIAL_CODEPOINTS.items()}




class 			UpperCAmelCase_      (   A       ):




							'''simple docstring'''



							a__						  =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES





							def __init__(					self       :	Dict       ,     a       :	int=chr(a			)       ,     a       :	Union[str, Any]=chr(a			)       ,     a       :	Dict=chr(a			)       ,     a       :	Optional[Any]=chr(a			)       ,     a       :	Optional[Any]=chr(a			)       ,     a       :	List[Any]=chr(a			)       ,     a       :	Union[str, Any]=False       ,     a       :	Dict=2_048       ,     **a       :	List[Any]       ,     )			->					Optional[int]:
										SCREAMING_SNAKE_CASE           =					AddedToken(a       ,     lstrip=a       ,     rstrip=a			) if isinstance(a       ,     a			) else bos_token
										SCREAMING_SNAKE_CASE           =					AddedToken(a       ,     lstrip=a       ,     rstrip=a			) if isinstance(a       ,     a			) else eos_token
										SCREAMING_SNAKE_CASE           =					AddedToken(a       ,     lstrip=a       ,     rstrip=a			) if isinstance(a       ,     a			) else sep_token
										SCREAMING_SNAKE_CASE           =					AddedToken(a       ,     lstrip=a       ,     rstrip=a			) if isinstance(a       ,     a			) else cls_token
										SCREAMING_SNAKE_CASE           =					AddedToken(a       ,     lstrip=a       ,     rstrip=a			) if isinstance(a       ,     a			) else pad_token

										# Mask token behave like a normal word, i.e. include the space before it
										SCREAMING_SNAKE_CASE           =					AddedToken(a       ,     lstrip=a       ,     rstrip=a			) if isinstance(a       ,     a			) else mask_token

										super().__init__(
										    bos_token=a       ,     eos_token=a       ,     sep_token=a       ,     cls_token=a       ,     pad_token=a       ,     mask_token=a       ,     add_prefix_space=a       ,     model_max_length=a       ,     **a       ,     )

										# Creates a mapping for looking up the IDs of special symbols.
										SCREAMING_SNAKE_CASE           =					{}
										for codepoint, name in SPECIAL_CODEPOINTS.items():
													SCREAMING_SNAKE_CASE           =					codepoint

										# Creates a mapping for looking up the string forms of special symbol IDs.
										SCREAMING_SNAKE_CASE           =					{
										    codepoint: name for name, codepoint in self._special_codepoints.items()
										}

										SCREAMING_SNAKE_CASE           =					UNICODE_VOCAB_SIZE
										SCREAMING_SNAKE_CASE           =					len(self._special_codepoints			)





							@property
							def    _UpperCAmelCase     (					self       :	int			)			->					int:
										return self._unicode_vocab_size





							def    _UpperCAmelCase     (					self       :	Optional[int]       ,     a       :	str			)			->					List[str]:
										return list(a			)





							def    _UpperCAmelCase     (					self       :	int       ,     a       :	str			)			->					int:
										try:
													return ord(a			)
										except TypeError:
													raise ValueError(f"""invalid token: '{token}'"""			)





							def    _UpperCAmelCase     (					self       :	Tuple       ,     a       :	int			)			->					str:
										try:
													if index in SPECIAL_CODEPOINTS:
																return SPECIAL_CODEPOINTS[index]
													return chr(a			)
										except TypeError:
													raise ValueError(f"""invalid id: {index}"""			)





							def    _UpperCAmelCase     (					self       :	Optional[int]       ,     a       :	str			)			->					Tuple:
										return "".join(a			)





							def    _UpperCAmelCase     (					self       :	List[Any]       ,     a       :	List[int]       ,     a       :	Optional[List[int]] = None			)			->					List[int]:
										SCREAMING_SNAKE_CASE           =					[self.sep_token_id]
										SCREAMING_SNAKE_CASE           =					[self.cls_token_id]

										SCREAMING_SNAKE_CASE           =					cls + token_ids_a + sep
										if token_ids_a is not None:
													result += token_ids_a + sep
										return result





							def    _UpperCAmelCase     (					self       :	Any       ,     a       :	List[int]       ,     a       :	Optional[List[int]] = None       ,     a       :	bool = False			)			->					List[int]:
										if already_has_special_tokens:
													return super().get_special_tokens_mask(
													    token_ids_a=a       ,     token_ids_a=a       ,     already_has_special_tokens=a			)

										SCREAMING_SNAKE_CASE           =					[1] + ([0] * len(a			)) + [1]
										if token_ids_a is not None:
													result += ([0] * len(a			)) + [1]
										return result





							def    _UpperCAmelCase     (					self       :	Any       ,     a       :	List[int]       ,     a       :	Optional[List[int]] = None			)			->					List[int]:
										SCREAMING_SNAKE_CASE           =					[self.sep_token_id]
										SCREAMING_SNAKE_CASE           =					[self.cls_token_id]

										SCREAMING_SNAKE_CASE           =					len(cls + token_ids_a + sep			) * [0]
										if token_ids_a is not None:
													result += len(token_ids_a + sep			) * [1]
										return result







							def    _UpperCAmelCase     (					self       :	Tuple       ,     a       :	str       ,     a       :	Optional[str] = None			)			->					int:
										return ()












import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class 			UpperCAmelCase_      (   A       ):




							'''simple docstring'''



							a__						  =     ['''image_processor''', '''tokenizer''']
							a__						  =     '''ViTImageProcessor'''
							a__						  =     ('''CLIPTokenizer''', '''CLIPTokenizerFast''')





							def __init__(					self       :	List[str]       ,     a       :	Dict=None       ,     a       :	List[str]=None       ,     **a       :	List[str]			)			->					Optional[Any]:
										SCREAMING_SNAKE_CASE           =					None
										if "feature_extractor" in kwargs:
													warnings.warn(
													    """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
													    """ instead."""       ,     a       ,     )
													SCREAMING_SNAKE_CASE           =					kwargs.pop("""feature_extractor"""			)

										SCREAMING_SNAKE_CASE           =					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__(a       ,     a			)





							def __call__(					self       :	List[Any]       ,     a       :	int=None       ,     a       :	Dict=None       ,     a       :	int=None       ,     a       :	Tuple=None       ,     **a       :	Any			)			->					Any:
										if text is None and visual_prompt is None and images is None:
													raise ValueError("""You have to specify either text, visual prompt or images."""			)

										if text is not None and visual_prompt is not None:
													raise ValueError("""You have to specify exactly one type of prompt. Either text or visual prompt."""			)

										if text is not None:
													SCREAMING_SNAKE_CASE           =					self.tokenizer(a       ,     return_tensors=a       ,     **a			)

										if visual_prompt is not None:
													SCREAMING_SNAKE_CASE           =					self.image_processor(a       ,     return_tensors=a       ,     **a			)

										if images is not None:
													SCREAMING_SNAKE_CASE           =					self.image_processor(a       ,     return_tensors=a       ,     **a			)

										if visual_prompt is not None and images is not None:
													SCREAMING_SNAKE_CASE           =					{
													    """pixel_values""": image_features.pixel_values,
													    """conditional_pixel_values""": prompt_features.pixel_values,
													}
													return encoding
										elif text is not None and images is not None:
													SCREAMING_SNAKE_CASE           =					image_features.pixel_values
													return encoding
										elif text is not None:
													return encoding
										elif visual_prompt is not None:
													SCREAMING_SNAKE_CASE           =					{
													    """conditional_pixel_values""": prompt_features.pixel_values,
													}
													return encoding
										else:
													return BatchEncoding(data=dict(**a			)       ,     tensor_type=a			)





							def    _UpperCAmelCase     (					self       :	Dict       ,     *a       :	Dict       ,     **a       :	Union[str, Any]			)			->					Any:
										return self.tokenizer.batch_decode(*a       ,     **a			)





							def    _UpperCAmelCase     (					self       :	Tuple       ,     *a       :	List[Any]       ,     **a       :	Union[str, Any]			)			->					Dict:
										return self.tokenizer.decode(*a       ,     **a			)





							@property
							def    _UpperCAmelCase     (					self       :	Any			)			->					Optional[Any]:
										warnings.warn(
										    """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""       ,     a       ,     )
										return self.image_processor_class







							@property
							def    _UpperCAmelCase     (					self       :	Optional[int]			)			->					str:
										warnings.warn(
										    """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""       ,     a       ,     )
										return self.image_processor






