



'''simple docstring'''





import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin






class __A    (						A		):



 '''simple docstring'''







 __lowerCamelCase					: Union[str, Any]    = 'MCTCTFeatureExtractor'
 __lowerCamelCase					: List[Any]    = 'AutoTokenizer'



 def __init__(self				,     A				,     A )					->  Tuple:


      """simple docstring"""



      super().__init__(A				,     A )
      _a											=						self.feature_extractor
      _a											=						False



 def __call__(self				,     *A				,     **A )					->  str:


      """simple docstring"""



      if self._in_target_context_manager:
           return self.current_processor(*A				,     **A )

      if "raw_speech" in kwargs:
           warnings.warn('''Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead.''' )
           _a											=						kwargs.pop('''raw_speech''' )
      else:
           _a											=						kwargs.pop('''audio'''				,     A )
      _a											=						kwargs.pop('''sampling_rate'''				,     A )
      _a											=						kwargs.pop('''text'''				,     A )
      if len(A ) > 0:
           _a											=						args[0]
           _a											=						args[1:]

      if audio is None and text is None:
           raise ValueError('''You need to specify either an `audio` or `text` input to process.''' )

      if audio is not None:
           _a											=						self.feature_extractor(A				,     *A				,     sampling_rate=A				,     **A )
      if text is not None:
           _a											=						self.tokenizer(A				,     **A )

      if text is None:
           return inputs
      elif audio is None:
           return encodings
      else:
           _a											=						encodings['''input_ids''']
           return inputs



 def       a__						(self				,     *A				,     **A )					->  Dict:


      """simple docstring"""



      return self.tokenizer.batch_decode(*A				,     **A )



 def       a__						(self				,     *A				,     **A )					->  str:


      """simple docstring"""



      if self._in_target_context_manager:
           return self.current_processor.pad(*A				,     **A )

      _a											=						kwargs.pop('''input_features'''				,     A )
      _a											=						kwargs.pop('''labels'''				,     A )
      if len(A ) > 0:
           _a											=						args[0]
           _a											=						args[1:]

      if input_features is not None:
           _a											=						self.feature_extractor.pad(A				,     *A				,     **A )
      if labels is not None:
           _a											=						self.tokenizer.pad(A				,     **A )

      if labels is None:
           return input_features
      elif input_features is None:
           return labels
      else:
           _a											=						labels['''input_ids''']
           return input_features



 def       a__						(self				,     *A				,     **A )					->  int:


      """simple docstring"""



      return self.tokenizer.decode(*A				,     **A )



 @contextmanager
 def       a__						(self )					->  Dict:


      """simple docstring"""



      warnings.warn(
          '''`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '''
          '''labels by using the argument `text` of the regular `__call__` method (either in the same call as '''
          '''your audio inputs, or in a separate call.''' )
      _a											=						True
      _a											=						self.tokenizer
      yield
      _a											=						self.feature_extractor
      _a											=						False








'''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_image_inputs


if is_torch_available():
  import torch

if is_vision_available():
  from PIL import Image

  from transformers import MobileNetVaImageProcessor






class __A    (						unittest.TestCase		):



 '''simple docstring'''







 def __init__(self				,     A				,     A=7				,     A=3				,     A=18				,     A=30				,     A=400				,     A=True				,     A=None				,     A=True				,     A=None				,     )					->  Any:


      """simple docstring"""



      _a											=						size if size is not None else {'''shortest_edge''': 20}
      _a											=						crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
      _a											=						parent
      _a											=						batch_size
      _a											=						num_channels
      _a											=						image_size
      _a											=						min_resolution
      _a											=						max_resolution
      _a											=						do_resize
      _a											=						size
      _a											=						do_center_crop
      _a											=						crop_size



 def       a__						(self )					->  Optional[Any]:


      """simple docstring"""



      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
      }






@require_torch
@require_vision
class __A    (						A     ,     unittest.TestCase		):



 '''simple docstring'''







 __lowerCamelCase					: Tuple    = MobileNetVaImageProcessor if is_vision_available() else None



 def       a__						(self )					->  int:


      """simple docstring"""



      _a											=						MobileNetVaImageProcessingTester(self )



 @property
 def       a__						(self )					->  Optional[Any]:


      """simple docstring"""



      return self.image_processor_tester.prepare_image_processor_dict()



 def       a__						(self )					->  str:


      """simple docstring"""



      _a											=						self.image_processing_class(**self.image_processor_dict )
      self.assertTrue(hasattr(A				,     '''do_resize''' ) )
      self.assertTrue(hasattr(A				,     '''size''' ) )
      self.assertTrue(hasattr(A				,     '''do_center_crop''' ) )
      self.assertTrue(hasattr(A				,     '''crop_size''' ) )



 def       a__						(self )					->  Optional[int]:


      """simple docstring"""



      _a											=						self.image_processing_class.from_dict(self.image_processor_dict )
      self.assertEqual(image_processor.size				,     {'''shortest_edge''': 20} )
      self.assertEqual(image_processor.crop_size				,     {'''height''': 18, '''width''': 18} )

      _a											=						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       a__						(self )					->  Union[str, Any]:


      """simple docstring"""



      pass



 def       a__						(self )					->  Any:


      """simple docstring"""



      _a											=						self.image_processing_class(**self.image_processor_dict )
      # create random PIL images
      _a											=						prepare_image_inputs(self.image_processor_tester				,     equal_resolution=A )
      for image in image_inputs:
           self.assertIsInstance(A				,     Image.Image )

      # Test not batched input
      _a											=						image_processing(image_inputs[0]				,     return_tensors='''pt''' ).pixel_values
      self.assertEqual(
          encoded_images.shape				,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )				,     )

      # Test batched
      _a											=						image_processing(A				,     return_tensors='''pt''' ).pixel_values
      self.assertEqual(
          encoded_images.shape				,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )				,     )



 def       a__						(self )					->  Optional[int]:


      """simple docstring"""



      _a											=						self.image_processing_class(**self.image_processor_dict )
      # create random numpy tensors
      _a											=						prepare_image_inputs(self.image_processor_tester				,     equal_resolution=A				,     numpify=A )
      for image in image_inputs:
           self.assertIsInstance(A				,     np.ndarray )

      # Test not batched input
      _a											=						image_processing(image_inputs[0]				,     return_tensors='''pt''' ).pixel_values
      self.assertEqual(
          encoded_images.shape				,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )				,     )

      # Test batched
      _a											=						image_processing(A				,     return_tensors='''pt''' ).pixel_values
      self.assertEqual(
          encoded_images.shape				,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )				,     )



 def       a__						(self )					->  Optional[Any]:


      """simple docstring"""



      _a											=						self.image_processing_class(**self.image_processor_dict )
      # create random PyTorch tensors
      _a											=						prepare_image_inputs(self.image_processor_tester				,     equal_resolution=A				,     torchify=A )
      for image in image_inputs:
           self.assertIsInstance(A				,     torch.Tensor )

      # Test not batched input
      _a											=						image_processing(image_inputs[0]				,     return_tensors='''pt''' ).pixel_values
      self.assertEqual(
          encoded_images.shape				,     (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )				,     )

      # Test batched
      _a											=						image_processing(A				,     return_tensors='''pt''' ).pixel_values
      self.assertEqual(
          encoded_images.shape				,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['''height'''],
              self.image_processor_tester.crop_size['''width'''],
          )				,     )



