



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

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

@add_end_docstrings(__UpperCAmelCase    )
class     _A       (	__UpperCAmelCase    ):



       def __init__(		self							:     Any     ,		*__SCREAMING_SNAKE_CASE							:     Any     ,		**__SCREAMING_SNAKE_CASE							:     List[str]):


           '''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 		_lowerCamelCase			(		self							:     Tuple     ,		__SCREAMING_SNAKE_CASE							:     Any=None):


           '''simple docstring'''

           __a						       =				{}
           if top_k is not None:
               __a						       =				top_k
           return {}, {}, postprocess_params



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


           '''simple docstring'''

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



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


           '''simple docstring'''

           __a						       =				load_image(__SCREAMING_SNAKE_CASE)
           __a						       =				self.image_processor(images=__SCREAMING_SNAKE_CASE     ,		return_tensors=self.framework)
           return model_inputs



       def 		_lowerCamelCase			(		self							:     Dict     ,		__SCREAMING_SNAKE_CASE							:     Tuple):


           '''simple docstring'''

           __a						       =				self.model(**__SCREAMING_SNAKE_CASE)
           return model_outputs





       def 		_lowerCamelCase			(		self							:     Any     ,		__SCREAMING_SNAKE_CASE							:     Union[str, Any]     ,		__SCREAMING_SNAKE_CASE							:     List[str]=5):


           '''simple docstring'''

           if top_k > self.model.config.num_labels:
               __a						       =				self.model.config.num_labels

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

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










import copy
from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Optional, Union

@dataclass
class     _A       :
       UpperCamelCase__  :    Optional[Union[str, Path]]											=						None
       UpperCamelCase__  :    bool											=						False
       UpperCamelCase__  :    bool											=						False
       UpperCamelCase__  :    bool											=						False
       UpperCamelCase__  :    Optional[Dict]											=						None
       UpperCamelCase__  :    Optional[str]											=						None
       UpperCamelCase__  :    bool											=						False
       UpperCamelCase__  :    bool											=						False
       UpperCamelCase__  :    bool											=						False
       UpperCamelCase__  :    bool											=						True
       UpperCamelCase__  :    Optional[int]											=						None
       UpperCamelCase__  :    int											=						1
       UpperCamelCase__  :    Optional[Union[str, bool]]											=						None
       UpperCamelCase__  :    bool											=						False
       UpperCamelCase__  :    Optional[Dict]											=						None
       UpperCamelCase__  :    Optional[str]											=						None



       def 		_lowerCamelCase			(		self							:     Union[str, Any]):


           '''simple docstring'''

           return self.__class__(**{k: copy.deepcopy(__SCREAMING_SNAKE_CASE) for k, v in self.__dict__.items()})





