



'''simple docstring'''





import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin






class    lowerCamelCase_       (							__lowerCamelCase	):
  """simple docstring"""




  a_				   =['image_processor', 'tokenizer']
  a_				   ='AutoImageProcessor'
  a_				   ='AutoTokenizer'




  def __init__(					self :      Tuple     ,      _a :      int=None     ,      _a :      Dict=None     ,      **_a :      Optional[Any]  )   ->   List[Any]:
    __lowerCamelCase			:			Union[str, Any]       			=					None
    if "feature_extractor" in kwargs:
      warnings.warn(
          'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
          ' instead.'     ,      _a     ,      )
      __lowerCamelCase			:			int       			=					kwargs.pop('feature_extractor'  )

    __lowerCamelCase			:			Tuple       			=					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__(_a     ,      _a  )
    __lowerCamelCase			:			Dict       			=					self.image_processor
    __lowerCamelCase			:			Optional[Any]       			=					False




  def __call__(					self :      Tuple     ,      *_a :      Optional[Any]     ,      **_a :      str  )   ->   List[Any]:






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

    __lowerCamelCase			:			Optional[Any]       			=					kwargs.pop('images'     ,      _a  )
    __lowerCamelCase			:			Union[str, Any]       			=					kwargs.pop('text'     ,      _a  )
    if len(_a  ) > 0:
      __lowerCamelCase			:			Optional[Any]       			=					args[0]
      __lowerCamelCase			:			int       			=					args[1:]

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

    if images is not None:
      __lowerCamelCase			:			Dict       			=					self.image_processor(_a     ,      *_a     ,      **_a  )
    if text is not None:
      __lowerCamelCase			:			Optional[int]       			=					self.tokenizer(_a     ,      **_a  )

    if text is None:
      return inputs
    elif images is None:
      return encodings
    else:
      __lowerCamelCase			:			Tuple       			=					encodings['input_ids']
      return inputs




  def 		_lowercase	(					self :      Any     ,      *_a :      Any     ,      **_a :      int  )   ->   Union[str, Any]:
    return self.tokenizer.batch_decode(*_a     ,      **_a  )




  def 		_lowercase	(					self :      Tuple     ,      *_a :      int     ,      **_a :      Optional[Any]  )   ->   Any:
    return self.tokenizer.decode(*_a     ,      **_a  )




  @contextmanager
  def 		_lowercase	(					self :      Tuple  )   ->   Optional[int]:
    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 images inputs, or in a separate call.'  )
    __lowerCamelCase			:			List[Any]       			=					True
    __lowerCamelCase			:			Optional[int]       			=					self.tokenizer
    yield
    __lowerCamelCase			:			List[str]       			=					self.image_processor
    __lowerCamelCase			:			Union[str, Any]       			=					False




  def 		_lowercase	(					self :      Tuple     ,      _a :      Any     ,      _a :      Dict=False     ,      _a :      Any=None  )   ->   Union[str, Any]:






    if added_vocab is None:
      __lowerCamelCase			:			Union[str, Any]       			=					self.tokenizer.get_added_vocab()

    __lowerCamelCase			:			Optional[int]       			=					{}

    while tokens:
      __lowerCamelCase			:			str       			=					re.search(R'<s_(.*?)>'     ,      _a     ,      re.IGNORECASE  )
      if start_token is None:
        break
      __lowerCamelCase			:			Dict       			=					start_token.group(1  )
      __lowerCamelCase			:			List[str]       			=					re.search(Rf'</s_{key}>'     ,      _a     ,      re.IGNORECASE  )
      __lowerCamelCase			:			str       			=					start_token.group()
      if end_token is None:
        __lowerCamelCase			:			Dict       			=					tokens.replace(_a     ,      ''  )
      else:
        __lowerCamelCase			:			Any       			=					end_token.group()
        __lowerCamelCase			:			str       			=					re.escape(_a  )
        __lowerCamelCase			:			List[Any]       			=					re.escape(_a  )
        __lowerCamelCase			:			str       			=					re.search(f'{start_token_escaped}(.*?){end_token_escaped}'     ,      _a     ,      re.IGNORECASE  )
        if content is not None:
          __lowerCamelCase			:			List[str]       			=					content.group(1  ).strip()
          if r"<s_" in content and r"</s_" in content:  # non-leaf node
            __lowerCamelCase			:			List[str]       			=					self.tokenajson(_a     ,      is_inner_value=_a     ,      added_vocab=_a  )
            if value:
              if len(_a  ) == 1:
                __lowerCamelCase			:			int       			=					value[0]
              __lowerCamelCase			:			List[str]       			=					value
          else:  # leaf nodes
            __lowerCamelCase			:			Tuple       			=					[]
            for leaf in content.split(R'<sep/>'  ):
              __lowerCamelCase			:			Tuple       			=					leaf.strip()
              if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                __lowerCamelCase			:			List[str]       			=					leaf[1:-2]  # for categorical special tokens
              output[key].append(_a  )
            if len(output[key]  ) == 1:
              __lowerCamelCase			:			Any       			=					output[key][0]

        __lowerCamelCase			:			Optional[Any]       			=					tokens[tokens.find(_a  ) + len(_a  ) :].strip()
        if tokens[:6] == r"<sep/>":  # non-leaf nodes
          return [output] + self.tokenajson(tokens[6:]     ,      is_inner_value=_a     ,      added_vocab=_a  )

    if len(_a  ):
      return [output] if is_inner_value else output
    else:
      return [] if is_inner_value else {"text_sequence": tokens}




  @property
  def 		_lowercase	(					self :      List[str]  )   ->   Any:
    warnings.warn(
        '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'     ,      _a     ,      )
    return self.image_processor_class




  @property
  def 		_lowercase	(					self :      Any  )   ->   Optional[Any]:
    warnings.warn(
        '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'     ,      _a     ,      )
    return self.image_processor








