




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     A__						(		*__snake_case   :int    , **__snake_case   :str ):
																	'''simple docstring'''

																	pass




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

						@require_torch
						def     A__						(		self   :Tuple ):
										'''simple docstring'''

										__magic_name__	:	List[str]								=pipeline(
										    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""    , )
										__magic_name__	:	Optional[Any]								=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
										__magic_name__	:	Optional[int]								=image_classifier(__snake_case    , 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(__snake_case )    , [
										        [{"""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"""}],
										    ]    , )

										__magic_name__	:	List[str]								=image_classifier([image] * 5    , candidate_labels=["""A""", """B""", """C"""]    , batch_size=2 )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										    ]    , )

						@require_tf
						def     A__						(		self   :Optional[Any] ):
										'''simple docstring'''

										__magic_name__	:	Dict								=pipeline(
										    model="""hf-internal-testing/tiny-random-clip-zero-shot-image-classification"""    , framework="""tf""" )
										__magic_name__	:	Tuple								=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
										__magic_name__	:	int								=image_classifier(__snake_case    , candidate_labels=["""a""", """b""", """c"""] )

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

										__magic_name__	:	str								=image_classifier([image] * 5    , candidate_labels=["""A""", """B""", """C"""]    , batch_size=2 )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										        [
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										            {"""score""": 0.333, """label""": ANY(__snake_case )},
										        ],
										    ]    , )

						@slow
						@require_torch
						def     A__						(		self   :int ):
										'''simple docstring'''

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

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

										__magic_name__	:	List[str]								=image_classifier([image] * 5    , candidate_labels=["""cat""", """plane""", """remote"""]    , batch_size=2 )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        [
										            {"""score""": 0.511, """label""": """remote"""},
										            {"""score""": 0.485, """label""": """cat"""},
										            {"""score""": 0.004, """label""": """plane"""},
										        ],
										    ]
										    * 5    , )


						@slow
						@require_tf
						def     A__						(		self   :str ):
										'''simple docstring'''

										__magic_name__	:	Optional[Any]								=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
										__magic_name__	:	List[str]								=Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png""" )
										__magic_name__	:	Any								=image_classifier(__snake_case    , candidate_labels=["""cat""", """plane""", """remote"""] )
										self.assertEqual(
										    nested_simplify(__snake_case )    , [
										        {"""score""": 0.511, """label""": """remote"""},
										        {"""score""": 0.485, """label""": """cat"""},
										        {"""score""": 0.004, """label""": """plane"""},
										    ]    , )

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










import inspect
import warnings
from typing import Any, Dict, Optional, Union

from packaging import version




def 		lowerCAmelCase_   (	*lowerCamelCase	,     lowerCamelCase = None	,     lowerCamelCase=True	,     lowerCamelCase=2   ):
				from .. import __version__

				__magic_name__	:	Optional[int]								=take_from
				__magic_name__	:	Tuple								=()
				if not isinstance(args[0]	,     lowerCamelCase   ):
								__magic_name__	:	List[Any]								=(args,)

				for attribute, version_name, message in args:
								if version.parse(version.parse(lowerCamelCase   ).base_version   ) >= version.parse(lowerCamelCase   ):
												raise ValueError(
												    F"The deprecation tuple {(attribute, version_name, message)} should be removed since diffusers'"
												    F" version {__version__} is >= {version_name}"   )

								__magic_name__	:	List[str]								=None
								if isinstance(lowerCamelCase	,     lowerCamelCase   ) and attribute in deprecated_kwargs:
												values += (deprecated_kwargs.pop(lowerCamelCase   ),)
												__magic_name__	:	List[str]								=F"The `{attribute}` argument is deprecated and will be removed in version {version_name}."
								elif hasattr(lowerCamelCase	,     lowerCamelCase   ):
												values += (getattr(lowerCamelCase	,     lowerCamelCase   ),)
												__magic_name__	:	List[str]								=F"The `{attribute}` attribute is deprecated and will be removed in version {version_name}."
								elif deprecated_kwargs is None:
												__magic_name__	:	List[str]								=F"`{attribute}` is deprecated and will be removed in version {version_name}."

								if warning is not None:
												__magic_name__	:	List[Any]								=warning + """ """ if standard_warn else """"""
												warnings.warn(warning + message	,     lowerCamelCase	,     stacklevel=lowerCamelCase   )

				if isinstance(lowerCamelCase	,     lowerCamelCase   ) and len(lowerCamelCase   ) > 0:
								__magic_name__	:	List[Any]								=inspect.getouterframes(inspect.currentframe()   )[1]
								__magic_name__	:	Optional[int]								=call_frame.filename
								__magic_name__	:	Tuple								=call_frame.lineno
								__magic_name__	:	str								=call_frame.function
								__magic_name__				, __magic_name__	:	Optional[int]								=next(iter(deprecated_kwargs.items()   )   )
								raise TypeError(F"{function} in {filename} line {line_number-1} got an unexpected keyword argument `{key}`"   )

				if len(lowerCamelCase   ) == 0:
								return
				elif len(lowerCamelCase   ) == 1:
								return values[0]
				return values




