


'''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       lowercase_				(							self	)				->     Tuple:
         __lowerCamelCase   :	List[Any]								=		pipeline(
             task='zero-shot-audio-classification'			,     model='hf-internal-testing/tiny-clap-htsat-unfused'	)
         __lowerCamelCase   :	Union[str, Any]								=		load_dataset('ashraq/esc50'	)
         __lowerCamelCase   :	Union[str, Any]								=		dataset['train']['audio'][-1]['array']
         __lowerCamelCase   :	Tuple								=		audio_classifier(SCREAMING_SNAKE_CASE_			,     candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']	)
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE_	)			,     [{'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       lowercase_				(							self	)				->     Any:
         pass







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

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

         __lowerCamelCase   :	Union[str, Any]								=		audio_classifier([audio] * 5			,     candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']	)
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE_	)			,     [
                 [
                     {'score': 0.9_9_9, 'label': 'Sound of a dog'},
                     {'score': 0.0_0_1, 'label': 'Sound of vaccum cleaner'},
                 ],
             ]
             * 5			,     )
         __lowerCamelCase   :	Optional[Any]								=		audio_classifier(
             [audio] * 5			,     candidate_labels=['Sound of a dog', 'Sound of vaccum cleaner']			,     batch_size=5	)
         self.assertEqual(
             nested_simplify(SCREAMING_SNAKE_CASE_	)			,     [
                 [
                     {'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       lowercase_				(							self	)				->     Dict:
         pass










'''simple docstring'''



import numpy as np
from cva import destroyAllWindows, imread, imshow, waitKey





class    UpperCAmelCase_  :





    """simple docstring"""






    def __init__(							self			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_			,     SCREAMING_SNAKE_CASE_	)				->     int:
         if dst_width < 0 or dst_height < 0:
              raise ValueError('Destination width/height should be > 0'	)

         __lowerCamelCase   :	Dict								=		img
         __lowerCamelCase   :	Any								=		img.shape[1]
         __lowerCamelCase   :	Optional[int]								=		img.shape[0]
         __lowerCamelCase   :	Dict								=		dst_width
         __lowerCamelCase   :	str								=		dst_height

         __lowerCamelCase   :	Dict								=		self.src_w / self.dst_w
         __lowerCamelCase   :	List[Any]								=		self.src_h / self.dst_h

         __lowerCamelCase   :	Optional[int]								=		(
             np.ones((self.dst_h, self.dst_w, 3)			,     np.uinta	) * 2_55
         )







    def       lowercase_				(							self	)				->     List[Any]:
         for i in range(self.dst_h	):
              for j in range(self.dst_w	):
                   __lowerCamelCase   :	Union[str, Any]								=		self.img[self.get_y(SCREAMING_SNAKE_CASE_	)][self.get_x(SCREAMING_SNAKE_CASE_	)]







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_	)				->     int:
         return int(self.ratio_x * x	)







    def       lowercase_				(							self			,     SCREAMING_SNAKE_CASE_	)				->     int:
         return int(self.ratio_y * y	)


if __name__ == "__main__":
      A__						,					A__		:					Optional[Any]												=  800, 600
      A__		:					List[str]												=  imread("""image_data/lena.jpg""", 1)
      A__		:					List[Any]												=  NearestNeighbour(im, dst_w, dst_h)
      n.process()

      imshow(
          f'''Image resized from: {im.shape[1]}x{im.shape[0]} to {dst_w}x{dst_h}''', n.output
      )
      waitKey(0)
      destroyAllWindows()






