"""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						(    *lowerCamelCase__       :     Dict   ,**lowerCamelCase__       :     Dict      ):
															pass
@is_pipeline_test
@require_torch_or_tf
@require_vision
class     snake_case	(			unittest.TestCase    ):




					"""simple docstring"""

					snake_case__       =			MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
					snake_case__       =			TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING







					def 		__lowerCAmelCase						(    self       :     Optional[int]   ,lowerCamelCase__       :     Optional[int]   ,lowerCamelCase__       :     Tuple   ,lowerCamelCase__       :     int      ):
									UpperCAmelCase__					=							ImageClassificationPipeline(model=lowerCamelCase__   ,image_processor=lowerCamelCase__   ,top_k=2      )
									UpperCAmelCase__					=							[
									    Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'      ),
									    'http://images.cocodataset.org/val2017/000000039769.jpg',
									]
									return image_classifier, examples







					def 		__lowerCAmelCase						(    self       :     int   ,lowerCamelCase__       :     str   ,lowerCamelCase__       :     Optional[int]      ):
									UpperCAmelCase__					=							image_classifier('./tests/fixtures/tests_samples/COCO/000000039769.png'      )

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

									import datasets

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

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







					@require_torch
					def 		__lowerCAmelCase						(    self       :     Any      ):
									UpperCAmelCase__					=							'hf-internal-testing/tiny-random-vit'
									UpperCAmelCase__					=							pipeline('image-classification'   ,model=lowerCamelCase__      )

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

									UpperCAmelCase__					=							image_classifier(
									    [
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									    ]   ,top_k=2   ,)
									self.assertEqual(
									    nested_simplify(lowerCamelCase__   ,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 		__lowerCAmelCase						(    self       :     int      ):
									UpperCAmelCase__					=							'hf-internal-testing/tiny-random-vit'
									UpperCAmelCase__					=							pipeline('image-classification'   ,model=lowerCamelCase__   ,framework='tf'      )

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

									UpperCAmelCase__					=							image_classifier(
									    [
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									    ]   ,top_k=2   ,)
									self.assertEqual(
									    nested_simplify(lowerCamelCase__   ,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 		__lowerCAmelCase						(    self       :     Optional[int]      ):
									UpperCAmelCase__					=							PreTrainedTokenizer()

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

									self.assertIs(image_classifier.tokenizer   ,lowerCamelCase__      )







					@slow
					@require_torch
					def 		__lowerCAmelCase						(    self       :     int      ):
									# Perceiver is not tested by `run_pipeline_test` properly.
									# That is because the type of feature_extractor and model preprocessor need to be kept
									# in sync, which is not the case in the current design
									UpperCAmelCase__					=							pipeline('image-classification'   ,model='deepmind/vision-perceiver-conv'      )
									UpperCAmelCase__					=							image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'      )
									self.assertEqual(
									    nested_simplify(lowerCamelCase__   ,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'},
									    ]   ,)

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

									UpperCAmelCase__					=							pipeline('image-classification'   ,model='deepmind/vision-perceiver-learned'      )
									UpperCAmelCase__					=							image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'      )
									self.assertEqual(
									    nested_simplify(lowerCamelCase__   ,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"""






import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


lowerCAmelCase__  :  List[Any]											=     '\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'
class     snake_case	(			unittest.TestCase				,   __UpperCAmelCase    ):




					"""simple docstring"""

					def 		__lowerCAmelCase						(    self       :     Tuple      ):
									UpperCAmelCase__					=							load_tool('summarization'      )
									self.tool.setup()
									UpperCAmelCase__					=							load_tool('summarization'   ,remote=lowerCamelCase__      )







					def 		__lowerCAmelCase						(    self       :     Union[str, Any]      ):
									UpperCAmelCase__					=							self.tool(lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)







					def 		__lowerCAmelCase						(    self       :     Tuple      ):
									UpperCAmelCase__					=							self.remote_tool(lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)







					def 		__lowerCAmelCase						(    self       :     List[Any]      ):
									UpperCAmelCase__					=							self.tool(text=lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)







					def 		__lowerCAmelCase						(    self       :     Tuple      ):
									UpperCAmelCase__					=							self.remote_tool(text=lowerCamelCase__      )
									self.assertEqual(
									    lowerCamelCase__   ,'Hugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf. In March 2021, Hugging Face raised $40 million in a Series B funding round. On April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model. In 2022, the workshop concluded with the announcement of BLOOM.'   ,)



