
'''simple docstring'''



import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin




class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						_lowercase						: List[Any]										=  '''Speech2TextFeatureExtractor'''
						_lowercase						: Any										=  '''Speech2TextTokenizer'''




						def __init__(   self       ,  _lowercase       ,  _lowercase ):

												"""simple docstring"""



												super().__init__(_lowercase       ,  _lowercase )
												_lowerCAmelCase    		=					self.feature_extractor
												_lowerCAmelCase    		=					False




						def __call__(   self       ,  *_lowercase       ,  **_lowercase ):

												"""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.""" )
																		_lowerCAmelCase    		=					kwargs.pop("""raw_speech""" )
												else:
																		_lowerCAmelCase    		=					kwargs.pop("""audio"""       ,  _lowercase )
												_lowerCAmelCase    		=					kwargs.pop("""sampling_rate"""       ,  _lowercase )
												_lowerCAmelCase    		=					kwargs.pop("""text"""       ,  _lowercase )
												if len(_lowercase ) > 0:
																		_lowerCAmelCase    		=					args[0]
																		_lowerCAmelCase    		=					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:
																		_lowerCAmelCase    		=					self.feature_extractor(_lowercase       ,  *_lowercase       ,  sampling_rate=_lowercase       ,  **_lowercase )
												if text is not None:
																		_lowerCAmelCase    		=					self.tokenizer(_lowercase       ,  **_lowercase )

												if text is None:
																		return inputs
												elif audio is None:
																		return encodings
												else:
																		_lowerCAmelCase    		=					encodings["""input_ids"""]
																		return inputs




						def    _lowercase      (   self       ,  *_lowercase       ,  **_lowercase ):

												"""simple docstring"""



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




						def    _lowercase      (   self       ,  *_lowercase       ,  **_lowercase ):

												"""simple docstring"""



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




						@contextmanager
						def    _lowercase      (   self ):

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



import unittest

from transformers import DonutProcessor


_lowerCAmelCase  :      str			 ="""naver-clova-ix/donut-base"""

class __UpperCamelCase     (				unittest.TestCase		):






					'''simple docstring'''



					def    _UpperCAmelCase    (				self						):
						UpperCAmelCase__:	Any									= DonutProcessor.from_pretrained(lowerCamelCase__						)





					def    _UpperCAmelCase    (				self						):
						UpperCAmelCase__:	Any									= {
						    "name": "John Doe",
						    "age": "99",
						    "city": "Atlanta",
						    "state": "GA",
						    "zip": "30301",
						    "phone": "123-4567",
						    "nicknames": [{"nickname": "Johnny"}, {"nickname": "JD"}],
						}

						UpperCAmelCase__:	Optional[Any]									= (
						    "<s_name>John Doe</s_name><s_age>99</s_age><s_city>Atlanta</s_city>"
						    "<s_state>GA</s_state><s_zip>30301</s_zip><s_phone>123-4567</s_phone>"
						    "<s_nicknames><s_nickname>Johnny</s_nickname>"
						    "<sep/><s_nickname>JD</s_nickname></s_nicknames>"
						)
						UpperCAmelCase__:	str									= self.processor.tokenajson(lowerCamelCase__						)

						self.assertDictEqual(lowerCamelCase__				,      lowerCamelCase__						)