


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCAmelCase__			:      List[Any]								={
    'configuration_mgp_str': ['MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MgpstrConfig'],
    'processing_mgp_str': ['MgpstrProcessor'],
    'tokenization_mgp_str': ['MgpstrTokenizer'],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				lowerCAmelCase__			:      Any								=[
				    'MGP_STR_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'MgpstrModel',
				    'MgpstrPreTrainedModel',
				    'MgpstrForSceneTextRecognition',
				]

if TYPE_CHECKING:
				from .configuration_mgp_str import MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP, MgpstrConfig
				from .processing_mgp_str import MgpstrProcessor
				from .tokenization_mgp_str import MgpstrTokenizer

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_mgp_str import (
								    MGP_STR_PRETRAINED_MODEL_ARCHIVE_LIST,
								    MgpstrForSceneTextRecognition,
								    MgpstrModel,
								    MgpstrPreTrainedModel,
								)
else:
				import sys

				lowerCAmelCase__			:      Any								=_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






"""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   __UpperCAmelCase		(      __lowerCAmelCase      ):
				A__ :  List[Any]    				=			'''Wav2Vec2FeatureExtractor'''
				A__ :  Any    				=			'''AutoTokenizer'''

				def __init__( self      ,					_lowerCamelCase      ,					_lowerCamelCase ):
										super().__init__(_lowerCamelCase      ,					_lowerCamelCase )
										lowerCamelCase__   =self.feature_extractor
										lowerCamelCase__   =False

				@classmethod
				def 						_a      ( cls      ,					_lowerCamelCase      ,					**_lowerCamelCase ):
										try:
																return super().from_pretrained(_lowerCamelCase      ,					**_lowerCamelCase )
										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: "      ,					_lowerCamelCase      ,					)

																lowerCamelCase__   =WavaVecaFeatureExtractor.from_pretrained(_lowerCamelCase      ,					**_lowerCamelCase )
																lowerCamelCase__   =WavaVecaCTCTokenizer.from_pretrained(_lowerCamelCase      ,					**_lowerCamelCase )

																return cls(feature_extractor=_lowerCamelCase      ,					tokenizer=_lowerCamelCase )

				def __call__( self      ,					*_lowerCamelCase      ,					**_lowerCamelCase ):
										# For backward compatibility
										if self._in_target_context_manager:
																return self.current_processor(*_lowerCamelCase      ,					**_lowerCamelCase )

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

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

				def 						_a      ( self      ,					*_lowerCamelCase      ,					**_lowerCamelCase ):
										# For backward compatibility
										if self._in_target_context_manager:
																return self.current_processor.pad(*_lowerCamelCase      ,					**_lowerCamelCase )

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

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

										if labels is None:
																return input_features
										elif input_features is None:
																return labels
										else:
																lowerCamelCase__   =labels["input_ids"]
																return input_features

				def 						_a      ( self      ,					*_lowerCamelCase      ,					**_lowerCamelCase ):
										return self.tokenizer.batch_decode(*_lowerCamelCase      ,					**_lowerCamelCase )

				def 						_a      ( self      ,					*_lowerCamelCase      ,					**_lowerCamelCase ):
										return self.tokenizer.decode(*_lowerCamelCase      ,					**_lowerCamelCase )






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


