


import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
			from PIL import Image
else:


			class 			_a				:

										@staticmethod
										def  lowerCamelCase_					(				*UpperCamelCase_:      Any       ,		**UpperCamelCase_:      Union[str, Any]				)     ->  int:





												"""simple docstring"""







												pass


@is_pipeline_test
@require_vision
class 			_a				(     unittest.TestCase     ):

							@require_torch
							def  lowerCamelCase_					(				self:      int				)     ->  Dict:





									"""simple docstring"""







									lowercase__				= pipeline(
									    model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''       ,		)
									lowercase__				= Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
									lowercase__				= image_classifier(UpperCamelCase_       ,		candidate_labels=['''a''', '''b''', '''c''']				)

									# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
									# python and torch versions.
									self.assertIn(
									    nested_simplify(UpperCamelCase_				)       ,		[
									        [{'''score''': 0.333, '''label''': '''a'''}, {'''score''': 0.333, '''label''': '''b'''}, {'''score''': 0.333, '''label''': '''c'''}],
									        [{'''score''': 0.333, '''label''': '''a'''}, {'''score''': 0.333, '''label''': '''c'''}, {'''score''': 0.333, '''label''': '''b'''}],
									    ]       ,		)

									lowercase__				= image_classifier([image] * 5       ,		candidate_labels=['''A''', '''B''', '''C''']       ,		batch_size=2				)
									self.assertEqual(
									    nested_simplify(UpperCamelCase_				)       ,		[
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									    ]       ,		)

							@require_tf
							def  lowerCamelCase_					(				self:      int				)     ->  Optional[Any]:





									"""simple docstring"""







									lowercase__				= pipeline(
									    model='''hf-internal-testing/tiny-random-clip-zero-shot-image-classification'''       ,		framework='''tf'''				)
									lowercase__				= Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
									lowercase__				= image_classifier(UpperCamelCase_       ,		candidate_labels=['''a''', '''b''', '''c''']				)

									self.assertEqual(
									    nested_simplify(UpperCamelCase_				)       ,		[{'''score''': 0.333, '''label''': '''a'''}, {'''score''': 0.333, '''label''': '''b'''}, {'''score''': 0.333, '''label''': '''c'''}]       ,		)

									lowercase__				= image_classifier([image] * 5       ,		candidate_labels=['''A''', '''B''', '''C''']       ,		batch_size=2				)
									self.assertEqual(
									    nested_simplify(UpperCamelCase_				)       ,		[
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									        [
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									            {'''score''': 0.333, '''label''': ANY(UpperCamelCase_				)},
									        ],
									    ]       ,		)

							@slow
							@require_torch
							def  lowerCamelCase_					(				self:      Tuple				)     ->  Union[str, Any]:





									"""simple docstring"""







									lowercase__				= pipeline(
									    task='''zero-shot-image-classification'''       ,		model='''openai/clip-vit-base-patch32'''       ,		)
									# This is an image of 2 cats with remotes and no planes
									lowercase__				= Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
									lowercase__				= image_classifier(UpperCamelCase_       ,		candidate_labels=['''cat''', '''plane''', '''remote''']				)

									self.assertEqual(
									    nested_simplify(UpperCamelCase_				)       ,		[
									        {'''score''': 0.511, '''label''': '''remote'''},
									        {'''score''': 0.485, '''label''': '''cat'''},
									        {'''score''': 0.004, '''label''': '''plane'''},
									    ]       ,		)

									lowercase__				= image_classifier([image] * 5       ,		candidate_labels=['''cat''', '''plane''', '''remote''']       ,		batch_size=2				)
									self.assertEqual(
									    nested_simplify(UpperCamelCase_				)       ,		[
									        [
									            {'''score''': 0.511, '''label''': '''remote'''},
									            {'''score''': 0.485, '''label''': '''cat'''},
									            {'''score''': 0.004, '''label''': '''plane'''},
									        ],
									    ]
									    * 5       ,		)


							@slow
							@require_tf
							def  lowerCamelCase_					(				self:      Optional[int]				)     ->  List[Any]:





									"""simple docstring"""







									lowercase__				= pipeline(
									    task='''zero-shot-image-classification'''       ,		model='''openai/clip-vit-base-patch32'''       ,		framework='''tf'''				)
									# This is an image of 2 cats with remotes and no planes
									lowercase__				= Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''				)
									lowercase__				= image_classifier(UpperCamelCase_       ,		candidate_labels=['''cat''', '''plane''', '''remote''']				)
									self.assertEqual(
									    nested_simplify(UpperCamelCase_				)       ,		[
									        {'''score''': 0.511, '''label''': '''remote'''},
									        {'''score''': 0.485, '''label''': '''cat'''},
									        {'''score''': 0.004, '''label''': '''plane'''},
									    ]       ,		)

									lowercase__				= image_classifier([image] * 5       ,		candidate_labels=['''cat''', '''plane''', '''remote''']       ,		batch_size=2				)
									self.assertEqual(
									    nested_simplify(UpperCamelCase_				)       ,		[
									        [
									            {'''score''': 0.511, '''label''': '''remote'''},
									            {'''score''': 0.485, '''label''': '''cat'''},
									            {'''score''': 0.004, '''label''': '''plane'''},
									        ],
									    ]
									    * 5       ,		)









'''simple docstring'''




import unittest

from transformers import DonutProcessor


__UpperCAmelCase            =       """naver-clova-ix/donut-base"""




class      UpperCamelCase__					(					unittest.TestCase			):




					"""simple docstring"""


					def lowerCamelCase_			(						self				:			List[str]						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Any		=			DonutProcessor.from_pretrained(lowerCamelCase_						)



					def lowerCamelCase_			(						self				:			Tuple						):

							'''simple docstring'''



							SCREAMING_SNAKE_CASE :				Optional[int]		=			{
							    """name""": """John Doe""",
							    """age""": """99""",
							    """city""": """Atlanta""",
							    """state""": """GA""",
							    """zip""": """30301""",
							    """phone""": """123-4567""",
							    """nicknames""": [{"""nickname""": """Johnny"""}, {"""nickname""": """JD"""}],
							}

							SCREAMING_SNAKE_CASE :				List[Any]		=			(
							    """<s_name>John Doe</s_name><s_age>99</s_age><s_city>Atlanta</s_city>"""
							    """<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>"""
							    """<s_nicknames><s_nickname>Johnny</s_nickname>"""
							    """<sep/><s_nickname>JD</s_nickname></s_nicknames>"""
							)
							SCREAMING_SNAKE_CASE :				List[Any]		=			self.processor.tokenajson(lowerCamelCase_						)

							self.assertDictEqual(lowerCamelCase_      ,						lowerCamelCase_						)



