"""simple docstring"""





import unittest

from transformers import (
    MODEL_FOR_OBJECT_DETECTION_MAPPING,
    AutoFeatureExtractor,
    AutoModelForObjectDetection,
    ObjectDetectionPipeline,
    is_vision_available,
    pipeline,
)
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_pytesseract,
    require_tf,
    require_timm,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
			from PIL import Image
else:




			class  _snake_case		:







							"""simple docstring"""






							@staticmethod
							def 		_lowerCAmelCase		(      *_A							:							Union[str, Any]      ,    **_A							:							List[Any]):



														"""simple docstring"""







														pass




@is_pipeline_test
@require_vision
@require_timm
@require_torch
class  _snake_case		(    unittest.TestCase ):







				"""simple docstring"""






				a			=						MODEL_FOR_OBJECT_DETECTION_MAPPING





				def 		_lowerCAmelCase		(      self							:							Union[str, Any]      ,    _A							:							Optional[int]      ,    _A							:							Any      ,    _A							:							Tuple):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    ObjectDetectionPipeline(model=_A      ,    image_processor=_A)
											return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]





				def 		_lowerCAmelCase		(      self							:							List[str]      ,    _A							:							List[str]      ,    _A							:							Optional[int]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    object_detector("""./tests/fixtures/tests_samples/COCO/000000039769.png"""      ,    threshold=0.0)

											self.assertGreater(len(_A)      ,    0)
											for detected_object in outputs:
																		self.assertEqual(
																		    _A      ,    {
																		        """score""": ANY(_A),
																		        """label""": ANY(_A),
																		        """box""": {"""xmin""": ANY(_A), """ymin""": ANY(_A), """xmax""": ANY(_A), """ymax""": ANY(_A)},
																		    }      ,    )

											import datasets

											_SCREAMING_SNAKE_CASE			  =    datasets.load_dataset("""hf-internal-testing/fixtures_image_utils"""      ,    """image"""      ,    split="""test""")

											_SCREAMING_SNAKE_CASE			  =    [
											    Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""),
											    """http://images.cocodataset.org/val2017/000000039769.jpg""",
											    # RGBA
											    dataset[0]["""file"""],
											    # LA
											    dataset[1]["""file"""],
											    # L
											    dataset[2]["""file"""],
											]
											_SCREAMING_SNAKE_CASE			  =    object_detector(_A      ,    threshold=0.0)

											self.assertEqual(len(_A)      ,    len(_A))
											for outputs in batch_outputs:
																		self.assertGreater(len(_A)      ,    0)
																		for detected_object in outputs:
																									self.assertEqual(
																									    _A      ,    {
																									        """score""": ANY(_A),
																									        """label""": ANY(_A),
																									        """box""": {"""xmin""": ANY(_A), """ymin""": ANY(_A), """xmax""": ANY(_A), """ymax""": ANY(_A)},
																									    }      ,    )





				@require_tf
				@unittest.skip("""Object detection not implemented in TF""")
				def 		_lowerCAmelCase		(      self							:							Dict):



											"""simple docstring"""







											pass





				@require_torch
				def 		_lowerCAmelCase		(      self							:							List[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    """hf-internal-testing/tiny-detr-mobilenetsv3"""

											_SCREAMING_SNAKE_CASE			  =    AutoModelForObjectDetection.from_pretrained(_A)
											_SCREAMING_SNAKE_CASE			  =    AutoFeatureExtractor.from_pretrained(_A)
											_SCREAMING_SNAKE_CASE			  =    ObjectDetectionPipeline(model=_A      ,    feature_extractor=_A)

											_SCREAMING_SNAKE_CASE			  =    object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg"""      ,    threshold=0.0)

											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 1_5_9, """ymin""": 1_2_0, """xmax""": 4_8_0, """ymax""": 3_5_9}},
											        {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 1_5_9, """ymin""": 1_2_0, """xmax""": 4_8_0, """ymax""": 3_5_9}},
											    ]      ,    )

											_SCREAMING_SNAKE_CASE			  =    object_detector(
											    [
											        """http://images.cocodataset.org/val2017/000000039769.jpg""",
											        """http://images.cocodataset.org/val2017/000000039769.jpg""",
											    ]      ,    threshold=0.0      ,    )

											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        [
											            {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 1_5_9, """ymin""": 1_2_0, """xmax""": 4_8_0, """ymax""": 3_5_9}},
											            {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 1_5_9, """ymin""": 1_2_0, """xmax""": 4_8_0, """ymax""": 3_5_9}},
											        ],
											        [
											            {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 1_5_9, """ymin""": 1_2_0, """xmax""": 4_8_0, """ymax""": 3_5_9}},
											            {"""score""": 0.3_376, """label""": """LABEL_0""", """box""": {"""xmin""": 1_5_9, """ymin""": 1_2_0, """xmax""": 4_8_0, """ymax""": 3_5_9}},
											        ],
											    ]      ,    )





				@require_torch
				@slow
				def 		_lowerCAmelCase		(      self							:							Optional[Any]):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    """facebook/detr-resnet-50"""

											_SCREAMING_SNAKE_CASE			  =    AutoModelForObjectDetection.from_pretrained(_A)
											_SCREAMING_SNAKE_CASE			  =    AutoFeatureExtractor.from_pretrained(_A)
											_SCREAMING_SNAKE_CASE			  =    ObjectDetectionPipeline(model=_A      ,    feature_extractor=_A)

											_SCREAMING_SNAKE_CASE			  =    object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg""")
											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_0, """xmax""": 1_7_5, """ymax""": 1_1_7}},
											        {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 3_3_3, """ymin""": 7_2, """xmax""": 3_6_8, """ymax""": 1_8_7}},
											        {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 6_3_9, """ymax""": 4_7_3}},
											        {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 1_3, """ymin""": 5_2, """xmax""": 3_1_4, """ymax""": 4_7_0}},
											        {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 3_4_5, """ymin""": 2_3, """xmax""": 6_4_0, """ymax""": 3_6_8}},
											    ]      ,    )

											_SCREAMING_SNAKE_CASE			  =    object_detector(
											    [
											        """http://images.cocodataset.org/val2017/000000039769.jpg""",
											        """http://images.cocodataset.org/val2017/000000039769.jpg""",
											    ])
											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        [
											            {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_0, """xmax""": 1_7_5, """ymax""": 1_1_7}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 3_3_3, """ymin""": 7_2, """xmax""": 3_6_8, """ymax""": 1_8_7}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 6_3_9, """ymax""": 4_7_3}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 1_3, """ymin""": 5_2, """xmax""": 3_1_4, """ymax""": 4_7_0}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 3_4_5, """ymin""": 2_3, """xmax""": 6_4_0, """ymax""": 3_6_8}},
											        ],
											        [
											            {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_0, """xmax""": 1_7_5, """ymax""": 1_1_7}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 3_3_3, """ymin""": 7_2, """xmax""": 3_6_8, """ymax""": 1_8_7}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 6_3_9, """ymax""": 4_7_3}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 1_3, """ymin""": 5_2, """xmax""": 3_1_4, """ymax""": 4_7_0}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 3_4_5, """ymin""": 2_3, """xmax""": 6_4_0, """ymax""": 3_6_8}},
											        ],
											    ]      ,    )





				@require_torch
				@slow
				def 		_lowerCAmelCase		(      self							:							int):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    """facebook/detr-resnet-50"""

											_SCREAMING_SNAKE_CASE			  =    pipeline("""object-detection"""      ,    model=_A)

											_SCREAMING_SNAKE_CASE			  =    object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg""")
											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_0, """xmax""": 1_7_5, """ymax""": 1_1_7}},
											        {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 3_3_3, """ymin""": 7_2, """xmax""": 3_6_8, """ymax""": 1_8_7}},
											        {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 6_3_9, """ymax""": 4_7_3}},
											        {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 1_3, """ymin""": 5_2, """xmax""": 3_1_4, """ymax""": 4_7_0}},
											        {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 3_4_5, """ymin""": 2_3, """xmax""": 6_4_0, """ymax""": 3_6_8}},
											    ]      ,    )

											_SCREAMING_SNAKE_CASE			  =    object_detector(
											    [
											        """http://images.cocodataset.org/val2017/000000039769.jpg""",
											        """http://images.cocodataset.org/val2017/000000039769.jpg""",
											    ])
											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        [
											            {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_0, """xmax""": 1_7_5, """ymax""": 1_1_7}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 3_3_3, """ymin""": 7_2, """xmax""": 3_6_8, """ymax""": 1_8_7}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 6_3_9, """ymax""": 4_7_3}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 1_3, """ymin""": 5_2, """xmax""": 3_1_4, """ymax""": 4_7_0}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 3_4_5, """ymin""": 2_3, """xmax""": 6_4_0, """ymax""": 3_6_8}},
											        ],
											        [
											            {"""score""": 0.9_982, """label""": """remote""", """box""": {"""xmin""": 4_0, """ymin""": 7_0, """xmax""": 1_7_5, """ymax""": 1_1_7}},
											            {"""score""": 0.9_960, """label""": """remote""", """box""": {"""xmin""": 3_3_3, """ymin""": 7_2, """xmax""": 3_6_8, """ymax""": 1_8_7}},
											            {"""score""": 0.9_955, """label""": """couch""", """box""": {"""xmin""": 0, """ymin""": 1, """xmax""": 6_3_9, """ymax""": 4_7_3}},
											            {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 1_3, """ymin""": 5_2, """xmax""": 3_1_4, """ymax""": 4_7_0}},
											            {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 3_4_5, """ymin""": 2_3, """xmax""": 6_4_0, """ymax""": 3_6_8}},
											        ],
											    ]      ,    )





				@require_torch
				@slow
				def 		_lowerCAmelCase		(      self							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    0.9_985
											_SCREAMING_SNAKE_CASE			  =    """facebook/detr-resnet-50"""

											_SCREAMING_SNAKE_CASE			  =    pipeline("""object-detection"""      ,    model=_A)

											_SCREAMING_SNAKE_CASE			  =    object_detector("""http://images.cocodataset.org/val2017/000000039769.jpg"""      ,    threshold=_A)
											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        {"""score""": 0.9_988, """label""": """cat""", """box""": {"""xmin""": 1_3, """ymin""": 5_2, """xmax""": 3_1_4, """ymax""": 4_7_0}},
											        {"""score""": 0.9_987, """label""": """cat""", """box""": {"""xmin""": 3_4_5, """ymin""": 2_3, """xmax""": 6_4_0, """ymax""": 3_6_8}},
											    ]      ,    )





				@require_torch
				@require_pytesseract
				@slow
				def 		_lowerCAmelCase		(      self							:							str):



											"""simple docstring"""







											_SCREAMING_SNAKE_CASE			  =    """Narsil/layoutlmv3-finetuned-funsd"""
											_SCREAMING_SNAKE_CASE			  =    0.9_993

											_SCREAMING_SNAKE_CASE			  =    pipeline("""object-detection"""      ,    model=_A      ,    threshold=_A)

											_SCREAMING_SNAKE_CASE			  =    object_detector(
											    """https://huggingface.co/spaces/impira/docquery/resolve/2359223c1837a7587402bda0f2643382a6eefeab/invoice.png""")
											self.assertEqual(
											    nested_simplify(_A      ,    decimals=4)      ,    [
											        {"""score""": 0.9_993, """label""": """I-ANSWER""", """box""": {"""xmin""": 2_9_4, """ymin""": 2_5_4, """xmax""": 3_4_3, """ymax""": 2_6_4}},
											        {"""score""": 0.9_993, """label""": """I-ANSWER""", """box""": {"""xmin""": 2_9_4, """ymin""": 2_5_4, """xmax""": 3_4_3, """ymax""": 2_6_4}},
											    ]      ,    )



"""simple docstring"""





from __future__ import annotations



def      lowerCamelCase_(__SCREAMING_SNAKE_CASE     ,	__SCREAMING_SNAKE_CASE     ,	__SCREAMING_SNAKE_CASE     ,	)->    tuple:
							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()


