



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

__lowerCamelCase   :					Dict   							=					logging.get_logger(__name__)







@add_end_docstrings(a_							)
class    A_	(a_							):
							"""simple docstring"""




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


										'''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			:List[str]       ,							lowerCAmelCase__			:Union[str, Any]       ,							**lowerCAmelCase__			:str				)				->  Any:


										'''simple docstring'''




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

							def 							_A	(		self			:Tuple       ,							**lowerCAmelCase__			:Any				)				->  int:


										'''simple docstring'''




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

										return preprocess_params, {}, {}

							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:Dict       ,							lowerCAmelCase__			:Optional[Any]=None       ,							lowerCAmelCase__			:Optional[Any]="This is a photo of {}."				)				->  Optional[Any]:


										'''simple docstring'''




										snake_case_				:					List[str]   =       load_image(_lowerCAmelCase				)
										snake_case_				:					int   =       self.image_processor(images=[image]       ,							return_tensors=self.framework				)
										snake_case_				:					Any   =       candidate_labels
										snake_case_				:					Optional[Any]   =       [hypothesis_template.format(_lowerCAmelCase				) for x in candidate_labels]
										snake_case_				:					Tuple   =       self.tokenizer(_lowerCAmelCase       ,							return_tensors=self.framework       ,							padding=_lowerCAmelCase				)
										snake_case_				:					int   =       [text_inputs]
										return inputs

							def 							_A	(		self			:Dict       ,							lowerCAmelCase__			:List[Any]				)				->  int:


										'''simple docstring'''




										snake_case_				:					Optional[int]   =       model_inputs.pop("candidate_labels"				)
										snake_case_				:					str   =       model_inputs.pop("text_inputs"				)
										if isinstance(text_inputs[0]       ,							_lowerCAmelCase				):
													snake_case_				:					Tuple   =       text_inputs[0]
										else:
													# Batching case.
													snake_case_				:					List[Any]   =       text_inputs[0][0]

										snake_case_				:					Union[str, Any]   =       self.model(**_lowerCAmelCase       ,							**_lowerCAmelCase				)

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






							def 							_A	(		self			:Tuple       ,							lowerCAmelCase__			:List[Any]				)				->  List[Any]:


										'''simple docstring'''




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

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












'''simple docstring'''




def 	__UpperCAmelCase       ( __magic_name__						)->    list[int]:



			"""simple docstring"""



			if length <= 0 or not isinstance(__magic_name__     ,__magic_name__						):
						raise ValueError("Length must be a positive integer."						)
			return [n * (2 * n - 1) for n in range(__magic_name__						)]


if __name__ == "__main__":
		print(hexagonal_numbers(length=5))
		print(hexagonal_numbers(length=10))




