





from collections import UserDict
from typing import List, Union

from ..utils import (
    add_end_docstrings,
    is_tf_available,
    is_torch_available,
    is_vision_available,
    logging,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_vision_available():
     from PIL import Image

     from ..image_utils import load_image

if is_torch_available():
     from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
     from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
     from ..tf_utils import stable_softmax

UpperCAmelCase     :     Any							=	logging.get_logger(__name__)







@add_end_docstrings(UpperCamelCase__)
class     __lowerCAmelCase	(   UpperCamelCase__):







      def __init__(   self		,				**lowerCAmelCase__							)       ->						List[Any]:



        '''simple docstring'''




        super().__init__(**lowerCamelCase_							)

        requires_backends(self		,				"vision"							)
        self.check_model_type(
            TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
            if self.framework == "tf"
            else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING							)







      def __call__(   self		,				lowerCAmelCase__		,				**lowerCAmelCase__							)       ->						Tuple:



        '''simple docstring'''




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







      def        _lowercase  (   self		,				**lowerCAmelCase__							)       ->						Union[str, Any]:



        '''simple docstring'''




        a__     : Dict  ={}
        if "candidate_labels" in kwargs:
          a__     : int  =kwargs["candidate_labels"]
        if "hypothesis_template" in kwargs:
          a__     : Optional[Any]  =kwargs["hypothesis_template"]

        return preprocess_params, {}, {}







      def        _lowercase  (   self		,				lowerCAmelCase__		,				lowerCAmelCase__=None		,				lowerCAmelCase__="This is a photo of {}."							)       ->						Tuple:



        '''simple docstring'''




        a__     : Dict  =load_image(lowerCamelCase_							)
        a__     : Union[str, Any]  =self.image_processor(images=[image]		,				return_tensors=self.framework							)
        a__     : Union[str, Any]  =candidate_labels
        a__     : Any  =[hypothesis_template.format(lowerCamelCase_							) for x in candidate_labels]
        a__     : List[str]  =self.tokenizer(lowerCamelCase_		,				return_tensors=self.framework		,				padding=lowerCamelCase_							)
        a__     : Optional[Any]  =[text_inputs]
        return inputs







      def        _lowercase  (   self		,				lowerCAmelCase__							)       ->						Tuple:



        '''simple docstring'''




        a__     : List[Any]  =model_inputs.pop("candidate_labels"							)
        a__     : Optional[int]  =model_inputs.pop("text_inputs"							)
        if isinstance(text_inputs[0]		,				lowerCamelCase_							):
          a__     : List[Any]  =text_inputs[0]
        else:
          # Batching case.
          a__     : Optional[Any]  =text_inputs[0][0]

        a__     : Tuple  =self.model(**lowerCamelCase_		,				**lowerCamelCase_							)

        a__     : List[Any]  ={
            "candidate_labels": candidate_labels,
            "logits": outputs.logits_per_image,
        }
        return model_outputs







      def        _lowercase  (   self		,				lowerCAmelCase__							)       ->						int:



        '''simple docstring'''




        a__     : Union[str, Any]  =model_outputs.pop("candidate_labels"							)
        a__     : List[Any]  =model_outputs["logits"][0]
        if self.framework == "pt":
          a__     : Dict  =logits.softmax(dim=-1							).squeeze(-1							)
          a__     : List[str]  =probs.tolist()
          if not isinstance(lowerCamelCase_		,				lowerCamelCase_							):
            a__     : int  =[scores]
        elif self.framework == "tf":
          a__     : Any  =stable_softmax(lowerCamelCase_		,				axis=-1							)
          a__     : List[Any]  =probs.numpy().tolist()
        else:
          raise ValueError(F'''Unsupported framework: {self.framework}'''							)

        a__     : List[str]  =[
            {"score": score, "label": candidate_label}
            for score, candidate_label in sorted(zip(lowerCamelCase_		,				lowerCamelCase_							)		,				key=lambda lowerCAmelCase__							: -x[0]							)
        ]
        return result













def 					_A	(		SCREAMING_SNAKE_CASE					:       float	,	SCREAMING_SNAKE_CASE					:       float						):





  """simple docstring"""



  return price * (1 + tax_rate)


if __name__ == "__main__":
     print(F"""{price_plus_tax(100, 0.2_5) = }""")
     print(F"""{price_plus_tax(1_2_5.5_0, 0.0_5) = }""")






