
'''simple docstring'''
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_video_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import VivitImageProcessor






class    UpperCAmelCase_				(	unittest.TestCase					):





 def __init__(    self ,       lowercase_ ,       lowercase_=7 ,       lowercase_=3 ,       lowercase_=10 ,       lowercase_=18 ,       lowercase_=30 ,       lowercase_=4_00 ,       lowercase_=True ,       lowercase_=None ,       lowercase_=True ,       lowercase_=[0.5, 0.5, 0.5] ,       lowercase_=[0.5, 0.5, 0.5] ,       lowercase_=None ,       ):
     snake_case_ :    List[str]     			=						size if size is not None else {"shortest_edge": 18}
     snake_case_ :    Optional[int]     			=						crop_size if crop_size is not None else {"height": 18, "width": 18}

     snake_case_ :    Optional[Any]     			=						parent
     snake_case_ :    List[Any]     			=						batch_size
     snake_case_ :    int     			=						num_channels
     snake_case_ :    List[Any]     			=						num_frames
     snake_case_ :    int     			=						image_size
     snake_case_ :    Tuple     			=						min_resolution
     snake_case_ :    Optional[int]     			=						max_resolution
     snake_case_ :    Optional[int]     			=						do_resize
     snake_case_ :    str     			=						size
     snake_case_ :    List[Any]     			=						do_normalize
     snake_case_ :    Optional[Any]     			=						image_mean
     snake_case_ :    Optional[int]     			=						image_std
     snake_case_ :    int     			=						crop_size





 def        snake_case__		(    self):
     return {
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_normalize": self.do_normalize,
         "do_resize": self.do_resize,
         "size": self.size,
         "crop_size": self.crop_size,
     }






@require_torch
@require_vision
class    UpperCAmelCase_				(	snake_case__    ,						unittest.TestCase					):
 UpperCAmelCase_		    =						VivitImageProcessor if is_vision_available() else None





 def        snake_case__		(    self):
     snake_case_ :    Any     			=						VivitImageProcessingTester(self)





 @property
 def        snake_case__		(    self):
     return self.image_processor_tester.prepare_image_processor_dict()





 def        snake_case__		(    self):
     snake_case_ :    Any     			=						self.image_processing_class(**self.image_processor_dict)
     self.assertTrue(hasattr(lowercase_ ,       "image_mean"))
     self.assertTrue(hasattr(lowercase_ ,       "image_std"))
     self.assertTrue(hasattr(lowercase_ ,       "do_normalize"))
     self.assertTrue(hasattr(lowercase_ ,       "do_resize"))
     self.assertTrue(hasattr(lowercase_ ,       "do_center_crop"))
     self.assertTrue(hasattr(lowercase_ ,       "size"))





 def        snake_case__		(    self):
     snake_case_ :    Dict     			=						self.image_processing_class.from_dict(self.image_processor_dict)
     self.assertEqual(image_processor.size ,       {"shortest_edge": 18})
     self.assertEqual(image_processor.crop_size ,       {"height": 18, "width": 18})

     snake_case_ :    Dict     			=						self.image_processing_class.from_dict(self.image_processor_dict ,       size=42 ,       crop_size=84)
     self.assertEqual(image_processor.size ,       {"shortest_edge": 42})
     self.assertEqual(image_processor.crop_size ,       {"height": 84, "width": 84})





 def        snake_case__		(    self):
     # Initialize image_processing
     snake_case_ :    Any     			=						self.image_processing_class(**self.image_processor_dict)
     # create random PIL videos
     snake_case_ :    Optional[Any]     			=						prepare_video_inputs(self.image_processor_tester ,       equal_resolution=lowercase_)
     for video in video_inputs:
         self.assertIsInstance(lowercase_ ,       lowercase_)
         self.assertIsInstance(video[0] ,       Image.Image)

     # Test not batched input
     snake_case_ :    List[Any]     			=						image_processing(video_inputs[0] ,       return_tensors="pt").pixel_values
     self.assertEqual(
         encoded_videos.shape ,       (
             1,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         ) ,       )

     # Test batched
     snake_case_ :    Optional[int]     			=						image_processing(lowercase_ ,       return_tensors="pt").pixel_values
     self.assertEqual(
         encoded_videos.shape ,       (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         ) ,       )





 def        snake_case__		(    self):
     # Initialize image_processing
     snake_case_ :    Any     			=						self.image_processing_class(**self.image_processor_dict)
     # create random numpy tensors
     snake_case_ :    Any     			=						prepare_video_inputs(self.image_processor_tester ,       equal_resolution=lowercase_ ,       numpify=lowercase_)
     for video in video_inputs:
         self.assertIsInstance(lowercase_ ,       lowercase_)
         self.assertIsInstance(video[0] ,       np.ndarray)

     # Test not batched input
     snake_case_ :    str     			=						image_processing(video_inputs[0] ,       return_tensors="pt").pixel_values
     self.assertEqual(
         encoded_videos.shape ,       (
             1,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         ) ,       )

     # Test batched
     snake_case_ :    Optional[Any]     			=						image_processing(lowercase_ ,       return_tensors="pt").pixel_values
     self.assertEqual(
         encoded_videos.shape ,       (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         ) ,       )





 def        snake_case__		(    self):
     # Initialize image_processing
     snake_case_ :    Tuple     			=						self.image_processing_class(**self.image_processor_dict)
     # create random PyTorch tensors
     snake_case_ :    Optional[Any]     			=						prepare_video_inputs(self.image_processor_tester ,       equal_resolution=lowercase_ ,       torchify=lowercase_)
     for video in video_inputs:
         self.assertIsInstance(lowercase_ ,       lowercase_)
         self.assertIsInstance(video[0] ,       torch.Tensor)

     # Test not batched input
     snake_case_ :    Union[str, Any]     			=						image_processing(video_inputs[0] ,       return_tensors="pt").pixel_values
     self.assertEqual(
         encoded_videos.shape ,       (
             1,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         ) ,       )

     # Test batched
     snake_case_ :    Optional[int]     			=						image_processing(lowercase_ ,       return_tensors="pt").pixel_values
     self.assertEqual(
         encoded_videos.shape ,       (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_frames,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.crop_size["height"],
             self.image_processor_tester.crop_size["width"],
         ) ,       )




