


from typing import Dict, List, Optional

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


snake_case_    :      Optional[Any]				    =				logging.get_logger(__name__)


snake_case_    :      List[Any]				    =				{
    '''nielsr/canine-s''': 20_48,
}

# Unicode defines 1,114,112 total “codepoints”
snake_case_    :      int				    =				1_11_41_12

# Below: Constants defining canonical codepoints for special, pseudo-characters.
# Copied from https://github.com/google-research/language/blob/master/language/canine/special_codepoints.py
snake_case_    :      Tuple				    =				0

snake_case_    :      List[str]				    =				0xE_000
snake_case_    :      Tuple				    =				0xE_001
snake_case_    :      Union[str, Any]				    =				0xE_002
snake_case_    :      Optional[int]				    =				0xE_003
snake_case_    :      Tuple				    =				0xE_004

# Maps special codepoints to human-readable names.
snake_case_    :      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.
snake_case_    :      Dict[str, int]				    =				{name: codepoint for codepoint, name in SPECIAL_CODEPOINTS.items()}

class     A__				(		a_	):
						UpperCAmelCase   							=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES




						def __init__(							self       :   List[str]					,     _a       :   int=chr(lowercase_	)					,     _a       :   Optional[Any]=chr(lowercase_	)					,     _a       :   Union[str, Any]=chr(lowercase_	)					,     _a       :   Tuple=chr(lowercase_	)					,     _a       :   str=chr(lowercase_	)					,     _a       :   Optional[Any]=chr(lowercase_	)					,     _a       :   Union[str, Any]=False					,     _a       :   int=2048					,     **_a       :   Union[str, Any]					,     )				->  Optional[int]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE      	=AddedToken(lowercase_					,     lstrip=lowercase_					,     rstrip=lowercase_	) if isinstance(lowercase_					,     lowercase_	) else bos_token
										_SCREAMING_SNAKE_CASE      	=AddedToken(lowercase_					,     lstrip=lowercase_					,     rstrip=lowercase_	) if isinstance(lowercase_					,     lowercase_	) else eos_token
										_SCREAMING_SNAKE_CASE      	=AddedToken(lowercase_					,     lstrip=lowercase_					,     rstrip=lowercase_	) if isinstance(lowercase_					,     lowercase_	) else sep_token
										_SCREAMING_SNAKE_CASE      	=AddedToken(lowercase_					,     lstrip=lowercase_					,     rstrip=lowercase_	) if isinstance(lowercase_					,     lowercase_	) else cls_token
										_SCREAMING_SNAKE_CASE      	=AddedToken(lowercase_					,     lstrip=lowercase_					,     rstrip=lowercase_	) if isinstance(lowercase_					,     lowercase_	) else pad_token

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

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

										# 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       :   Dict	)				->  str:


										"""simple docstring"""





										return self._unicode_vocab_size




						def 				__UpperCamelCase					(							self       :   Any					,     _a       :   str	)				->  List[str]:


										"""simple docstring"""





										return list(lowercase_	)




						def 				__UpperCamelCase					(							self       :   Union[str, Any]					,     _a       :   str	)				->  Dict:


										"""simple docstring"""





										try:
														return ord(lowercase_	)
										except TypeError:
														raise ValueError(f"invalid token: \'{token}\'"	)




						def 				__UpperCamelCase					(							self       :   Any					,     _a       :   int	)				->  List[Any]:


										"""simple docstring"""





										try:
														if index in SPECIAL_CODEPOINTS:
																		return SPECIAL_CODEPOINTS[index]
														return chr(lowercase_	)
										except TypeError:
														raise ValueError(f"invalid id: {index}"	)




						def 				__UpperCamelCase					(							self       :   int					,     _a       :   Optional[int]	)				->  Optional[Any]:


										"""simple docstring"""





										return "".join(lowercase_	)




						def 				__UpperCamelCase					(							self       :   Any					,     _a       :   List[int]					,     _a       :   Optional[List[int]] = None	)				->  List[str]:


										"""simple docstring"""





										_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       :   List[str]					,     _a       :   List[int]					,     _a       :   Optional[List[int]] = None					,     _a       :   bool = False	)				->  List[str]:


										"""simple docstring"""





										if already_has_special_tokens:
														return super().get_special_tokens_mask(
														    token_ids_a=lowercase_					,     token_ids_a=lowercase_					,     already_has_special_tokens=lowercase_	)

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




						def 				__UpperCamelCase					(							self       :   Dict					,     _a       :   List[int]					,     _a       :   Optional[List[int]] = None	)				->  Optional[Any]:


										"""simple docstring"""





										_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       :   List[Any]					,     _a       :   str					,     _a       :   Optional[str] = None	)				->  List[Any]:


										"""simple docstring"""





										return ()


"""simple docstring"""





# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ..models.auto import AutoModelForVisionaSeq
from ..utils import requires_backends
from .base import PipelineTool


if TYPE_CHECKING:
							from PIL import Image







class 							SCREAMING_SNAKE_CASE   (						a_			):






					"""simple docstring"""



					lowercase__												=			"Salesforce/blip-image-captioning-base"
					lowercase__												=			(
					    "This is a tool that generates a description of an image. It takes an input named `image` which should be the "
					    "image to caption, and returns a text that contains the description in English."
					)
					lowercase__												=			"image_captioner"
					lowercase__												=			AutoModelForVisionaSeq

					lowercase__												=			["image"]
					lowercase__												=			["text"]







					def __init__(			self     :							int  ,*lowercase_     :							int  ,**lowercase_     :							List[str]						):
						requires_backends(self  ,['''vision''']						)
						super().__init__(*lowercase_  ,**lowercase_						)







					def 			__lowerCAmelCase					(			self     :							List[str]  ,lowercase_     :							"Image"						):
						return self.pre_processor(images=lowercase_  ,return_tensors='''pt'''						)







					def 			__lowerCAmelCase					(			self     :							List[Any]  ,lowercase_     :							Any						):
						return self.model.generate(**lowercase_						)







					def 			__lowerCAmelCase					(			self     :							Dict  ,lowercase_     :							Union[str, Any]						):
						return self.pre_processor.batch_decode(lowercase_  ,skip_special_tokens=lowercase_						)[0].strip()




