

'''simple docstring'''



import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin
from .feature_extraction_wavaveca import WavaVecaFeatureExtractor
from .tokenization_wavaveca import WavaVecaCTCTokenizer







class 		lowerCAmelCase__  ( a   ):



 """simple docstring"""



 lowerCAmelCase__       = "Wav2Vec2FeatureExtractor"
 lowerCAmelCase__       = "AutoTokenizer"
 def __init__(						self   :			Tuple   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any]   ,				__SCREAMING_SNAKE_CASE   :			Dict     )    ->					Any:


      """simple docstring"""




      super().__init__(__SCREAMING_SNAKE_CASE   ,				__SCREAMING_SNAKE_CASE     )
      __SCREAMING_SNAKE_CASE      = self.feature_extractor
      __SCREAMING_SNAKE_CASE      = False
 @classmethod
 def  UpperCAmelCase__						(						cls   :			List[Any]   ,				__SCREAMING_SNAKE_CASE   :			Tuple   ,				**__SCREAMING_SNAKE_CASE   :			Any     )    ->					Any:


      """simple docstring"""




      try:
           return super().from_pretrained(__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
      except OSError:
           warnings.warn(
               f'Loading a tokenizer inside {cls.__name__} from a config that does not'
               """ include a `tokenizer_class` attribute is deprecated and will be """
               """removed in v5. Please add `'tokenizer_class': 'Wav2Vec2CTCTokenizer'`"""
               """ attribute to either your `config.json` or `tokenizer_config.json` """
               """file to suppress this warning: """   ,				__SCREAMING_SNAKE_CASE   ,				)

           __SCREAMING_SNAKE_CASE      = WavaVecaFeatureExtractor.from_pretrained(__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
           __SCREAMING_SNAKE_CASE      = WavaVecaCTCTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )

           return cls(feature_extractor=__SCREAMING_SNAKE_CASE   ,				tokenizer=__SCREAMING_SNAKE_CASE     )
 def __call__(						self   :			Tuple   ,				*__SCREAMING_SNAKE_CASE   :			Optional[int]   ,				**__SCREAMING_SNAKE_CASE   :			Tuple     )    ->					Any:


      """simple docstring"""




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

      if "raw_speech" in kwargs:
           warnings.warn("""Using `raw_speech` as a keyword argument is deprecated. Use `audio` instead."""     )
           __SCREAMING_SNAKE_CASE      = kwargs.pop("""raw_speech"""     )
      else:
           __SCREAMING_SNAKE_CASE      = kwargs.pop("""audio"""   ,				__SCREAMING_SNAKE_CASE     )
      __SCREAMING_SNAKE_CASE      = kwargs.pop("""sampling_rate"""   ,				__SCREAMING_SNAKE_CASE     )
      __SCREAMING_SNAKE_CASE      = kwargs.pop("""text"""   ,				__SCREAMING_SNAKE_CASE     )
      if len(__SCREAMING_SNAKE_CASE     ) > 0:
           __SCREAMING_SNAKE_CASE      = args[0]
           __SCREAMING_SNAKE_CASE      = 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:
           __SCREAMING_SNAKE_CASE      = self.feature_extractor(__SCREAMING_SNAKE_CASE   ,				*__SCREAMING_SNAKE_CASE   ,				sampling_rate=__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
      if text is not None:
           __SCREAMING_SNAKE_CASE      = self.tokenizer(__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )

      if text is None:
           return inputs
      elif audio is None:
           return encodings
      else:
           __SCREAMING_SNAKE_CASE      = encodings["""input_ids"""]
           return inputs
 def  UpperCAmelCase__						(						self   :			List[str]   ,				*__SCREAMING_SNAKE_CASE   :			Dict   ,				**__SCREAMING_SNAKE_CASE   :			str     )    ->					str:


      """simple docstring"""




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

      __SCREAMING_SNAKE_CASE      = kwargs.pop("""input_features"""   ,				__SCREAMING_SNAKE_CASE     )
      __SCREAMING_SNAKE_CASE      = kwargs.pop("""labels"""   ,				__SCREAMING_SNAKE_CASE     )
      if len(__SCREAMING_SNAKE_CASE     ) > 0:
           __SCREAMING_SNAKE_CASE      = args[0]
           __SCREAMING_SNAKE_CASE      = args[1:]

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

      if labels is None:
           return input_features
      elif input_features is None:
           return labels
      else:
           __SCREAMING_SNAKE_CASE      = labels["""input_ids"""]
           return input_features
 def  UpperCAmelCase__						(						self   :			str   ,				*__SCREAMING_SNAKE_CASE   :			str   ,				**__SCREAMING_SNAKE_CASE   :			int     )    ->					List[str]:


      """simple docstring"""




      return self.tokenizer.batch_decode(*__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
 def  UpperCAmelCase__						(						self   :			List[str]   ,				*__SCREAMING_SNAKE_CASE   :			Optional[int]   ,				**__SCREAMING_SNAKE_CASE   :			Any     )    ->					Optional[Any]:


      """simple docstring"""




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


 @contextmanager
 def  UpperCAmelCase__						(						self   :			int     )    ->					Union[str, Any]:


      """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."""     )
      __SCREAMING_SNAKE_CASE      = True
      __SCREAMING_SNAKE_CASE      = self.tokenizer
      yield
      __SCREAMING_SNAKE_CASE      = self.feature_extractor
      __SCREAMING_SNAKE_CASE      = False









'''simple docstring'''



import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding







class 		lowerCAmelCase__  ( a   ):



 """simple docstring"""



 lowerCAmelCase__       = ["image_processor", "tokenizer"]
 lowerCAmelCase__       = "CLIPImageProcessor"
 lowerCAmelCase__       = ("XLMRobertaTokenizer", "XLMRobertaTokenizerFast")
 def __init__(						self   :			Optional[Any]   ,				__SCREAMING_SNAKE_CASE   :			Any=None   ,				__SCREAMING_SNAKE_CASE   :			str=None   ,				**__SCREAMING_SNAKE_CASE   :			Tuple     )    ->					Dict:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = None
      if "feature_extractor" in kwargs:
           warnings.warn(
               """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
               """ instead."""   ,				__SCREAMING_SNAKE_CASE   ,				)
           __SCREAMING_SNAKE_CASE      = kwargs.pop("""feature_extractor"""     )

      __SCREAMING_SNAKE_CASE      = image_processor if image_processor is not None else feature_extractor
      if image_processor is None:
           raise ValueError("""You need to specify an `image_processor`."""     )
      if tokenizer is None:
           raise ValueError("""You need to specify a `tokenizer`."""     )

      super().__init__(__SCREAMING_SNAKE_CASE   ,				__SCREAMING_SNAKE_CASE     )
 def __call__(						self   :			Union[str, Any]   ,				__SCREAMING_SNAKE_CASE   :			Union[str, Any]=None   ,				__SCREAMING_SNAKE_CASE   :			Any=None   ,				__SCREAMING_SNAKE_CASE   :			Optional[Any]=None   ,				**__SCREAMING_SNAKE_CASE   :			str     )    ->					int:


      """simple docstring"""




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

      if text is not None:
           __SCREAMING_SNAKE_CASE      = self.tokenizer(__SCREAMING_SNAKE_CASE   ,				return_tensors=__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )

      if images is not None:
           __SCREAMING_SNAKE_CASE      = self.image_processor(__SCREAMING_SNAKE_CASE   ,				return_tensors=__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )

      if text is not None and images is not None:
           __SCREAMING_SNAKE_CASE      = image_features.pixel_values
           return encoding
      elif text is not None:
           return encoding
      else:
           return BatchEncoding(data=dict(**__SCREAMING_SNAKE_CASE     )   ,				tensor_type=__SCREAMING_SNAKE_CASE     )
 def  UpperCAmelCase__						(						self   :			List[str]   ,				*__SCREAMING_SNAKE_CASE   :			Tuple   ,				**__SCREAMING_SNAKE_CASE   :			List[Any]     )    ->					Optional[int]:


      """simple docstring"""




      return self.tokenizer.batch_decode(*__SCREAMING_SNAKE_CASE   ,				**__SCREAMING_SNAKE_CASE     )
 def  UpperCAmelCase__						(						self   :			List[Any]   ,				*__SCREAMING_SNAKE_CASE   :			Union[str, Any]   ,				**__SCREAMING_SNAKE_CASE   :			str     )    ->					Optional[Any]:


      """simple docstring"""




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


 @property
 def  UpperCAmelCase__						(						self   :			List[Any]     )    ->					List[Any]:


      """simple docstring"""




      __SCREAMING_SNAKE_CASE      = self.tokenizer.model_input_names
      __SCREAMING_SNAKE_CASE      = self.image_processor.model_input_names
      return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names     )     )






