

'''simple docstring'''
import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast







@dataclass
class 							A__   (	datasets.BuilderConfig  ):
  A__					=    None







class 							A__   (	datasets.ArrowBasedBuilder  ):
  A__					=    PandasConfig





  def 						A  (		self				:     Tuple			)     ->   str:





       '''simple docstring'''






       return datasets.DatasetInfo(features=self.config.features			)





  def 						A  (		self				:     Tuple							, _a				:     List[str]			)     ->   List[Any]:





       '''simple docstring'''






       if not self.config.data_files:
            raise ValueError(f"At least one data file must be specified, but got data_files={self.config.data_files}"			)
       _SCREAMING_SNAKE_CASE							   =dl_manager.download_and_extract(self.config.data_files			)
       if isinstance(_a							, (str, list, tuple)			):
            _SCREAMING_SNAKE_CASE							   =data_files
            if isinstance(_a							, _a			):
                 _SCREAMING_SNAKE_CASE							   =[files]
            # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
            _SCREAMING_SNAKE_CASE							   =[dl_manager.iter_files(_a			) for file in files]
            return [datasets.SplitGenerator(name=datasets.Split.TRAIN							, gen_kwargs={'files': files}			)]
       _SCREAMING_SNAKE_CASE							   =[]
       for split_name, files in data_files.items():
            if isinstance(_a							, _a			):
                 _SCREAMING_SNAKE_CASE							   =[files]
            # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
            _SCREAMING_SNAKE_CASE							   =[dl_manager.iter_files(_a			) for file in files]
            splits.append(datasets.SplitGenerator(name=_a							, gen_kwargs={'files': files}			)			)
       return splits





  def 						A  (		self				:     Optional[int]							, _a				:     pa.Table			)     ->   pa.Table:





       '''simple docstring'''






       if self.config.features is not None:
            # more expensive cast to support nested features with keys in a different order
            # allows str <-> int/float or str to Audio for example
            _SCREAMING_SNAKE_CASE							   =table_cast(_a							, self.config.features.arrow_schema			)
       return pa_table





  def 						A  (		self				:     int							, _a				:     Optional[int]			)     ->   Union[str, Any]:





       '''simple docstring'''






       for i, file in enumerate(itertools.chain.from_iterable(_a			)			):
            with open(_a							, 'rb'			) as f:
                 _SCREAMING_SNAKE_CASE							   =pa.Table.from_pandas(pd.read_pickle(_a			)			)
                 yield i, self._cast_table(_a			)



'''simple docstring'''
import warnings
from contextlib import contextmanager

from ....processing_utils import ProcessorMixin







class 							A__   (	A__  ):
  A__					=    'MCTCTFeatureExtractor'
  A__					=    'AutoTokenizer'





  def __init__(		self				:     Optional[Any]							, _a				:     Optional[int]							, _a				:     Union[str, Any]			)     ->   Union[str, Any]:





       '''simple docstring'''






       super().__init__(_a							, _a			)
       _SCREAMING_SNAKE_CASE							   =self.feature_extractor
       _SCREAMING_SNAKE_CASE							   =False





  def __call__(		self				:     Dict							, *_a				:     str							, **_a				:     Dict			)     ->   Dict:





       '''simple docstring'''






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

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

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





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





       '''simple docstring'''






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





  def 						A  (		self				:     Dict							, *_a				:     Tuple							, **_a				:     Dict			)     ->   List[str]:





       '''simple docstring'''






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

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

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

       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 						A  (		self				:     Tuple							, *_a				:     Dict							, **_a				:     List[Any]			)     ->   Optional[int]:





       '''simple docstring'''






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





  @contextmanager
  def 						A  (		self				:     Optional[Any]			)     ->   Dict:





       '''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
