"""simple docstring"""




import math

import tensorflow as tf
from packaging import version





def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       Optional[int]	)       ->      Tuple:
  _lowerCAmelCase						:       Any  			=     tf.convert_to_tensor(_lowerCamelCase	)
  _lowerCAmelCase						:       Optional[Any]  			=     0.5 * (1.0 + tf.math.erf(x / tf.cast(tf.sqrt(2.0	)			,x.dtype	)	))

  return x * cdf





def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       Optional[Any]	)       ->      str:
  _lowerCAmelCase						:       str  			=     tf.convert_to_tensor(_lowerCamelCase	)
  _lowerCAmelCase						:       Optional[Any]  			=     tf.cast(math.pi			,x.dtype	)
  _lowerCAmelCase						:       int  			=     tf.cast(0.04_47_15			,x.dtype	)
  _lowerCAmelCase						:       Tuple  			=     0.5 * (1.0 + tf.tanh(tf.sqrt(2.0 / pi	) * (x + coeff * tf.pow(_lowerCamelCase			,3	))	))

  return x * cdf





def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       Union[str, Any]	)       ->      List[Any]:
  _lowerCAmelCase						:       Optional[int]  			=     tf.convert_to_tensor(_lowerCamelCase	)

  return x * tf.tanh(tf.math.softplus(_lowerCamelCase	)	)





def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       List[Any]	)       ->      Union[str, Any]:
  _lowerCAmelCase						:       Union[str, Any]  			=     tf.convert_to_tensor(_lowerCamelCase	)
  _lowerCAmelCase						:       Tuple  			=     tf.cast(0.04_47_15			,x.dtype	)
  _lowerCAmelCase						:       Union[str, Any]  			=     tf.cast(0.79_78_84_56_08			,x.dtype	)

  return 0.5 * x * (1.0 + tf.tanh(x * coeffa * (1.0 + coeffa * x * x)	))





def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       Any	)       ->      Optional[int]:
  _lowerCAmelCase						:       Optional[Any]  			=     tf.convert_to_tensor(_lowerCamelCase	)
  _lowerCAmelCase						:       Tuple  			=     tf.cast(1.7_02			,x.dtype	)
  return x * tf.math.sigmoid(coeff * x	)





def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       int	)       ->      Dict:
  return tf.clip_by_value(_gelu(_lowerCamelCase	)			,-10			,10	)





def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       Tuple			,_lowerCamelCase						:       Dict=-1	)       ->      List[Any]:
  _lowerCAmelCase			,	_lowerCAmelCase						:       Dict  			=     tf.split(_lowerCamelCase			,2			,axis=_lowerCamelCase	)
  return a * tf.math.sigmoid(_lowerCamelCase	)


if version.parse(tf.version.VERSION) >= version.parse('2.4'):





     def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       str	)       ->      List[Any]:
       return tf.keras.activations.gelu(_lowerCamelCase			,approximate=_lowerCamelCase	)

     _a      :		Optional[int]           =   tf.keras.activations.gelu






     _a      :		Any           =   approximate_gelu_wrap
else:
     _a      :		Dict           =   _gelu
     _a      :		int           =   _gelu_new


_a      :		Dict           =   {
    'gelu': gelu,
    'gelu_10': gelu_aa,
    'gelu_fast': gelu_fast,
    'gelu_new': gelu_new,
    'glu': glu,
    'mish': mish,
    'quick_gelu': quick_gelu,
    'relu': tf.keras.activations.relu,
    'sigmoid': tf.keras.activations.sigmoid,
    'silu': tf.keras.activations.swish,
    'swish': tf.keras.activations.swish,
    'tanh': tf.keras.activations.tanh,
}






def 							SCREAMING_SNAKE_CASE     (			_lowerCamelCase						:       str	)       ->      List[str]:
  if activation_string in ACTaFN:
    return ACTaFN[activation_string]
  else:
    raise KeyError(f"function {activation_string} not found in ACT2FN mapping {list(ACTaFN.keys()	)}"	)





# 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 __snake_case				(						lowerCamelCase_		):
   lowerCAmelCase_														=							"Salesforce/blip-image-captioning-base"
   lowerCAmelCase_														=							(
       "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."
   )
   lowerCAmelCase_														=							"image_captioner"
   lowerCAmelCase_														=							AutoModelForVisionaSeq

   lowerCAmelCase_														=							["image"]
   lowerCAmelCase_														=							["text"]




   def __init__(    self			:				List[Any]       ,	*_lowercase			:				Optional[int]       ,	**_lowercase			:				Union[str, Any]      ):



     """simple docstring"""






     requires_backends(self       ,	["""vision"""]      )
     super().__init__(*_lowercase       ,	**_lowercase      )




   def 	__a						(    self			:				Tuple       ,	_lowercase			:				"Image"      ):



     """simple docstring"""






     return self.pre_processor(images=_lowercase       ,	return_tensors="""pt"""      )




   def 	__a						(    self			:				Union[str, Any]       ,	_lowercase			:				Optional[int]      ):



     """simple docstring"""






     return self.model.generate(**_lowercase      )




   def 	__a						(    self			:				int       ,	_lowercase			:				Any      ):



     """simple docstring"""






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