



"""simple docstring"""






from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType



class     UpperCAmelCase    (	__SCREAMING_SNAKE_CASE  ):
   A__		:	str           =  ['''image_processor''', '''tokenizer''']
   A__		:	Tuple           =  '''BlipImageProcessor'''
   A__		:	str           =  ('''BertTokenizer''', '''BertTokenizerFast''')



   def __init__(       self    :	Any							,       __lowerCamelCase    :	List[Any]							,       __lowerCamelCase    :	Any				):



     """simple docstring"""
     _snake_case   	=      False
     super().__init__(__lowerCamelCase							,       __lowerCamelCase				)
     _snake_case   	=      self.image_processor



   def __call__(       self    :	Optional[int]							,       __lowerCamelCase    :	ImageInput = None							,       __lowerCamelCase    :	Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None							,       __lowerCamelCase    :	bool = True							,       __lowerCamelCase    :	Union[bool, str, PaddingStrategy] = False							,       __lowerCamelCase    :	Union[bool, str, TruncationStrategy] = None							,       __lowerCamelCase    :	Optional[int] = None							,       __lowerCamelCase    :	int = 0							,       __lowerCamelCase    :	Optional[int] = None							,       __lowerCamelCase    :	Optional[bool] = None							,       __lowerCamelCase    :	bool = False							,       __lowerCamelCase    :	bool = False							,       __lowerCamelCase    :	bool = False							,       __lowerCamelCase    :	bool = False							,       __lowerCamelCase    :	bool = False							,       __lowerCamelCase    :	bool = True							,       __lowerCamelCase    :	Optional[Union[str, TensorType]] = None							,       **__lowerCamelCase    :	List[str]							,       ):



     """simple docstring"""
     if images is None and text is None:
       raise ValueError('''You have to specify either images or text.'''				)

     # Get only text
     if images is None:
       _snake_case   	=      self.tokenizer
       _snake_case   	=      self.tokenizer(
           text=__lowerCamelCase							,       add_special_tokens=__lowerCamelCase							,       padding=__lowerCamelCase							,       truncation=__lowerCamelCase							,       max_length=__lowerCamelCase							,       stride=__lowerCamelCase							,       pad_to_multiple_of=__lowerCamelCase							,       return_attention_mask=__lowerCamelCase							,       return_overflowing_tokens=__lowerCamelCase							,       return_special_tokens_mask=__lowerCamelCase							,       return_offsets_mapping=__lowerCamelCase							,       return_token_type_ids=__lowerCamelCase							,       return_length=__lowerCamelCase							,       verbose=__lowerCamelCase							,       return_tensors=__lowerCamelCase							,       **__lowerCamelCase							,       )
       return text_encoding

     # add pixel_values
     _snake_case   	=      self.image_processor(__lowerCamelCase							,       return_tensors=__lowerCamelCase				)

     if text is not None:
       _snake_case   	=      self.tokenizer(
           text=__lowerCamelCase							,       add_special_tokens=__lowerCamelCase							,       padding=__lowerCamelCase							,       truncation=__lowerCamelCase							,       max_length=__lowerCamelCase							,       stride=__lowerCamelCase							,       pad_to_multiple_of=__lowerCamelCase							,       return_attention_mask=__lowerCamelCase							,       return_overflowing_tokens=__lowerCamelCase							,       return_special_tokens_mask=__lowerCamelCase							,       return_offsets_mapping=__lowerCamelCase							,       return_token_type_ids=__lowerCamelCase							,       return_length=__lowerCamelCase							,       verbose=__lowerCamelCase							,       return_tensors=__lowerCamelCase							,       **__lowerCamelCase							,       )
     else:
       _snake_case   	=      None

     if text_encoding is not None:
       encoding_image_processor.update(__lowerCamelCase				)

     return encoding_image_processor



   def    __UpperCAmelCase    (       self    :	Dict							,       *__lowerCamelCase    :	List[str]							,       **__lowerCamelCase    :	Optional[Any]				):



     """simple docstring"""
     return self.tokenizer.batch_decode(*__lowerCamelCase							,       **__lowerCamelCase				)



   def    __UpperCAmelCase    (       self    :	List[str]							,       *__lowerCamelCase    :	Optional[Any]							,       **__lowerCamelCase    :	Any				):



     """simple docstring"""
     return self.tokenizer.decode(*__lowerCamelCase							,       **__lowerCamelCase				)





   @property
   def    __UpperCAmelCase    (       self    :	str				):



     """simple docstring"""
     _snake_case   	=      self.tokenizer.model_input_names
     _snake_case   	=      self.image_processor.model_input_names
     return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names				)				)










'''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()