


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_sentencepiece_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


A				:   Any		= {"configuration_pegasus": ["PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP", "PegasusConfig"]}

try:
    if not is_sentencepiece_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A				:   List[str]		= ["PegasusTokenizer"]

try:
    if not is_tokenizers_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A				:   Tuple		= ["PegasusTokenizerFast"]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A				:   Tuple		= [
        "PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST",
        "PegasusForCausalLM",
        "PegasusForConditionalGeneration",
        "PegasusModel",
        "PegasusPreTrainedModel",
    ]

try:
    if not is_tf_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A				:   Union[str, Any]		= [
        "TFPegasusForConditionalGeneration",
        "TFPegasusModel",
        "TFPegasusPreTrainedModel",
    ]

try:
    if not is_flax_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A				:   List[str]		= [
        "FlaxPegasusForConditionalGeneration",
        "FlaxPegasusModel",
        "FlaxPegasusPreTrainedModel",
    ]


if TYPE_CHECKING:
    from .configuration_pegasus import PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP, PegasusConfig

    try:
        if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_pegasus import PegasusTokenizer

    try:
        if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_pegasus_fast import PegasusTokenizerFast

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_pegasus import (
            PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
            PegasusForCausalLM,
            PegasusForConditionalGeneration,
            PegasusModel,
            PegasusPreTrainedModel,
        )

    try:
        if not is_tf_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_tf_pegasus import TFPegasusForConditionalGeneration, TFPegasusModel, TFPegasusPreTrainedModel

    try:
        if not is_flax_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_flax_pegasus import (
            FlaxPegasusForConditionalGeneration,
            FlaxPegasusModel,
            FlaxPegasusPreTrainedModel,
        )

else:
    import sys

    A				:   Union[str, Any]		= _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)






import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin







class       _lowercase			(							lowercase__):


       """simple docstring"""




       A__ 						=      "AutoFeatureExtractor"
       A__ 						=      "Speech2Text2Tokenizer"





       def __init__(       self							:      List[str] ,				__lowerCamelCase							:      Dict ,				__lowerCamelCase							:      str	):


             '''simple docstring'''



             super().__init__(__lowerCamelCase ,				__lowerCamelCase	)
             lowerCamelCase__		:    Optional[Any]   =  self.feature_extractor
             lowerCamelCase__		:    Optional[int]   =  False





       def __call__(       self							:      List[str] ,				*__lowerCamelCase							:      Union[str, Any] ,				**__lowerCamelCase							:      List[Any]	):


             '''simple docstring'''



             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__		:    List[Any]   =  kwargs.pop("raw_speech"	)
             else:
                   lowerCamelCase__		:    str   =  kwargs.pop("audio" ,				__lowerCamelCase	)
             lowerCamelCase__		:    Optional[Any]   =  kwargs.pop("sampling_rate" ,				__lowerCamelCase	)
             lowerCamelCase__		:    Union[str, Any]   =  kwargs.pop("text" ,				__lowerCamelCase	)
             if len(__lowerCamelCase	) > 0:
                   lowerCamelCase__		:    Dict   =  args[0]
                   lowerCamelCase__		:    int   =  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__		:    str   =  self.feature_extractor(__lowerCamelCase ,				*__lowerCamelCase ,				sampling_rate=__lowerCamelCase ,				**__lowerCamelCase	)
             if text is not None:
                   lowerCamelCase__		:    Optional[int]   =  self.tokenizer(__lowerCamelCase ,				**__lowerCamelCase	)

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





       def 						lowerCAmelCase					(       self							:      Any ,				*__lowerCamelCase							:      Any ,				**__lowerCamelCase							:      Any	):


             '''simple docstring'''



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





       def 						lowerCAmelCase					(       self							:      Dict ,				*__lowerCamelCase							:      int ,				**__lowerCamelCase							:      List[str]	):


             '''simple docstring'''



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





       @contextmanager
       def 						lowerCAmelCase					(       self							:      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."	)
             lowerCamelCase__		:    int   =  True
             lowerCamelCase__		:    List[Any]   =  self.tokenizer
             yield
             lowerCamelCase__		:    Optional[int]   =  self.feature_extractor
             lowerCamelCase__		:    List[str]   =  False


