


'''simple docstring'''




import os
import warnings
from typing import List, Optional

from ...tokenization_utils_base import BatchEncoding
from ...utils import logging
from .configuration_rag import RagConfig


_a   :   Tuple												=   logging.get_logger(__name__)




class 			_lowercase :
   def __init__(						self       :      int       ,   SCREAMING_SNAKE_CASE_       :      Optional[Any]       ,   SCREAMING_SNAKE_CASE_       :      Optional[int]      ) ->							List[str]:
        __snake_case           =						question_encoder
        __snake_case           =						generator
        __snake_case           =						self.question_encoder
   def a  (						self       :      List[str]       ,   SCREAMING_SNAKE_CASE_       :      Optional[int]      ) ->							int:
        if os.path.isfile(SCREAMING_SNAKE_CASE_      ):
             raise ValueError(f'Provided path ({save_directory}) should be a directory, not a file'      )
        os.makedirs(SCREAMING_SNAKE_CASE_       ,   exist_ok=SCREAMING_SNAKE_CASE_      )
        __snake_case           =						os.path.join(SCREAMING_SNAKE_CASE_       ,   'question_encoder_tokenizer'      )
        __snake_case           =						os.path.join(SCREAMING_SNAKE_CASE_       ,   'generator_tokenizer'      )
        self.question_encoder.save_pretrained(SCREAMING_SNAKE_CASE_      )
        self.generator.save_pretrained(SCREAMING_SNAKE_CASE_      )
   @classmethod
   def a  (						cls       :      Any       ,   SCREAMING_SNAKE_CASE_       :      str       ,   **SCREAMING_SNAKE_CASE_       :      Optional[Any]      ) ->							str:
        # dynamically import AutoTokenizer
        from ..auto.tokenization_auto import AutoTokenizer

        __snake_case           =						kwargs.pop('config'       ,   SCREAMING_SNAKE_CASE_      )

        if config is None:
             __snake_case           =						RagConfig.from_pretrained(SCREAMING_SNAKE_CASE_      )

        __snake_case           =						AutoTokenizer.from_pretrained(
            SCREAMING_SNAKE_CASE_       ,   config=config.question_encoder       ,   subfolder='question_encoder_tokenizer'      )
        __snake_case           =						AutoTokenizer.from_pretrained(
            SCREAMING_SNAKE_CASE_       ,   config=config.generator       ,   subfolder='generator_tokenizer'      )
        return cls(question_encoder=SCREAMING_SNAKE_CASE_       ,   generator=SCREAMING_SNAKE_CASE_      )
   def __call__(						self       :      str       ,   *SCREAMING_SNAKE_CASE_       :      Dict       ,   **SCREAMING_SNAKE_CASE_       :      Any      ) ->							str:
        return self.current_tokenizer(*SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )
   def a  (						self       :      Any       ,   *SCREAMING_SNAKE_CASE_       :      Tuple       ,   **SCREAMING_SNAKE_CASE_       :      Optional[int]      ) ->							Union[str, Any]:
        return self.generator.batch_decode(*SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )
   def a  (						self       :      List[str]       ,   *SCREAMING_SNAKE_CASE_       :      str       ,   **SCREAMING_SNAKE_CASE_       :      Dict      ) ->							Dict:
        return self.generator.decode(*SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_      )
   def a  (						self       :      Union[str, Any]      ) ->							Tuple:
        __snake_case           =						self.question_encoder
   def a  (						self       :      Optional[int]      ) ->							List[str]:
        __snake_case           =						self.generator





   def a  (						self       :      Union[str, Any]       ,   SCREAMING_SNAKE_CASE_       :      List[str]       ,   SCREAMING_SNAKE_CASE_       :      Optional[List[str]] = None       ,   SCREAMING_SNAKE_CASE_       :      Optional[int] = None       ,   SCREAMING_SNAKE_CASE_       :      Optional[int] = None       ,   SCREAMING_SNAKE_CASE_       :      str = "longest"       ,   SCREAMING_SNAKE_CASE_       :      str = None       ,   SCREAMING_SNAKE_CASE_       :      bool = True       ,   **SCREAMING_SNAKE_CASE_       :      List[str]       ,   ) ->							BatchEncoding:
        warnings.warn(
            '`prepare_seq2seq_batch` is deprecated and will be removed in version 5 of 🤗 Transformers. Use the '
            'regular `__call__` method to prepare your inputs and the tokenizer under the `with_target_tokenizer` '
            'context manager to prepare your targets. See the documentation of your specific tokenizer for more '
            'details'       ,   SCREAMING_SNAKE_CASE_       ,   )
        if max_length is None:
             __snake_case           =						self.current_tokenizer.model_max_length
        __snake_case           =						self(
            SCREAMING_SNAKE_CASE_       ,   add_special_tokens=SCREAMING_SNAKE_CASE_       ,   return_tensors=SCREAMING_SNAKE_CASE_       ,   max_length=SCREAMING_SNAKE_CASE_       ,   padding=SCREAMING_SNAKE_CASE_       ,   truncation=SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_       ,   )
        if tgt_texts is None:
             return model_inputs
        # Process tgt_texts
        if max_target_length is None:
             __snake_case           =						self.current_tokenizer.model_max_length
        __snake_case           =						self(
            text_target=SCREAMING_SNAKE_CASE_       ,   add_special_tokens=SCREAMING_SNAKE_CASE_       ,   return_tensors=SCREAMING_SNAKE_CASE_       ,   padding=SCREAMING_SNAKE_CASE_       ,   max_length=SCREAMING_SNAKE_CASE_       ,   truncation=SCREAMING_SNAKE_CASE_       ,   **SCREAMING_SNAKE_CASE_       ,   )
        __snake_case           =						labels['input_ids']
        return model_inputs








