



# 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      __lowerCAmelCase     (		UpperCAmelCase_      ):
					"""simple docstring"""






					A__				:		str			       =    "Salesforce/blip-image-captioning-base"
					A__				:		Any			       =    (
					    "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."
					)
					A__				:		Optional[Any]			       =    "image_captioner"
					A__				:		Dict			       =    AutoModelForVisionaSeq

					A__				:		int			       =    ["image"]
					A__				:		int			       =    ["text"]



					def __init__(     self					:       Tuple				,					*_snake_case					:       Optional[int]				,					**_snake_case					:       str					):






								"""simple docstring"""


								requires_backends(self				,					['vision']					)
								super().__init__(*_snake_case				,					**_snake_case					)



					def     _a							(     self					:       List[Any]				,					_snake_case					:       "Image"					):






								"""simple docstring"""


								return self.pre_processor(images=_snake_case				,					return_tensors='pt'					)



					def     _a							(     self					:       Any				,					_snake_case					:       Optional[int]					):






								"""simple docstring"""


								return self.model.generate(**_snake_case					)



					def     _a							(     self					:       Dict				,					_snake_case					:       Union[str, Any]					):






								"""simple docstring"""


								return self.pre_processor.batch_decode(_snake_case				,					skip_special_tokens=_snake_case					)[0].strip()









from typing import Dict

from .base import GenericTensor, Pipeline


class      __lowerCAmelCase     (		UpperCAmelCase_      ):
					"""simple docstring"""






					def     _a							(     self					:       Any				,					_snake_case					:       str=None				,					_snake_case					:       Dict=None				,					_snake_case					:       Any=None				,					**_snake_case					:       str					):






								"""simple docstring"""


								if tokenize_kwargs is None:
											A__       =    {}

								if truncation is not None:
											if "truncation" in tokenize_kwargs:
														raise ValueError(
														    'truncation parameter defined twice (given as keyword argument as well as in tokenize_kwargs)'					)
											A__       =    truncation

								A__       =    tokenize_kwargs

								A__       =    {}
								if return_tensors is not None:
											A__       =    return_tensors

								return preprocess_params, {}, postprocess_params



					def     _a							(     self					:       Any				,					_snake_case					:       Dict				,					**_snake_case					:       Optional[Any]					):






								"""simple docstring"""


								A__       =    self.framework
								A__       =    self.tokenizer(_snake_case				,					return_tensors=_snake_case				,					**_snake_case					)
								return model_inputs



					def     _a							(     self					:       List[Any]				,					_snake_case					:       Dict					):






								"""simple docstring"""


								A__       =    self.model(**_snake_case					)
								return model_outputs



					def     _a							(     self					:       Optional[Any]				,					_snake_case					:       List[Any]				,					_snake_case					:       str=False					):






								"""simple docstring"""


								if return_tensors:
											return model_outputs[0]
								if self.framework == "pt":
											return model_outputs[0].tolist()
								elif self.framework == "tf":
											return model_outputs[0].numpy().tolist()



					def __call__(     self					:       Dict				,					*_snake_case					:       int				,					**_snake_case					:       List[str]					):






								"""simple docstring"""


								return super().__call__(*_snake_case				,					**_snake_case					)




