
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_tf_available():
 import tensorflow as tf

 from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
 from ..tf_utils import stable_softmax

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

__lowerCAmelCase					:			Dict			      =		logging.get_logger(__name__)


@add_end_docstrings(lowerCAmelCase_      )
class 						__lowerCAmelCase	(	lowerCAmelCase_      ):



      """simple docstring"""







      def __init__(      self		:       int				,       *_snake_case		:       List[Any]				,       **_snake_case		:       List[Any]				):
          super().__init__(*_snake_case				,       **_snake_case				)
          requires_backends(self				,       '''vision'''				)
          self.check_model_type(
              TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
              if self.framework == '''tf'''
              else MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING				)




      def 		snake_case_			(      self		:       List[Any]				,       _snake_case		:       List[str]=None				):
          __lowercase		:			int	    =       {}
          if top_k is not None:
              __lowercase		:			str	    =       top_k
          return {}, {}, postprocess_params




      def __call__(      self		:       Optional[Any]				,       _snake_case		:       Union[str, List[str], "Image.Image", List["Image.Image"]]				,       **_snake_case		:       List[str]				):
          return super().__call__(_snake_case				,       **_snake_case				)




      def 		snake_case_			(      self		:       Optional[Any]				,       _snake_case		:       List[str]				):
          __lowercase		:			Optional[Any]	    =       load_image(_snake_case				)
          __lowercase		:			Dict	    =       self.image_processor(images=_snake_case				,       return_tensors=self.framework				)
          return model_inputs




      def 		snake_case_			(      self		:       List[str]				,       _snake_case		:       int				):
          __lowercase		:			int	    =       self.model(**_snake_case				)
          return model_outputs




      def 		snake_case_			(      self		:       Tuple				,       _snake_case		:       List[Any]				,       _snake_case		:       List[Any]=5				):
          if top_k > self.model.config.num_labels:
              __lowercase		:			Optional[Any]	    =       self.model.config.num_labels

          if self.framework == "pt":
              __lowercase		:			str	    =       model_outputs.logits.softmax(-1				)[0]
              __lowercase    ,      __lowercase		:			List[str]	    =       probs.topk(_snake_case				)
          elif self.framework == "tf":
              __lowercase		:			Dict	    =       stable_softmax(model_outputs.logits				,       axis=-1				)[0]
              __lowercase		:			Dict	    =       tf.math.top_k(_snake_case				,       k=_snake_case				)
              __lowercase    ,      __lowercase		:			Tuple	    =       topk.values.numpy(), topk.indices.numpy()
          else:
              raise ValueError(F'Unsupported framework: {self.framework}'				)

          __lowercase		:			Tuple	    =       scores.tolist()
          __lowercase		:			Optional[Any]	    =       ids.tolist()
          return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(_snake_case				,       _snake_case				)]




from __future__ import annotations


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						int:
    if not nums:
        return 0
    __lowercase		:			List[Any]	    =       nums[0]
    __lowercase		:			Union[str, Any]	    =       0
    for num in nums[1:]:
        __lowercase    ,      __lowercase		:			Dict	    =       (
            max_excluding + num,
            max(__lowerCAmelCase	,					__lowerCAmelCase	),
        )
    return max(__lowerCAmelCase	,					__lowerCAmelCase	)


if __name__ == "__main__":
 import doctest

 doctest.testmod()


