






"""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

UpperCamelCase_	:				Any										= logging.get_logger(__name__)


@add_end_docstrings(lowerCAmelCase						)
class      _lowercase (     lowerCAmelCase						):


      def __init__(    self				:	Tuple							,   *a				:	int							,   **a				:	List[str]						):





            """simple docstring"""







            super().__init__(*a							,   **a						)
            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				:	Optional[int]							,   a				:	List[Any]=None						):





            """simple docstring"""







            __snake_case      :    Dict  			={}
            if top_k is not None:
                  __snake_case      :    Optional[int]  			=top_k
            return {}, {}, postprocess_params


      def __call__(    self				:	int							,   a				:	Union[str, List[str], "Image.Image", List["Image.Image"]]							,   **a				:	List[Any]						):





            """simple docstring"""







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


      def _UpperCamelCase						(    self				:	Optional[int]							,   a				:	Optional[int]						):





            """simple docstring"""







            __snake_case      :    Dict  			=load_image(a						)
            __snake_case      :    Tuple  			=self.image_processor(images=a							,   return_tensors=self.framework						)
            return model_inputs


      def _UpperCamelCase						(    self				:	List[str]							,   a				:	int						):





            """simple docstring"""







            __snake_case      :    Optional[int]  			=self.model(**a						)
            return model_outputs







      def _UpperCamelCase						(    self				:	int							,   a				:	Any							,   a				:	int=5						):





            """simple docstring"""







            if top_k > self.model.config.num_labels:
                  __snake_case      :    int  			=self.model.config.num_labels

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

            __snake_case      :    List[Any]  			=scores.tolist()
            __snake_case      :    Union[str, Any]  			=ids.tolist()
            return [{"score": score, "label": self.model.config.idalabel[_id]} for score, _id in zip(a							,   a						)]










"""simple docstring"""





from typing import TYPE_CHECKING

from ...utils import _LazyModule


UpperCamelCase_	:				Union[str, Any]										= {"""tokenization_wav2vec2_phoneme""": ["""Wav2Vec2PhonemeCTCTokenizer"""]}


if TYPE_CHECKING:
    from .tokenization_wavaveca_phoneme import WavaVecaPhonemeCTCTokenizer
else:
    import sys

    UpperCamelCase_	:				List[Any]										= _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


