





"""simple docstring"""
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_								=		logging.get_logger(__name__)






@add_end_docstrings(A  )
class 					_SCREAMING_SNAKE_CASE(   A  ):




       def __init__(						self		,*SCREAMING_SNAKE_CASE__		,**SCREAMING_SNAKE_CASE__							)			->      int:





             """simple docstring"""






             super().__init__(*SCREAMING_SNAKE_CASE__		,**SCREAMING_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     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__=None							)			->      str:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :str						=  {}
             if top_k is not None:
                   __SCREAMING_SNAKE_CASE   :Any						=  top_k
             return {}, {}, postprocess_params




       def __call__(						self		,SCREAMING_SNAKE_CASE__		,**SCREAMING_SNAKE_CASE__							)			->      List[Any]:





             """simple docstring"""






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




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__							)			->      Tuple:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Dict						=  load_image(SCREAMING_SNAKE_CASE__							)
             __SCREAMING_SNAKE_CASE   :Any						=  self.image_processor(images=SCREAMING_SNAKE_CASE__		,return_tensors=self.framework							)
             return model_inputs




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__							)			->      Optional[int]:





             """simple docstring"""






             __SCREAMING_SNAKE_CASE   :Tuple						=  self.model(**SCREAMING_SNAKE_CASE__							)
             return model_outputs




       def     _UpperCamelCase     (						self		,SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__=5							)			->      Any:





             """simple docstring"""






             if top_k > self.model.config.num_labels:
                   __SCREAMING_SNAKE_CASE   :Optional[int]						=  self.model.config.num_labels

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

             __SCREAMING_SNAKE_CASE   :Optional[int]						=  scores.tolist()
             __SCREAMING_SNAKE_CASE   :int						=  ids.tolist()
             return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(SCREAMING_SNAKE_CASE__		,SCREAMING_SNAKE_CASE__							)]






"""simple docstring"""
from typing import Any



def      __lowerCamelCase   (							a_     :		list							)			->      list[Any]:
      if not input_list:
            return []
      __SCREAMING_SNAKE_CASE   :int						=  [input_list.count(a_							) for value in input_list]
      __SCREAMING_SNAKE_CASE   :str						=  max(a_							)  # Gets the maximum count in the input list.
      # Gets values of modes
      return sorted({input_list[i] for i, value in enumerate(a_							) if value == y}							)


if __name__ == "__main__":
  import doctest

  doctest.testmod()