'''simple docstring'''




import multiprocessing
from typing import TYPE_CHECKING, Optional, Union

from .. import Dataset, Features, config
from ..formatting import query_table
from ..packaged_modules.sql.sql import Sql
from ..utils import logging
from .abc import AbstractDatasetInputStream


if TYPE_CHECKING:
  import sqlitea

  import sqlalchemy




class    a__				(       UpperCAmelCase__			):






     def __init__(			self		:		Dict  ,    a		:		Union[str, "sqlalchemy.sql.Selectable"]  ,    a		:		Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]  ,    a		:		Optional[Features] = None  ,    a		:		str = None  ,    a		:		bool = False  ,    **a		:		Dict  ,    ):





         """simple docstring"""



         super().__init__(features=a  ,    cache_dir=a  ,    keep_in_memory=a  ,    **a   )
         __lowerCamelCase          =  Sql(
             cache_dir=a  ,    features=a  ,    sql=a  ,    con=a  ,    **a  ,    )






     def        SCREAMING_SNAKE_CASE__       (			self		:		Any   ):





         """simple docstring"""



         __lowerCamelCase          =  None
         __lowerCamelCase          =  None
         __lowerCamelCase          =  None
         __lowerCamelCase          =  None

         self.builder.download_and_prepare(
             download_config=a  ,    download_mode=a  ,    verification_mode=a  ,    base_path=a  ,    )

         # Build dataset for splits
         __lowerCamelCase          =  self.builder.as_dataset(
             split='''train'''  ,    verification_mode=a  ,    in_memory=self.keep_in_memory   )
         return dataset




class    a__				:






     def __init__(			self		:		Optional[int]  ,    a		:		Dataset  ,    a		:		str  ,    a		:		Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]  ,    a		:		Optional[int] = None  ,    a		:		Optional[int] = None  ,    **a		:		int  ,    ):





         """simple docstring"""



         if num_proc is not None and num_proc <= 0:
             raise ValueError(f"""num_proc {num_proc} must be an integer > 0."""   )

         __lowerCamelCase          =  dataset
         __lowerCamelCase          =  name
         __lowerCamelCase          =  con
         __lowerCamelCase          =  batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
         __lowerCamelCase          =  num_proc
         __lowerCamelCase          =  to_sql_kwargs






     def        SCREAMING_SNAKE_CASE__       (			self		:		Tuple   ):





         """simple docstring"""



         __lowerCamelCase          =  self.to_sql_kwargs.pop('''sql'''  ,    a   )
         __lowerCamelCase          =  self.to_sql_kwargs.pop('''con'''  ,    a   )
         __lowerCamelCase          =  self.to_sql_kwargs.pop('''index'''  ,    a   )

         __lowerCamelCase          =  self._write(index=a  ,    **self.to_sql_kwargs   )
         return written






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]  ,    a		:		str   ):





         """simple docstring"""



         __lowerCamelCase     ,  __lowerCamelCase     ,  __lowerCamelCase          =  args
         __lowerCamelCase          =  {**to_sql_kwargs, '''if_exists''': '''append'''} if offset > 0 else to_sql_kwargs
         __lowerCamelCase          =  query_table(
             table=self.dataset.data  ,    key=slice(a  ,    offset + self.batch_size   )  ,    indices=self.dataset._indices  ,    )
         __lowerCamelCase          =  batch.to_pandas()
         __lowerCamelCase          =  df.to_sql(self.name  ,    self.con  ,    index=a  ,    **a   )
         return num_rows or len(a   )






     def        SCREAMING_SNAKE_CASE__       (			self		:		List[str]  ,    a		:		List[str]  ,    **a		:		List[str]   ):





         """simple docstring"""



         __lowerCamelCase          =  0

         if self.num_proc is None or self.num_proc == 1:
             for offset in logging.tqdm(
                 range(0  ,    len(self.dataset   )  ,    self.batch_size   )  ,    unit='''ba'''  ,    disable=not logging.is_progress_bar_enabled()  ,    desc='''Creating SQL from Arrow format'''  ,    ):
                 written += self._batch_sql((offset, index, to_sql_kwargs)   )
         else:
             __lowerCamelCase     ,  __lowerCamelCase          =  len(self.dataset   ), self.batch_size
             with multiprocessing.Pool(self.num_proc   ) as pool:
                 for num_rows in logging.tqdm(
                     pool.imap(
                         self._batch_sql  ,    [(offset, index, to_sql_kwargs) for offset in range(0  ,    a  ,    a   )]  ,    )  ,    total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size  ,    unit='''ba'''  ,    disable=not logging.is_progress_bar_enabled()  ,    desc='''Creating SQL from Arrow format'''  ,    ):
                     written += num_rows

         return written

'''simple docstring'''




from typing import TYPE_CHECKING

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


__UpperCAmelCase												={
    "configuration_whisper": ["WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP", "WhisperConfig", "WhisperOnnxConfig"],
    "feature_extraction_whisper": ["WhisperFeatureExtractor"],
    "processing_whisper": ["WhisperProcessor"],
    "tokenization_whisper": ["WhisperTokenizer"],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase												=["WhisperTokenizerFast"]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase												=[
      "WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "WhisperForConditionalGeneration",
      "WhisperModel",
      "WhisperPreTrainedModel",
      "WhisperForAudioClassification",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase												=[
      "TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST",
      "TFWhisperForConditionalGeneration",
      "TFWhisperModel",
      "TFWhisperPreTrainedModel",
  ]

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase												=[
      "FlaxWhisperForConditionalGeneration",
      "FlaxWhisperModel",
      "FlaxWhisperPreTrainedModel",
      "FlaxWhisperForAudioClassification",
  ]


if TYPE_CHECKING:
  from .configuration_whisper import WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP, WhisperConfig, WhisperOnnxConfig
  from .feature_extraction_whisper import WhisperFeatureExtractor
  from .processing_whisper import WhisperProcessor
  from .tokenization_whisper import WhisperTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_whisper_fast import WhisperTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_whisper import (
        WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
        WhisperForAudioClassification,
        WhisperForConditionalGeneration,
        WhisperModel,
        WhisperPreTrainedModel,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_whisper import (
        TF_WHISPER_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFWhisperForConditionalGeneration,
        TFWhisperModel,
        TFWhisperPreTrainedModel,
    )

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flax_whisper import (
        FlaxWhisperForAudioClassification,
        FlaxWhisperForConditionalGeneration,
        FlaxWhisperModel,
        FlaxWhisperPreTrainedModel,
    )

else:
  import sys

  __UpperCAmelCase												=_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
