





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

@add_end_docstrings(_a    )
class     __SCREAMING_SNAKE_CASE   (       _a    ):






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






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






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






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







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

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

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











from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available


UpperCamelCase__     =	{}

try:
					if not is_sentencepiece_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					UpperCamelCase__     =	["GPTSw3Tokenizer"]


if TYPE_CHECKING:
					try:
										if not is_sentencepiece_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_gpt_swa import GPTSwaTokenizer

else:
					import sys

					UpperCamelCase__     =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




