


"""simple docstring"""
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

__SCREAMING_SNAKE_CASE							:    List[str]		=    logging.get_logger(__name__)





@add_end_docstrings(UpperCamelCase__)
class        __A     (UpperCamelCase__):





							'''simple docstring'''

							def __init__(				self							:      Union[str, Any]		,       **UpperCAmelCase_							:      Dict       )					->Tuple:



														"""simple docstring"""



														super().__init__(**__A       )

														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							:      Optional[int]		,       UpperCAmelCase_							:      Union[str, List[str], "Image", List["Image"]]		,       **UpperCAmelCase_							:      Any       )					->List[str]:



														"""simple docstring"""



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



							def 		lowerCAmelCase       (				self							:      Optional[int]		,       **UpperCAmelCase_							:      List[Any]       )					->List[Any]:



														"""simple docstring"""



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

														return preprocess_params, {}, {}



							def 		lowerCAmelCase       (				self							:      int		,       UpperCAmelCase_							:      Any		,       UpperCAmelCase_							:      List[str]=None		,       UpperCAmelCase_							:      Any="This is a photo of {}."       )					->List[Any]:



														"""simple docstring"""



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



							def 		lowerCAmelCase       (				self							:      str		,       UpperCAmelCase_							:      Optional[int]       )					->Union[str, Any]:



														"""simple docstring"""



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

														snake_case_           =		self.model(**__A		,       **__A       )

														snake_case_           =		{
														    """candidate_labels""": candidate_labels,
														    """logits""": outputs.logits_per_image,
														}
														return model_outputs



							def 		lowerCAmelCase       (				self							:      List[Any]		,       UpperCAmelCase_							:      str       )					->Optional[Any]:



														"""simple docstring"""



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

														snake_case_           =		[
														    {"""score""": score, """label""": candidate_label}
														    for score, candidate_label in sorted(zip(__A		,       __A       )		,       key=lambda UpperCAmelCase_       : -x[0]       )
														]
														return result







"""simple docstring"""
from __future__ import annotations







def 						_a				(      _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)    ->				list[int]:
							snake_case_           =		0
							snake_case_           =		len(_SCREAMING_SNAKE_CASE				) - 1

							while i < j:
														if nums[i] + nums[j] == target:
																					return [i, j]
														elif nums[i] + nums[j] < target:
																					snake_case_           =		i + 1
														else:
																					snake_case_           =		j - 1

							return []


if __name__ == "__main__":
				import doctest

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



