





import unittest

from transformers import (
    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    PreTrainedTokenizer,
    is_vision_available,
)
from transformers.pipelines import ImageClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
						from PIL import Image
else:




						class 				_a		:






										@staticmethod
										def        snake_case			(				*lowerCAmelCase__	:					Dict,				**lowerCAmelCase__	:					Union[str, Any]							)			->   str:




																'''simple docstring'''



																pass




@is_pipeline_test
@require_torch_or_tf
@require_vision
class 				_a		(   unittest.TestCase       ):
				UpperCamelCase			=					MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
				UpperCamelCase			=					TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING






				def        snake_case			(				self	:					List[str],				lowerCAmelCase__	:					List[str],				lowerCAmelCase__	:					List[Any],				lowerCAmelCase__	:					Optional[Any]							)			->   Any:




										'''simple docstring'''



										_UpperCamelCase    :      Any						     =					ImageClassificationPipeline(model=SCREAMING_SNAKE_CASE_,				image_processor=SCREAMING_SNAKE_CASE_,				top_k=2							)
										_UpperCamelCase    :      List[str]						     =					[
										    Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							),
										    '''http://images.cocodataset.org/val2017/000000039769.jpg''',
										]
										return image_classifier, examples






				def        snake_case			(				self	:					List[str],				lowerCAmelCase__	:					int,				lowerCAmelCase__	:					Any							)			->   Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase    :      Any						     =					image_classifier('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)

										self.assertEqual(
										    SCREAMING_SNAKE_CASE_,				[
										        {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										        {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										    ],				)

										import datasets

										_UpperCamelCase    :      Optional[int]						     =					datasets.load_dataset('''hf-internal-testing/fixtures_image_utils''',				'''image''',				split='''test'''							)

										# Accepts URL + PIL.Image + lists
										_UpperCamelCase    :      Any						     =					image_classifier(
										    [
										        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'''],
										    ]							)
										self.assertEqual(
										    SCREAMING_SNAKE_CASE_,				[
										        [
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										        ],
										        [
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										        ],
										        [
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										        ],
										        [
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										        ],
										        [
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										            {'''score''': ANY(SCREAMING_SNAKE_CASE_							), '''label''': ANY(SCREAMING_SNAKE_CASE_							)},
										        ],
										    ],				)






				@require_torch
				def        snake_case			(				self	:					List[Any]							)			->   Dict:




										'''simple docstring'''



										_UpperCamelCase    :      Tuple						     =					'''hf-internal-testing/tiny-random-vit'''
										_UpperCamelCase    :      Union[str, Any]						     =					pipeline('''image-classification''',				model=SCREAMING_SNAKE_CASE_							)

										_UpperCamelCase    :      List[Any]						     =					image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
										self.assertEqual(
										    nested_simplify(SCREAMING_SNAKE_CASE_,				decimals=4							),				[{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],				)

										_UpperCamelCase    :      Optional[Any]						     =					image_classifier(
										    [
										        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
										        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
										    ],				top_k=2,				)
										self.assertEqual(
										    nested_simplify(SCREAMING_SNAKE_CASE_,				decimals=4							),				[
										        [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
										        [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
										    ],				)






				@require_tf
				def        snake_case			(				self	:					List[str]							)			->   str:




										'''simple docstring'''



										_UpperCamelCase    :      Optional[Any]						     =					'''hf-internal-testing/tiny-random-vit'''
										_UpperCamelCase    :      Optional[Any]						     =					pipeline('''image-classification''',				model=SCREAMING_SNAKE_CASE_,				framework='''tf'''							)

										_UpperCamelCase    :      List[Any]						     =					image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
										self.assertEqual(
										    nested_simplify(SCREAMING_SNAKE_CASE_,				decimals=4							),				[{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],				)

										_UpperCamelCase    :      List[str]						     =					image_classifier(
										    [
										        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
										        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
										    ],				top_k=2,				)
										self.assertEqual(
										    nested_simplify(SCREAMING_SNAKE_CASE_,				decimals=4							),				[
										        [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
										        [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
										    ],				)






				def        snake_case			(				self	:					List[str]							)			->   Tuple:




										'''simple docstring'''



										_UpperCamelCase    :      str						     =					PreTrainedTokenizer()

										# Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
										_UpperCamelCase    :      Optional[int]						     =					pipeline(
										    '''image-classification''',				model='''hf-internal-testing/tiny-random-vit''',				tokenizer=SCREAMING_SNAKE_CASE_							)

										self.assertIs(image_classifier.tokenizer,				SCREAMING_SNAKE_CASE_							)






				@slow
				@require_torch
				def        snake_case			(				self	:					List[str]							)			->   str:




										'''simple docstring'''



										_UpperCamelCase    :      str						     =					pipeline('''image-classification''',				model='''deepmind/vision-perceiver-conv'''							)
										_UpperCamelCase    :      int						     =					image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
										self.assertEqual(
										    nested_simplify(SCREAMING_SNAKE_CASE_,				decimals=4							),				[
										        {'''score''': 0.4_385, '''label''': '''tabby, tabby cat'''},
										        {'''score''': 0.321, '''label''': '''tiger cat'''},
										        {'''score''': 0.0_502, '''label''': '''Egyptian cat'''},
										        {'''score''': 0.0_137, '''label''': '''crib, cot'''},
										        {'''score''': 0.007, '''label''': '''radiator'''},
										    ],				)

										_UpperCamelCase    :      int						     =					pipeline('''image-classification''',				model='''deepmind/vision-perceiver-fourier'''							)
										_UpperCamelCase    :      List[str]						     =					image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
										self.assertEqual(
										    nested_simplify(SCREAMING_SNAKE_CASE_,				decimals=4							),				[
										        {'''score''': 0.5_658, '''label''': '''tabby, tabby cat'''},
										        {'''score''': 0.1_309, '''label''': '''tiger cat'''},
										        {'''score''': 0.0_722, '''label''': '''Egyptian cat'''},
										        {'''score''': 0.0_707, '''label''': '''remote control, remote'''},
										        {'''score''': 0.0_082, '''label''': '''computer keyboard, keypad'''},
										    ],				)

										_UpperCamelCase    :      str						     =					pipeline('''image-classification''',				model='''deepmind/vision-perceiver-learned'''							)
										_UpperCamelCase    :      Dict						     =					image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
										self.assertEqual(
										    nested_simplify(SCREAMING_SNAKE_CASE_,				decimals=4							),				[
										        {'''score''': 0.3_022, '''label''': '''tabby, tabby cat'''},
										        {'''score''': 0.2_362, '''label''': '''Egyptian cat'''},
										        {'''score''': 0.1_856, '''label''': '''tiger cat'''},
										        {'''score''': 0.0_324, '''label''': '''remote control, remote'''},
										        {'''score''': 0.0_096, '''label''': '''quilt, comforter, comfort, puff'''},
										    ],				)










"""simple docstring"""




def  a_       (							_lowercase     ):
						_UpperCamelCase    :      str						     =					len(_lowercase     )

						# Set the gap value to be decreased by a factor of 1.3
						# after each iteration
						_UpperCamelCase    :      str						     =					1.3

						# Continue sorting until the gap is 1
						while gap > 1:
												# Decrease the gap value
												_UpperCamelCase    :      Union[str, Any]						     =					int(gap / shrink     )

												# Sort the elements using insertion sort
												for i in range(_lowercase ,		len(_lowercase     )     ):
																		_UpperCamelCase    :      Optional[Any]						     =					collection[i]
																		_UpperCamelCase    :      int						     =					i
																		while j >= gap and collection[j - gap] > temp:
																								_UpperCamelCase    :      List[str]						     =					collection[j - gap]
																								j -= gap
																		_UpperCamelCase    :      Union[str, Any]						     =					temp

						return collection


if __name__ == "__main__":
						import doctest

						doctest.testmod()



