





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


from __future__ import annotations

SCREAMING_SNAKE_CASE		:     Tuple         =	1.6_021E-19  # units = C






def     lowerCAmelCase_			(   _SCREAMING_SNAKE_CASE     :				float		, _SCREAMING_SNAKE_CASE     :				float		, _SCREAMING_SNAKE_CASE     :				float		, ):
						if (conductivity, electron_conc, mobility).count(0			) != 1:
												raise ValueError("""You cannot supply more or less than 2 values"""			)
						elif conductivity < 0:
												raise ValueError("""Conductivity cannot be negative"""			)
						elif electron_conc < 0:
												raise ValueError("""Electron concentration cannot be negative"""			)
						elif mobility < 0:
												raise ValueError("""mobility cannot be negative"""			)
						elif conductivity == 0:
												return (
												    "conductivity",
												    mobility * electron_conc * ELECTRON_CHARGE,
												)
						elif electron_conc == 0:
												return (
												    "electron_conc",
												    conductivity / (mobility * ELECTRON_CHARGE),
												)
						else:
												return (
												    "mobility",
												    conductivity / (electron_conc * ELECTRON_CHARGE),
												)


if __name__ == "__main__":
	import doctest

	doctest.testmod()






