


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

A__:       Optional[int]          =			logging.get_logger(__name__)







@add_end_docstrings(a_ )
class A__			(		a_ ):






      def __init__(					self     :Tuple	,		*SCREAMING_SNAKE_CASE     :int	,		**SCREAMING_SNAKE_CASE     :Optional[int]      )			->   Any:




             '''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     :Optional[int]	,		SCREAMING_SNAKE_CASE     :int=None      )			->   int:




             '''simple docstring'''
             _a       :					Optional[int]	   ={}
             if top_k is not None:
                    _a       :					Any	   =top_k
             return {}, {}, postprocess_params






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




             '''simple docstring'''
             return super().__call__(_SCREAMING_SNAKE_CASE	,		**_SCREAMING_SNAKE_CASE      )






      def __UpperCAmelCase			(					self     :Tuple	,		SCREAMING_SNAKE_CASE     :Optional[int]      )			->   int:




             '''simple docstring'''
             _a       :					Dict	   =load_image(_SCREAMING_SNAKE_CASE      )
             _a       :					List[str]	   =self.image_processor(images=_SCREAMING_SNAKE_CASE	,		return_tensors=self.framework      )
             return model_inputs






      def __UpperCAmelCase			(					self     :List[Any]	,		SCREAMING_SNAKE_CASE     :str      )			->   str:




             '''simple docstring'''
             _a       :					List[Any]	   =self.model(**_SCREAMING_SNAKE_CASE      )
             return model_outputs






      def __UpperCAmelCase			(					self     :Union[str, Any]	,		SCREAMING_SNAKE_CASE     :Dict	,		SCREAMING_SNAKE_CASE     :Any=5      )			->   List[str]:




             '''simple docstring'''

             if top_k > self.model.config.num_labels:
                    _a       :					Dict	   =self.model.config.num_labels

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

             _a       :					Any	   =scores.tolist()
             _a       :					Optional[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 TYPE_CHECKING

from ...file_utils import _LazyModule, is_torch_available
from ...utils import OptionalDependencyNotAvailable


_UpperCamelCase						:  str							       =				{
    "configuration_gpt_neox_japanese": ["GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP", "GPTNeoXJapaneseConfig"],
    "tokenization_gpt_neox_japanese": ["GPTNeoXJapaneseTokenizer"],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _UpperCamelCase						:  Dict							       =				[
         "GPT_NEOX_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST",
         "GPTNeoXJapaneseForCausalLM",
         "GPTNeoXJapaneseLayer",
         "GPTNeoXJapaneseModel",
         "GPTNeoXJapanesePreTrainedModel",
     ]


if TYPE_CHECKING:
     from .configuration_gpt_neox_japanese import GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoXJapaneseConfig
     from .tokenization_gpt_neox_japanese import GPTNeoXJapaneseTokenizer

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_gpt_neox_japanese import (
              GPT_NEOX_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
              GPTNeoXJapaneseForCausalLM,
              GPTNeoXJapaneseLayer,
              GPTNeoXJapaneseModel,
              GPTNeoXJapanesePreTrainedModel,
          )


else:
     import sys

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





