



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

__snake_case						:List[str]      		=     logging.get_logger(__name__)

@add_end_docstrings(__UpperCAmelCase    )
class     _A       (	__UpperCAmelCase    ):



       def __init__(		self							:     Any     ,		**__SCREAMING_SNAKE_CASE							:     Tuple):


           '''simple docstring'''

           super().__init__(**__SCREAMING_SNAKE_CASE)

           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							:     Tuple     ,		__SCREAMING_SNAKE_CASE							:     Union[str, List[str], "Image", List["Image"]]     ,		**__SCREAMING_SNAKE_CASE							:     Tuple):


           '''simple docstring'''

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



       def 		_lowerCamelCase			(		self							:     Dict     ,		**__SCREAMING_SNAKE_CASE							:     Optional[int]):


           '''simple docstring'''

           __a						       =				{}
           if "candidate_labels" in kwargs:
               __a						       =				kwargs['''candidate_labels''']
           if "hypothesis_template" in kwargs:
               __a						       =				kwargs['''hypothesis_template''']

           return preprocess_params, {}, {}



       def 		_lowerCamelCase			(		self							:     Optional[Any]     ,		__SCREAMING_SNAKE_CASE							:     Union[str, Any]     ,		__SCREAMING_SNAKE_CASE							:     List[str]=None     ,		__SCREAMING_SNAKE_CASE							:     Dict="This is a photo of {}."):


           '''simple docstring'''

           __a						       =				load_image(__SCREAMING_SNAKE_CASE)
           __a						       =				self.image_processor(images=[image]     ,		return_tensors=self.framework)
           __a						       =				candidate_labels
           __a						       =				[hypothesis_template.format(__SCREAMING_SNAKE_CASE) for x in candidate_labels]
           __a						       =				self.tokenizer(__SCREAMING_SNAKE_CASE     ,		return_tensors=self.framework     ,		padding=__SCREAMING_SNAKE_CASE)
           __a						       =				[text_inputs]
           return inputs



       def 		_lowerCamelCase			(		self							:     Dict     ,		__SCREAMING_SNAKE_CASE							:     Optional[Any]):


           '''simple docstring'''

           __a						       =				model_inputs.pop('''candidate_labels''')
           __a						       =				model_inputs.pop('''text_inputs''')
           if isinstance(text_inputs[0]     ,		__SCREAMING_SNAKE_CASE):
               __a						       =				text_inputs[0]
           else:
               # Batching case.
               __a						       =				text_inputs[0][0]

           __a						       =				self.model(**__SCREAMING_SNAKE_CASE     ,		**__SCREAMING_SNAKE_CASE)

           __a						       =				{
               '''candidate_labels''': candidate_labels,
               '''logits''': outputs.logits_per_image,
           }
           return model_outputs





       def 		_lowerCamelCase			(		self							:     List[Any]     ,		__SCREAMING_SNAKE_CASE							:     Dict):


           '''simple docstring'''

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

           __a						       =				[
               {'''score''': score, '''label''': candidate_label}
               for score, candidate_label in sorted(zip(__SCREAMING_SNAKE_CASE     ,		__SCREAMING_SNAKE_CASE)     ,		key=lambda __SCREAMING_SNAKE_CASE: -x[0])
           ]
           return result












from __future__ import annotations







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a  )      ->      float:
					if days_between_payments <= 0:
										raise ValueError('days_between_payments must be > 0'  )
					if daily_interest_rate < 0:
										raise ValueError('daily_interest_rate must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )
					return principal * daily_interest_rate * days_between_payments







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a					,						)      ->      float:
					if number_of_compounding_periods <= 0:
										raise ValueError('number_of_compounding_periods must be > 0'  )
					if nominal_annual_interest_rate_percentage < 0:
										raise ValueError('nominal_annual_interest_rate_percentage must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )

					return principal * (
					    (1 + nominal_annual_interest_rate_percentage) ** number_of_compounding_periods
					    - 1
					)







def  _SCREAMING_SNAKE_CASE				(   a					,						a					,						a					,						)      ->      float:
					if number_of_years <= 0:
										raise ValueError('number_of_years must be > 0'  )
					if nominal_annual_percentage_rate < 0:
										raise ValueError('nominal_annual_percentage_rate must be >= 0'  )
					if principal <= 0:
										raise ValueError('principal must be > 0'  )

					return compound_interest(
					    a					,						nominal_annual_percentage_rate / 3_65					,						number_of_years * 3_65  )


if __name__ == "__main__":
				import doctest

				doctest.testmod()




