


"""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     :   List[Any]			    =			logging.get_logger(__name__)
@add_end_docstrings(lowerCAmelCase__		)
class   _UpperCamelCase  (   lowerCAmelCase__		):
							'''simple docstring'''







							def __init__(     self    ,   *__a    ,   **__a	):
										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 			snake_case				(     self    ,   __a=None	):
										__lowerCAmelCase				    =			{}
										if top_k is not None:
													__lowerCAmelCase				    =			top_k
										return {}, {}, postprocess_params

							def __call__(     self    ,   __a    ,   **__a	):
										return super().__call__(__a    ,   **__a	)

							def 			snake_case				(     self    ,   __a	):
										__lowerCAmelCase				    =			load_image(__a	)
										__lowerCAmelCase				    =			self.image_processor(images=__a    ,   return_tensors=self.framework	)
										return model_inputs

							def 			snake_case				(     self    ,   __a	):
										__lowerCAmelCase				    =			self.model(**__a	)
										return model_outputs



							def 			snake_case				(     self    ,   __a    ,   __a=5	):
										if top_k > self.model.config.num_labels:
													__lowerCAmelCase				    =			self.model.config.num_labels

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

										__lowerCAmelCase				    =			scores.tolist()
										__lowerCAmelCase				    =			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 OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


_lowerCamelCase	:       List[Any]      	=	{
    "configuration_m2m_100": ["M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP", "M2M100Config", "M2M100OnnxConfig"],
    "tokenization_m2m_100": ["M2M100Tokenizer"],
}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   _lowerCamelCase	:       int      	=	[
       "M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST",
       "M2M100ForConditionalGeneration",
       "M2M100Model",
       "M2M100PreTrainedModel",
   ]


if TYPE_CHECKING:
   from .configuration_mam_aaa import M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP, MaMaaaConfig, MaMaaaOnnxConfig
   from .tokenization_mam_aaa import MaMaaaTokenizer

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_mam_aaa import (
          M2M_100_PRETRAINED_MODEL_ARCHIVE_LIST,
          MaMaaaForConditionalGeneration,
          MaMaaaModel,
          MaMaaaPreTrainedModel,
      )


else:
   import sys

   _lowerCamelCase	:       Optional[int]      	=	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