'''simple docstring'''
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class    UpperCAmelCase_				(	snake_case__					):
 UpperCAmelCase_		    =						"""ClapFeatureExtractor"""
 UpperCAmelCase_		    =						("""RobertaTokenizer""", """RobertaTokenizerFast""")





 def __init__(    self ,       lowercase_ ,       lowercase_):
     super().__init__(lowercase_ ,       lowercase_)





 def __call__(    self ,       lowercase_=None ,       lowercase_=None ,       lowercase_=None ,       **lowercase_):
     snake_case_ :    Any     			=						kwargs.pop("sampling_rate" ,       lowercase_)

     if text is None and audios is None:
         raise ValueError("You have to specify either text or audios. Both cannot be none.")

     if text is not None:
         snake_case_ :    Optional[int]     			=						self.tokenizer(lowercase_ ,       return_tensors=lowercase_ ,       **lowercase_)

     if audios is not None:
         snake_case_ :    Any     			=						self.feature_extractor(
             lowercase_ ,       sampling_rate=lowercase_ ,       return_tensors=lowercase_ ,       **lowercase_)

     if text is not None and audios is not None:
         snake_case_ :    Dict     			=						audio_features.input_features
         return encoding
     elif text is not None:
         return encoding
     else:
         return BatchEncoding(data=dict(**lowercase_) ,       tensor_type=lowercase_)





 def        snake_case__		(    self ,       *lowercase_ ,       **lowercase_):
     return self.tokenizer.batch_decode(*lowercase_ ,       **lowercase_)





 def        snake_case__		(    self ,       *lowercase_ ,       **lowercase_):
     return self.tokenizer.decode(*lowercase_ ,       **lowercase_)





 @property
 def        snake_case__		(    self):
     snake_case_ :    Union[str, Any]     			=						self.tokenizer.model_input_names
     snake_case_ :    int     			=						self.feature_extractor.model_input_names
     return list(dict.fromkeys(tokenizer_input_names + feature_extractor_input_names))




