


"""simple docstring"""
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     :





											'''simple docstring'''

											@staticmethod
											def 		lowerCAmelCase       (				*UpperCAmelCase_							:      Dict		,       **UpperCAmelCase_							:      List[str]       )					->Any:



																		"""simple docstring"""



																		pass





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





							'''simple docstring'''

							@require_torch
							def 		lowerCAmelCase       (				self							:      Dict       )					->Optional[Any]:



														"""simple docstring"""



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

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



							@require_tf
							def 		lowerCAmelCase       (				self							:      Union[str, Any]       )					->Tuple:



														"""simple docstring"""



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

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

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



							@slow
							@require_torch
							def 		lowerCAmelCase       (				self							:      Any       )					->int:



														"""simple docstring"""



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

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

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



							@slow
							@require_tf
							def 		lowerCAmelCase       (				self							:      int       )					->Any:



														"""simple docstring"""



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

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







"""simple docstring"""
from ....configuration_utils import PretrainedConfig
from ....utils import logging


__SCREAMING_SNAKE_CASE							:    str		=    logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							:    str		=    {
    'speechbrain/m-ctc-t-large': 'https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json',
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}





class      __A     (snake_case__):





							'''simple docstring'''

							__lowercase:		Any							      =    """mctct"""



							def __init__(				self							:      Dict		,       UpperCAmelCase_							:      List[Any]=8_065		,       UpperCAmelCase_							:      Tuple=1_536		,       UpperCAmelCase_							:      Optional[Any]=36		,       UpperCAmelCase_							:      int=6_144		,       UpperCAmelCase_							:      Dict=4		,       UpperCAmelCase_							:      Any=384		,       UpperCAmelCase_							:      List[str]=920		,       UpperCAmelCase_							:      Any=1E-5		,       UpperCAmelCase_							:      Any=0.3		,       UpperCAmelCase_							:      Tuple="relu"		,       UpperCAmelCase_							:      Union[str, Any]=0.02		,       UpperCAmelCase_							:      Dict=0.3		,       UpperCAmelCase_							:      str=0.3		,       UpperCAmelCase_							:      Any=1		,       UpperCAmelCase_							:      Any=0		,       UpperCAmelCase_							:      int=2		,       UpperCAmelCase_							:      str=1		,       UpperCAmelCase_							:      Tuple=0.3		,       UpperCAmelCase_							:      Optional[Any]=1		,       UpperCAmelCase_							:      Optional[Any]=(7,)		,       UpperCAmelCase_							:      Optional[Any]=(3,)		,       UpperCAmelCase_							:      List[str]=80		,       UpperCAmelCase_							:      Tuple=1		,       UpperCAmelCase_							:      List[Any]=None		,       UpperCAmelCase_							:      List[str]="sum"		,       UpperCAmelCase_							:      Union[str, Any]=False		,       **UpperCAmelCase_							:      Any		,       )					->Dict:



														"""simple docstring"""



														super().__init__(**UpperCAmelCase_		,       pad_token_id=UpperCAmelCase_		,       bos_token_id=UpperCAmelCase_		,       eos_token_id=UpperCAmelCase_       )
														snake_case_           =		vocab_size
														snake_case_           =		hidden_size
														snake_case_           =		num_hidden_layers
														snake_case_           =		intermediate_size
														snake_case_           =		num_attention_heads
														snake_case_           =		attention_head_dim
														snake_case_           =		max_position_embeddings
														snake_case_           =		layer_norm_eps
														snake_case_           =		layerdrop
														snake_case_           =		hidden_act
														snake_case_           =		initializer_range
														snake_case_           =		hidden_dropout_prob
														snake_case_           =		attention_probs_dropout_prob
														snake_case_           =		pad_token_id
														snake_case_           =		bos_token_id
														snake_case_           =		eos_token_id
														snake_case_           =		conv_glu_dim
														snake_case_           =		conv_dropout
														snake_case_           =		num_conv_layers
														snake_case_           =		input_feat_per_channel
														snake_case_           =		input_channels
														snake_case_           =		conv_channels
														snake_case_           =		ctc_loss_reduction
														snake_case_           =		ctc_zero_infinity

														# prevents config testing fail with exporting to json
														snake_case_           =		list(UpperCAmelCase_       )
														snake_case_           =		list(UpperCAmelCase_       )

														if len(self.conv_kernel       ) != self.num_conv_layers:
																					raise ValueError(
																					    """Configuration for convolutional module is incorrect. """
																					    """It is required that `len(config.conv_kernel)` == `config.num_conv_layers` """
																					    F"""but is `len(config.conv_kernel) = {len(self.conv_kernel       )}`, """
																					    F"""`config.num_conv_layers = {self.num_conv_layers}`."""       )



