
'''simple docstring'''
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      snake_case__    :







								"""simple docstring"""

								@staticmethod
								def 	lowerCAmelCase							(	*UpperCamelCase__							:       List[Any]   ,     **UpperCamelCase__							:       Optional[int]	)		->       Optional[Any]:






										"""simple docstring"""







										pass






@is_pipeline_test
@require_torch_or_tf
@require_vision
class      snake_case__    (	unittest.TestCase ):







		"""simple docstring"""

		lowerCamelCase							=		MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
		lowerCamelCase							=		TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING



		def 	lowerCAmelCase							(	self							:       List[Any]   ,     UpperCamelCase__							:       List[str]   ,     UpperCamelCase__							:       Union[str, Any]   ,     UpperCamelCase__							:       Tuple	)		->       Optional[Any]:






				"""simple docstring"""







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



		def 	lowerCAmelCase							(	self							:       Optional[int]   ,     UpperCamelCase__							:       Optional[int]   ,     UpperCamelCase__							:       Optional[Any]	)		->       Dict:






				"""simple docstring"""







				snake_case   :    int			       =		image_classifier('''./tests/fixtures/tests_samples/COCO/000000039769.png'''	)

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

				import datasets

				snake_case   :    Any			       =		datasets.load_dataset('''hf-internal-testing/fixtures_image_utils'''   ,     '''image'''   ,     split='''test'''	)

				# Accepts URL + PIL.Image + lists
				snake_case   :    int			       =		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(
				    __A   ,     [
				        [
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				        ],
				        [
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				        ],
				        [
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				        ],
				        [
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				        ],
				        [
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				            {'''score''': ANY(__A	), '''label''': ANY(__A	)},
				        ],
				    ]   ,     )



		@require_torch
		def 	lowerCAmelCase							(	self							:       Dict	)		->       Dict:






				"""simple docstring"""







				snake_case   :    Union[str, Any]			       =		'''hf-internal-testing/tiny-random-vit'''
				snake_case   :    List[str]			       =		pipeline('''image-classification'''   ,     model=__A	)

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

				snake_case   :    Dict			       =		image_classifier(
				    [
				        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
				        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
				    ]   ,     top_k=2   ,     )
				self.assertEqual(
				    nested_simplify(__A   ,     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 	lowerCAmelCase							(	self							:       Tuple	)		->       Union[str, Any]:






				"""simple docstring"""







				snake_case   :    Union[str, Any]			       =		'''hf-internal-testing/tiny-random-vit'''
				snake_case   :    Union[str, Any]			       =		pipeline('''image-classification'''   ,     model=__A   ,     framework='''tf'''	)

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

				snake_case   :    Tuple			       =		image_classifier(
				    [
				        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
				        '''http://images.cocodataset.org/val2017/000000039769.jpg''',
				    ]   ,     top_k=2   ,     )
				self.assertEqual(
				    nested_simplify(__A   ,     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 	lowerCAmelCase							(	self							:       Tuple	)		->       Any:






				"""simple docstring"""







				snake_case   :    Optional[Any]			       =		PreTrainedTokenizer()

				# Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
				snake_case   :    Dict			       =		pipeline(
				    '''image-classification'''   ,     model='''hf-internal-testing/tiny-random-vit'''   ,     tokenizer=__A	)

				self.assertIs(image_classifier.tokenizer   ,     __A	)



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






				"""simple docstring"""







				snake_case   :    List[str]			       =		pipeline('''image-classification'''   ,     model='''deepmind/vision-perceiver-conv'''	)
				snake_case   :    Tuple			       =		image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''	)
				self.assertEqual(
				    nested_simplify(__A   ,     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'''},
				    ]   ,     )

				snake_case   :    List[Any]			       =		pipeline('''image-classification'''   ,     model='''deepmind/vision-perceiver-fourier'''	)
				snake_case   :    int			       =		image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''	)
				self.assertEqual(
				    nested_simplify(__A   ,     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'''},
				    ]   ,     )

				snake_case   :    Union[str, Any]			       =		pipeline('''image-classification'''   ,     model='''deepmind/vision-perceiver-learned'''	)
				snake_case   :    Optional[int]			       =		image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''	)
				self.assertEqual(
				    nested_simplify(__A   ,     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'''},
				    ]   ,     )









from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
)


_lowerCamelCase       =	{
    'configuration_gptsan_japanese': ['GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'GPTSanJapaneseConfig'],
    'tokenization_gptsan_japanese': ['GPTSanJapaneseTokenizer'],
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	_lowerCamelCase       =	[
	    'GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'GPTSanJapaneseForConditionalGeneration',
	    'GPTSanJapaneseModel',
	    'GPTSanJapanesePreTrainedModel',
	]
	_lowerCamelCase       =	[
	    'GPTSanJapaneseTokenizer',
	]


if TYPE_CHECKING:
	from .configuration_gptsan_japanese import GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTSanJapaneseConfig
	from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_gptsan_japanese import (
		    GPTSAN_JAPANESE_PRETRAINED_MODEL_ARCHIVE_LIST,
		    GPTSanJapaneseForConditionalGeneration,
		    GPTSanJapaneseModel,
		    GPTSanJapanesePreTrainedModel,
		)
		from .tokenization_gptsan_japanese import GPTSanJapaneseTokenizer


else:
	import sys

	_lowerCamelCase       =	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)