'''simple docstring'''

import unittest

import numpy as np
import torch

from diffusers import ScoreSdeVePipeline, ScoreSdeVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()



class       UpperCAmelCase  (						unittest.TestCase ):





       '''simple docstring'''



       @property
       def _lowerCAmelCase(						self			)  ->  Optional[int]:
        torch.manual_seed(0			)
        lowercase__    :   Any						= UNetaDModel(
            block_out_channels=(32, 64)     ,       layers_per_block=2     ,       sample_size=32     ,       in_channels=3     ,       out_channels=3     ,       down_block_types=('''DownBlock2D''', '''AttnDownBlock2D''')     ,       up_block_types=('''AttnUpBlock2D''', '''UpBlock2D''')     ,       )
        return model


       def _lowerCAmelCase(						self			)  ->  str:
        lowercase__    :   Any						= self.dummy_uncond_unet
        lowercase__    :   Tuple						= ScoreSdeVeScheduler()

        lowercase__    :   Any						= ScoreSdeVePipeline(unet=__lowerCamelCase     ,       scheduler=__lowerCamelCase			)
        sde_ve.to(__lowerCamelCase			)
        sde_ve.set_progress_bar_config(disable=__lowerCamelCase			)

        lowercase__    :   List[str]						= torch.manual_seed(0			)
        lowercase__    :   Optional[Any]						= sde_ve(num_inference_steps=2     ,       output_type='''numpy'''     ,       generator=__lowerCamelCase			).images

        lowercase__    :   Any						= torch.manual_seed(0			)
        lowercase__    :   Union[str, Any]						= sde_ve(num_inference_steps=2     ,       output_type='''numpy'''     ,       generator=__lowerCamelCase     ,       return_dict=__lowerCamelCase			)[
            0
        ]

        lowercase__    :   List[Any]						= image[0, -3:, -3:, -1]
        lowercase__    :   Any						= image_from_tuple[0, -3:, -3:, -1]

        assert image.shape == (1, 32, 32, 3)
        lowercase__    :   int						= np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]			)

        assert np.abs(image_slice.flatten() - expected_slice			).max() < 1E-2
        assert np.abs(image_from_tuple_slice.flatten() - expected_slice			).max() < 1E-2



@slow
@require_torch
class       UpperCAmelCase  (						unittest.TestCase ):





       '''simple docstring'''



       def _lowerCAmelCase(						self			)  ->  Any:
        lowercase__    :   int						= '''google/ncsnpp-church-256'''
        lowercase__    :   Dict						= UNetaDModel.from_pretrained(__lowerCamelCase			)

        lowercase__    :   int						= ScoreSdeVeScheduler.from_pretrained(__lowerCamelCase			)

        lowercase__    :   List[str]						= ScoreSdeVePipeline(unet=__lowerCamelCase     ,       scheduler=__lowerCamelCase			)
        sde_ve.to(__lowerCamelCase			)
        sde_ve.set_progress_bar_config(disable=__lowerCamelCase			)

        lowercase__    :   List[Any]						= torch.manual_seed(0			)
        lowercase__    :   Optional[Any]						= sde_ve(num_inference_steps=10     ,       output_type='''numpy'''     ,       generator=__lowerCamelCase			).images

        lowercase__    :   str						= image[0, -3:, -3:, -1]

        assert image.shape == (1, 256, 256, 3)

        lowercase__    :   Any						= np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]			)

        assert np.abs(image_slice.flatten() - expected_slice			).max() < 1E-2


'''simple docstring'''

import unittest

from datasets import load_dataset

from transformers.pipelines import pipeline
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_torch, slow



@is_pipeline_test
@require_torch
class       UpperCAmelCase  (						unittest.TestCase ):





       '''simple docstring'''



       @require_torch
       def _lowerCAmelCase(						self			)  ->  int:
        lowercase__    :   str						= pipeline(
            task='''zero-shot-audio-classification'''     ,       model='''hf-internal-testing/tiny-clap-htsat-unfused'''			)
        lowercase__    :   Optional[Any]						= load_dataset('''ashraq/esc50'''			)
        lowercase__    :   Tuple						= dataset['''train''']['''audio'''][-1]['''array''']
        lowercase__    :   Optional[Any]						= audio_classifier(__lowerCAmelCase     ,       candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']			)
        self.assertEqual(
            nested_simplify(__lowerCAmelCase			)     ,       [{'''score''': 0.5_0_1, '''label''': '''Sound of a dog'''}, {'''score''': 0.4_9_9, '''label''': '''Sound of vaccum cleaner'''}]     ,       )

       @unittest.skip('''No models are available in TF'''			)
       def _lowerCAmelCase(						self			)  ->  str:
        pass

       @slow
       @require_torch
       def _lowerCAmelCase(						self			)  ->  Tuple:
        lowercase__    :   List[str]						= pipeline(
            task='''zero-shot-audio-classification'''     ,       model='''laion/clap-htsat-unfused'''     ,       )
        # This is an audio of a dog
        lowercase__    :   int						= load_dataset('''ashraq/esc50'''			)
        lowercase__    :   str						= dataset['''train''']['''audio'''][-1]['''array''']
        lowercase__    :   Any						= audio_classifier(__lowerCAmelCase     ,       candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']			)

        self.assertEqual(
            nested_simplify(__lowerCAmelCase			)     ,       [
                {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
            ]     ,       )

        lowercase__    :   Dict						= audio_classifier([audio] * 5     ,       candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']			)
        self.assertEqual(
            nested_simplify(__lowerCAmelCase			)     ,       [
                [
                    {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                    {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                ],
            ]
            * 5     ,       )
        lowercase__    :   Any						= audio_classifier(
            [audio] * 5     ,       candidate_labels=['''Sound of a dog''', '''Sound of vaccum cleaner''']     ,       batch_size=5			)
        self.assertEqual(
            nested_simplify(__lowerCAmelCase			)     ,       [
                [
                    {'''score''': 0.9_9_9, '''label''': '''Sound of a dog'''},
                    {'''score''': 0.0_0_1, '''label''': '''Sound of vaccum cleaner'''},
                ],
            ]
            * 5     ,       )


       @unittest.skip('''No models are available in TF'''			)
       def _lowerCAmelCase(						self			)  ->  Union[str, Any]:
        pass

