

from collections import UserDict
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_torch_available():
	from ..models.auto.modeling_auto import MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING

if is_tf_available():
	from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
	from ..tf_utils import stable_softmax

lowerCAmelCase__		      =       logging.get_logger(__name__)

@add_end_docstrings(__UpperCamelCase	)
class     a__  (    __UpperCamelCase	):
			"""simple docstring"""







			def __init__(			self					,					**lowercase				)     ->  List[str]:
							'''simple docstring'''






							super().__init__(**lowerCAmelCase__				)

							requires_backends(self					,					"vision"				)
							self.check_model_type(
							    TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING
							    if self.framework == "tf"
							    else MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING				)


			def __call__(			self					,					lowercase					,					**lowercase				)     ->  Optional[Any]:
							'''simple docstring'''






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


			def    UpperCamelCase						(			self					,					**lowercase				)     ->  Dict:
							'''simple docstring'''






							A__						=	{}
							if "candidate_labels" in kwargs:
											A__						=	kwargs['candidate_labels']
							if "hypothesis_template" in kwargs:
											A__						=	kwargs['hypothesis_template']

							return preprocess_params, {}, {}


			def    UpperCamelCase						(			self					,					lowercase					,					lowercase=None					,					lowercase="This is a photo of {}."				)     ->  int:
							'''simple docstring'''






							A__						=	load_image(lowerCAmelCase__				)
							A__						=	self.image_processor(images=[image]					,					return_tensors=self.framework				)
							A__						=	candidate_labels
							A__						=	[hypothesis_template.format(lowerCAmelCase__				) for x in candidate_labels]
							A__						=	self.tokenizer(lowerCAmelCase__					,					return_tensors=self.framework					,					padding=lowerCAmelCase__				)
							A__						=	[text_inputs]
							return inputs


			def    UpperCamelCase						(			self					,					lowercase				)     ->  int:
							'''simple docstring'''






							A__						=	model_inputs.pop("candidate_labels"				)
							A__						=	model_inputs.pop("text_inputs"				)
							if isinstance(text_inputs[0]					,					lowerCAmelCase__				):
											A__						=	text_inputs[0]
							else:
											# Batching case.
											A__						=	text_inputs[0][0]

							A__						=	self.model(**lowerCAmelCase__					,					**lowerCAmelCase__				)

							A__						=	{
							    'candidate_labels': candidate_labels,
							    'logits': outputs.logits_per_image,
							}
							return model_outputs


			def    UpperCamelCase						(			self					,					lowercase				)     ->  Union[str, Any]:
							'''simple docstring'''






							A__						=	model_outputs.pop("candidate_labels"				)
							A__						=	model_outputs['logits'][0]
							if self.framework == "pt":
											A__						=	logits.softmax(dim=-1				).squeeze(-1				)
											A__						=	probs.tolist()
											if not isinstance(lowerCAmelCase__					,					lowerCAmelCase__				):
															A__						=	[scores]
							elif self.framework == "tf":
											A__						=	stable_softmax(lowerCAmelCase__					,					axis=-1				)
											A__						=	probs.numpy().tolist()
							else:
											raise ValueError(F'Unsupported framework: {self.framework}'				)

							A__						=	[
							    {'score': score, 'label': candidate_label}
							    for score, candidate_label in sorted(zip(lowerCAmelCase__					,					lowerCAmelCase__				)					,					key=lambda lowercase				: -x[0]				)
							]
							return result





from __future__ import annotations




def    snake_case_     (  snake_case			,							snake_case     )  ->				list[int]:
       lowercase__:   List[str]  			=   0
       lowercase__:   Dict  			=   len(snake_case     ) - 1

       while i < j:
              if nums[i] + nums[j] == target:
                     return [i, j]
              elif nums[i] + nums[j] < target:
                     lowercase__:   Dict  			=   i + 1
              else:
                     lowercase__:   List[Any]  			=   j - 1

       return []


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 print(F'''{two_pointer([2, 7, 11, 15], 9) = }''')


