





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

__A							   =							logging.get_logger(__name__)



@add_end_docstrings(__SCREAMING_SNAKE_CASE       )
class   _SCREAMING_SNAKE_CASE		(      __SCREAMING_SNAKE_CASE       ):







 '''simple docstring'''

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



   '''simple docstring'''



   super().__init__(**UpperCAmelCase_)

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



   '''simple docstring'''



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

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



   '''simple docstring'''



   lowerCamelCase__: Optional[int]         ={}
   if "candidate_labels" in kwargs:
     lowerCamelCase__: Tuple         =kwargs["candidate_labels"]
   if "hypothesis_template" in kwargs:
     lowerCamelCase__: Tuple         =kwargs["hypothesis_template"]

   return preprocess_params, {}, {}

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



   '''simple docstring'''



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

 def 				SCREAMING_SNAKE_CASE_   (self							:  Optional[int]			,					UpperCAmelCase_							:  Any)			->Tuple:



   '''simple docstring'''



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

   lowerCamelCase__: List[str]         =self.model(**UpperCAmelCase_			,					**UpperCAmelCase_)

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







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



   '''simple docstring'''



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

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








"""simple docstring"""





from __future__ import annotations



def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				list[int | str] ):


							'''simple docstring'''







							create_state_space_tree(SCREAMING_SNAKE_CASE     ,    []     ,    0     ,    [0 for i in range(len(SCREAMING_SNAKE_CASE ) )] )



def 					lowerCAmelCase_      (   SCREAMING_SNAKE_CASE							:				list[int | str]     ,    SCREAMING_SNAKE_CASE							:				list[int | str]     ,    SCREAMING_SNAKE_CASE							:				int     ,    SCREAMING_SNAKE_CASE							:				list[int]     ,    ):


							'''simple docstring'''







							if index == len(SCREAMING_SNAKE_CASE ):
														print(SCREAMING_SNAKE_CASE )
														return

							for i in range(len(SCREAMING_SNAKE_CASE ) ):
														if not index_used[i]:
																					current_sequence.append(sequence[i] )
																					__lowerCamelCase   :   List[Any]       =True
																					create_state_space_tree(SCREAMING_SNAKE_CASE     ,    SCREAMING_SNAKE_CASE     ,    index + 1     ,    SCREAMING_SNAKE_CASE )
																					current_sequence.pop()
																					__lowerCamelCase   :   List[Any]       =False
_UpperCamelCase					      =   [3, 1, 2, 4]
generate_all_permutations(sequence)

_UpperCamelCase					      =   ["A", "B", "C"]
generate_all_permutations(sequence_a)




