



'''simple docstring'''






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


lowerCAmelCase:   Union[str, Any]					=		logging.get_logger(__name__)

lowerCAmelCase:   List[Any]					=		{'vocab_file': 'vocab.txt'}

lowerCAmelCase:   Dict					=		{
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

lowerCAmelCase:   Optional[Any]					=		{
    'YituTech/conv-bert-base': 5_1_2,
    'YituTech/conv-bert-medium-small': 5_1_2,
    'YituTech/conv-bert-small': 5_1_2,
}


lowerCAmelCase:   List[str]					=		{
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}

class 				a__(   lowerCamelCase__      ):
    lowercase__					=       VOCAB_FILES_NAMES
    lowercase__					=       PRETRAINED_VOCAB_FILES_MAP
    lowercase__					=       PRETRAINED_INIT_CONFIGURATION
    lowercase__					=       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    lowercase__					=       ConvBertTokenizer







    def __init__( self					:    List[str]		,     __snake_case					:    Dict=None		,     __snake_case					:    List[Any]=None		,     __snake_case					:    Union[str, Any]=True		,     __snake_case					:    Optional[Any]="[UNK]"		,     __snake_case					:    int="[SEP]"		,     __snake_case					:    List[Any]="[PAD]"		,     __snake_case					:    str="[CLS]"		,     __snake_case					:    Dict="[MASK]"		,     __snake_case					:    Tuple=True		,     __snake_case					:    List[Any]=None		,     **__snake_case					:    Tuple		,     ):
      super().__init__(
          __snake_case		,     tokenizer_file=__snake_case		,     do_lower_case=__snake_case		,     unk_token=__snake_case		,     sep_token=__snake_case		,     pad_token=__snake_case		,     cls_token=__snake_case		,     mask_token=__snake_case		,     tokenize_chinese_chars=__snake_case		,     strip_accents=__snake_case		,     **__snake_case		,     )

      a		:   Dict	  =	json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
      if (
          normalizer_state.get('lowercase'		,     __snake_case      ) != do_lower_case
          or normalizer_state.get('strip_accents'		,     __snake_case      ) != strip_accents
          or normalizer_state.get('handle_chinese_chars'		,     __snake_case      ) != tokenize_chinese_chars
      ):
        a		:   int	  =	getattr(__snake_case		,     normalizer_state.pop('type'      )      )
        a		:   List[Any]	  =	do_lower_case
        a		:   Dict	  =	strip_accents
        a		:   str	  =	tokenize_chinese_chars
        a		:   Union[str, Any]	  =	normalizer_class(**__snake_case      )

      a		:   List[str]	  =	do_lower_case







    def      lowercase_			( self					:    Tuple		,     __snake_case					:    str		,     __snake_case					:    List[Any]=None      ):
      a		:   Optional[Any]	  =	[self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
        output += token_ids_a + [self.sep_token_id]

      return output







    def      lowercase_			( self					:    List[str]		,     __snake_case					:    List[int]		,     __snake_case					:    Optional[List[int]] = None      ):
      a		:   str	  =	[self.sep_token_id]
      a		:   Union[str, Any]	  =	[self.cls_token_id]
      if token_ids_a is None:
        return len(cls + token_ids_a + sep      ) * [0]
      return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]







    def      lowercase_			( self					:    List[str]		,     __snake_case					:    str		,     __snake_case					:    Optional[str] = None      ):
      a		:   Tuple	  =	self._tokenizer.model.save(__snake_case		,     name=__snake_case      )
      return tuple(__snake_case      )




'''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 				a__(   lowerCamelCase__      ):
    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					:    Tuple		,     *__snake_case					:    int		,     **__snake_case					:    List[Any]      ):
      requires_backends(self		,     ['vision']      )
      super().__init__(*__snake_case		,     **__snake_case      )







    def      lowercase_			( self					:    Optional[int]		,     __snake_case					:    "Image"      ):
      return self.pre_processor(images=__snake_case		,     return_tensors='pt'      )







    def      lowercase_			( self					:    Optional[Any]		,     __snake_case					:    str      ):
      return self.model.generate(**__snake_case      )







    def      lowercase_			( self					:    Optional[Any]		,     __snake_case					:    Tuple      ):
      return self.pre_processor.batch_decode(__snake_case		,     skip_special_tokens=__snake_case      )[0].strip()