import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin





class     lowerCamelCase      (       __lowerCamelCase					):
	UpperCamelCase_  :					Optional[Any]    		=	'MCTCTFeatureExtractor'
	UpperCamelCase_  :					List[Any]    		=	'AutoTokenizer'







	def __init__(     self      :Tuple   ,     lowercase      :List[str]   ,     lowercase      :Dict			)		->      Tuple:







				"""simple docstring"""






				super().__init__(lowercase   ,     lowercase			)
				SCREAMING_SNAKE_CASE     						= self.feature_extractor
				SCREAMING_SNAKE_CASE     						= False







	def __call__(     self      :Union[str, Any]   ,     *lowercase      :Union[str, Any]   ,     **lowercase      :str			)		->      int:







				"""simple docstring"""






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

				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'''   ,     lowercase			)
				SCREAMING_SNAKE_CASE     						= kwargs.pop('''sampling_rate'''   ,     lowercase			)
				SCREAMING_SNAKE_CASE     						= kwargs.pop('''text'''   ,     lowercase			)
				if len(lowercase			) > 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(lowercase   ,     *lowercase   ,     sampling_rate=lowercase   ,     **lowercase			)
				if text is not None:
							SCREAMING_SNAKE_CASE     						= self.tokenizer(lowercase   ,     **lowercase			)

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







	def  snake_case__     (     self      :Dict   ,     *lowercase      :Union[str, Any]   ,     **lowercase      :List[str]			)		->      Union[str, Any]:







				"""simple docstring"""






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







	def  snake_case__     (     self      :List[Any]   ,     *lowercase      :List[Any]   ,     **lowercase      :List[str]			)		->      int:







				"""simple docstring"""






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

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

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

				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  snake_case__     (     self      :Dict   ,     *lowercase      :List[str]   ,     **lowercase      :Union[str, Any]			)		->      List[Any]:







				"""simple docstring"""






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







	@contextmanager
	def  snake_case__     (     self      :str			)		->      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