






"""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 							_SCREAMING_SNAKE_CASE    :





								"""simple docstring"""





								@staticmethod
								def 			lowercase		( *__A:  Tuple					,		**__A:  List[Any]     ):

													'''simple docstring'''

													pass







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





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE     =MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
							_SCREAMING_SNAKE_CASE     =TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING




							def 			lowercase		( self:  str					,		__A:  Dict					,		__A:  Optional[Any]					,		__A:  List[Any]     ):

												'''simple docstring'''

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




							def 			lowercase		( self:  Dict					,		__A:  str					,		__A:  Dict     ):

												'''simple docstring'''

												a__ 							=	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

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

												# Accepts URL + PIL.Image + lists
												a__ 							=	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 			lowercase		( self:  Any     ):

												'''simple docstring'''

												a__ 							=	'''hf-internal-testing/tiny-random-vit'''
												a__ 							=	pipeline('''image-classification'''					,		model=__A     )

												a__ 							=	image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''     )
												self.assertEqual(
												    nested_simplify(__A					,		decimals=4     )					,		[{'''label''': '''LABEL_1''', '''score''': 0.5_7_4}, {'''label''': '''LABEL_0''', '''score''': 0.4_2_6}]					,		)

												a__ 							=	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.5_7_4}, {'''label''': '''LABEL_0''', '''score''': 0.4_2_6}],
												        [{'''label''': '''LABEL_1''', '''score''': 0.5_7_4}, {'''label''': '''LABEL_0''', '''score''': 0.4_2_6}],
												    ]					,		)




							@require_tf
							def 			lowercase		( self:  Optional[Any]     ):

												'''simple docstring'''

												a__ 							=	'''hf-internal-testing/tiny-random-vit'''
												a__ 							=	pipeline('''image-classification'''					,		model=__A					,		framework='''tf'''     )

												a__ 							=	image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''     )
												self.assertEqual(
												    nested_simplify(__A					,		decimals=4     )					,		[{'''label''': '''LABEL_1''', '''score''': 0.5_7_4}, {'''label''': '''LABEL_0''', '''score''': 0.4_2_6}]					,		)

												a__ 							=	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.5_7_4}, {'''label''': '''LABEL_0''', '''score''': 0.4_2_6}],
												        [{'''label''': '''LABEL_1''', '''score''': 0.5_7_4}, {'''label''': '''LABEL_0''', '''score''': 0.4_2_6}],
												    ]					,		)




							def 			lowercase		( self:  Optional[Any]     ):

												'''simple docstring'''

												a__ 							=	PreTrainedTokenizer()

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

												self.assertIs(image_classifier.tokenizer					,		__A     )





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

												'''simple docstring'''

												a__ 							=	pipeline('''image-classification'''					,		model='''deepmind/vision-perceiver-conv'''     )
												a__ 							=	image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''     )
												self.assertEqual(
												    nested_simplify(__A					,		decimals=4     )					,		[
												        {'''score''': 0.4_3_8_5, '''label''': '''tabby, tabby cat'''},
												        {'''score''': 0.3_2_1, '''label''': '''tiger cat'''},
												        {'''score''': 0.0_5_0_2, '''label''': '''Egyptian cat'''},
												        {'''score''': 0.0_1_3_7, '''label''': '''crib, cot'''},
												        {'''score''': 0.0_0_7, '''label''': '''radiator'''},
												    ]					,		)

												a__ 							=	pipeline('''image-classification'''					,		model='''deepmind/vision-perceiver-fourier'''     )
												a__ 							=	image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''     )
												self.assertEqual(
												    nested_simplify(__A					,		decimals=4     )					,		[
												        {'''score''': 0.5_6_5_8, '''label''': '''tabby, tabby cat'''},
												        {'''score''': 0.1_3_0_9, '''label''': '''tiger cat'''},
												        {'''score''': 0.0_7_2_2, '''label''': '''Egyptian cat'''},
												        {'''score''': 0.0_7_0_7, '''label''': '''remote control, remote'''},
												        {'''score''': 0.0_0_8_2, '''label''': '''computer keyboard, keypad'''},
												    ]					,		)

												a__ 							=	pipeline('''image-classification'''					,		model='''deepmind/vision-perceiver-learned'''     )
												a__ 							=	image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''     )
												self.assertEqual(
												    nested_simplify(__A					,		decimals=4     )					,		[
												        {'''score''': 0.3_0_2_2, '''label''': '''tabby, tabby cat'''},
												        {'''score''': 0.2_3_6_2, '''label''': '''Egyptian cat'''},
												        {'''score''': 0.1_8_5_6, '''label''': '''tiger cat'''},
												        {'''score''': 0.0_3_2_4, '''label''': '''remote control, remote'''},
												        {'''score''': 0.0_0_9_6, '''label''': '''quilt, comforter, comfort, puff'''},
												    ]					,		)










"""simple docstring"""







from ...configuration_utils import PretrainedConfig
from ...utils import logging


__a							:						Union[str, Any]   							=			logging.get_logger(__name__)

__a							:						Optional[Any]   							=			{
    'tau/splinter-base': 'https://huggingface.co/tau/splinter-base/resolve/main/config.json',
    'tau/splinter-base-qass': 'https://huggingface.co/tau/splinter-base-qass/resolve/main/config.json',
    'tau/splinter-large': 'https://huggingface.co/tau/splinter-large/resolve/main/config.json',
    'tau/splinter-large-qass': 'https://huggingface.co/tau/splinter-large-qass/resolve/main/config.json',
    # See all Splinter models at https://huggingface.co/models?filter=splinter
}







class 							_SCREAMING_SNAKE_CASE    (	__snake_case				):





							"""simple docstring"""





							_SCREAMING_SNAKE_CASE     ='splinter'




							def __init__( self:  Dict					,		__A:  List[Any]=30522					,		__A:  str=768					,		__A:  int=12					,		__A:  str=12					,		__A:  Tuple=3072					,		__A:  Dict="gelu"					,		__A:  Optional[int]=0.1					,		__A:  List[str]=0.1					,		__A:  str=512					,		__A:  List[Any]=2					,		__A:  Any=0.0_2					,		__A:  Any=1e-12					,		__A:  Tuple=True					,		__A:  List[Any]=0					,		__A:  List[str]=104					,		**__A:  Union[str, Any]					,		):

												'''simple docstring'''

												super().__init__(pad_token_id=__A					,		**__A     )

												a__ 							=	vocab_size
												a__ 							=	max_position_embeddings
												a__ 							=	hidden_size
												a__ 							=	num_hidden_layers
												a__ 							=	num_attention_heads
												a__ 							=	intermediate_size
												a__ 							=	hidden_act
												a__ 							=	hidden_dropout_prob
												a__ 							=	attention_probs_dropout_prob
												a__ 							=	initializer_range
												a__ 							=	type_vocab_size
												a__ 							=	layer_norm_eps
												a__ 							=	use_cache
												a__ 							=	question_token_id


