


"""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_       :       int      						=  logging.get_logger(__name__)






@add_end_docstrings(__SCREAMING_SNAKE_CASE      )
class 				__A    (	__SCREAMING_SNAKE_CASE      ):






	"""simple docstring"""




	def __init__(		self			,   **__A						) ->					List[Any]:
					super().__init__(**_snake_case						)

					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			,   __A			,   **__A						) ->					Any:
					return super().__call__(_snake_case			,   **_snake_case						)


	def 				SCREAMING_SNAKE_CASE							(		self			,   **__A						) ->					Tuple:
					a					={}
					if "candidate_labels" in kwargs:
									a					=kwargs["candidate_labels"]
					if "hypothesis_template" in kwargs:
									a					=kwargs["hypothesis_template"]

					return preprocess_params, {}, {}


	def 				SCREAMING_SNAKE_CASE							(		self			,   __A			,   __A=None			,   __A="This is a photo of {}."						) ->					Optional[Any]:
					a					=load_image(_snake_case						)
					a					=self.image_processor(images=[image]			,   return_tensors=self.framework						)
					a					=candidate_labels
					a					=[hypothesis_template.format(_snake_case						) for x in candidate_labels]
					a					=self.tokenizer(_snake_case			,   return_tensors=self.framework			,   padding=_snake_case						)
					a					=[text_inputs]
					return inputs


	def 				SCREAMING_SNAKE_CASE							(		self			,   __A						) ->					Optional[int]:
					a					=model_inputs.pop('''candidate_labels'''						)
					a					=model_inputs.pop('''text_inputs'''						)
					if isinstance(text_inputs[0]			,   _snake_case						):
									a					=text_inputs[0]
					else:
									# Batching case.
									a					=text_inputs[0][0]

					a					=self.model(**_snake_case			,   **_snake_case						)

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





	def 				SCREAMING_SNAKE_CASE							(		self			,   __A						) ->					Optional[Any]:
					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(_snake_case			,   _snake_case						):
													a					=[scores]
					elif self.framework == "tf":
									a					=stable_softmax(_snake_case			,   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(_snake_case			,   _snake_case						)			,   key=lambda __A						: -x[0]						)
					]
					return result



"""simple docstring"""







from __future__ import annotations
def _A						(						lowercase	,   lowercase	,   lowercase	,   ):







    """simple docstring"""
    if (electron_conc, hole_conc, intrinsic_conc).count(0		) != 1:
        raise ValueError('''You cannot supply more or less than 2 values'''		)
    elif electron_conc < 0:
        raise ValueError('''Electron concentration cannot be negative in a semiconductor'''		)
    elif hole_conc < 0:
        raise ValueError('''Hole concentration cannot be negative in a semiconductor'''		)
    elif intrinsic_conc < 0:
        raise ValueError(
            '''Intrinsic concentration cannot be negative in a semiconductor'''		)
    elif electron_conc == 0:
        return (
            "electron_conc",
            intrinsic_conc**2 / hole_conc,
        )
    elif hole_conc == 0:
        return (
            "hole_conc",
            intrinsic_conc**2 / electron_conc,
        )
    elif intrinsic_conc == 0:
        return (
            "intrinsic_conc",
            (electron_conc * hole_conc) ** 0.5,
        )
    else:
        return (-1, -1)


if __name__ == "__main__":
       import doctest

       doctest.testmod()