






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    				=		logging.get_logger(__name__)


@add_end_docstrings(lowerCAmelCase					)
class  SCREAMING_SNAKE_CASE			(			lowerCAmelCase					):
     '''simple docstring'''


     def __init__(				self       :	Tuple					, *UpperCAmelCase_       :	List[Any]					, **UpperCAmelCase_       :	Dict      ):
       super().__init__(*UpperCAmelCase_					, **UpperCAmelCase_      )
       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 				_A       (				self       :	Optional[Any]					, UpperCAmelCase_       :	Optional[int]=None      ):
       SCREAMING_SNAKE_CASE       :      int							=    {}
       if top_k is not None:
         SCREAMING_SNAKE_CASE       :      Dict							=    top_k
       return {}, {}, postprocess_params


     def __call__(				self       :	List[str]					, UpperCAmelCase_       :	Union[str, List[str], "Image.Image", List["Image.Image"]]					, **UpperCAmelCase_       :	Tuple      ):
       return super().__call__(UpperCAmelCase_					, **UpperCAmelCase_      )


     def 				_A       (				self       :	Dict					, UpperCAmelCase_       :	List[Any]      ):
       SCREAMING_SNAKE_CASE       :      int							=    load_image(UpperCAmelCase_      )
       SCREAMING_SNAKE_CASE       :      Tuple							=    self.image_processor(images=UpperCAmelCase_					, return_tensors=self.framework      )
       return model_inputs


     def 				_A       (				self       :	List[str]					, UpperCAmelCase_       :	Union[str, Any]      ):
       SCREAMING_SNAKE_CASE       :      Optional[Any]							=    self.model(**UpperCAmelCase_      )
       return model_outputs






     def 				_A       (				self       :	Optional[Any]					, UpperCAmelCase_       :	Any					, UpperCAmelCase_       :	Tuple=5      ):
       if top_k > self.model.config.num_labels:
         SCREAMING_SNAKE_CASE       :      Optional[Any]							=    self.model.config.num_labels

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

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














from ..utils import DummyObject, requires_backends


class  SCREAMING_SNAKE_CASE			(			metaclass=lowerCAmelCase					):
     '''simple docstring'''


     UpperCamelCase_							:		Union[str, Any]			=	['''keras_nlp''']


     def __init__(				self       :	Dict					, *UpperCAmelCase_       :	Optional[Any]					, **UpperCAmelCase_       :	Dict      ):
       requires_backends(self					, ["keras_nlp"]      )