from ...processing_utils import ProcessorMixin







class 	__lowercase    (__SCREAMING_SNAKE_CASE  ):





							"""simple docstring"""







							_UpperCAmelCase      =						"""WhisperFeatureExtractor"""
							_UpperCAmelCase      =						"""WhisperTokenizer"""






							def __init__(      self			,						lowerCAmelCase__			,						lowerCAmelCase__       ):





										"""simple docstring"""




										super().__init__(lowerCAmelCase__			,						lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Union[str, Any]					=					self.feature_extractor
										SCREAMING_SNAKE_CASE_		:     List[Any]					=					False






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__=None			,						lowerCAmelCase__=None			,						lowerCAmelCase__=True       ):





										"""simple docstring"""




										return self.tokenizer.get_decoder_prompt_ids(task=lowerCAmelCase__			,						language=lowerCAmelCase__			,						no_timestamps=lowerCAmelCase__       )






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





										"""simple docstring"""




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

										SCREAMING_SNAKE_CASE_		:     Tuple					=					kwargs.pop('audio'			,						lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     str					=					kwargs.pop('sampling_rate'			,						lowerCAmelCase__       )
										SCREAMING_SNAKE_CASE_		:     Optional[Any]					=					kwargs.pop('text'			,						lowerCAmelCase__       )
										if len(lowerCAmelCase__       ) > 0:
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					args[0]
													SCREAMING_SNAKE_CASE_		:     List[Any]					=					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_		:     List[Any]					=					self.feature_extractor(lowerCAmelCase__			,						*lowerCAmelCase__			,						sampling_rate=lowerCAmelCase__			,						**lowerCAmelCase__       )
										if text is not None:
													SCREAMING_SNAKE_CASE_		:     Optional[int]					=					self.tokenizer(lowerCAmelCase__			,						**lowerCAmelCase__       )

										if text is None:
													return inputs

										elif audio is None:
													return encodings
										else:
													SCREAMING_SNAKE_CASE_		:     Optional[int]					=					encodings['input_ids']
													return inputs






							def 					UpperCamelCase__     (      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




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






							def 					UpperCamelCase__     (      self			,						*lowerCAmelCase__			,						**lowerCAmelCase__       ):





										"""simple docstring"""




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






							def 					UpperCamelCase__     (      self			,						lowerCAmelCase__			,						lowerCAmelCase__="np"       ):





										"""simple docstring"""




										return self.tokenizer.get_prompt_ids(lowerCAmelCase__			,						return_tensors=lowerCAmelCase__       )





