






import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast


if TYPE_CHECKING:
   import sqlitea

   import sqlalchemy


_UpperCAmelCase					:						Dict         =     datasets.utils.logging.get_logger(__name__)


@dataclass
class 		lowerCAmelCase_				(  datasets.BuilderConfig ):
     __lowerCamelCase       :    Union[str, "sqlalchemy.sql.Selectable"] 	=     None
     __lowerCamelCase       :    Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"] 	=     None
     __lowerCamelCase       :    Optional[Union[str, List[str]]] 	=     None
     __lowerCamelCase       :    bool 	=     True
     __lowerCamelCase       :    Optional[Union[List, Tuple, Dict]] 	=     None
     __lowerCamelCase       :    Optional[Union[List, Dict]] 	=     None
     __lowerCamelCase       :    Optional[List[str]] 	=     None
     __lowerCamelCase       :    Optional[int] 	=     1_00_00
     __lowerCamelCase       :    Optional[datasets.Features] 	=     None





     def 						lowerCamelCase							(	self  )		->				List[Any]:
        if self.sql is None:
           raise ValueError("""sql must be specified"""  )
        if self.con is None:
           raise ValueError("""con must be specified"""  )





     def 						lowerCamelCase							(	self							, _UpperCAmelCase							, _UpperCAmelCase = None							, )		->				str:
        lowerCamelCase									=config_kwargs.copy()
        # We need to stringify the Selectable object to make its hash deterministic

        # The process of stringifying is explained here: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html
        lowerCamelCase									=config_kwargs["""sql"""]
        if not isinstance(_UpperCAmelCase							, _UpperCAmelCase  ):
           if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
              import sqlalchemy

              if isinstance(_UpperCAmelCase							, sqlalchemy.sql.Selectable  ):
                 lowerCamelCase									=sqlalchemy.create_engine(config_kwargs["""con"""].split("""://"""  )[0] + """://"""  )
                 lowerCamelCase									=str(sql.compile(dialect=engine.dialect  )  )
                 lowerCamelCase									=sql_str
              else:
                 raise TypeError(
                     F'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(_UpperCAmelCase  )}: {sql}'''  )
           else:
              raise TypeError(
                  F'''Supported types for \'sql\' are string and sqlalchemy.sql.Selectable but got {type(_UpperCAmelCase  )}: {sql}'''  )
        lowerCamelCase									=config_kwargs["""con"""]
        if not isinstance(_UpperCAmelCase							, _UpperCAmelCase  ):
           lowerCamelCase									=id(_UpperCAmelCase  )
           logger.info(
               F'''SQL connection \'con\' of type {type(_UpperCAmelCase  )} couldn\'t be hashed properly. To enable hashing, specify \'con\' as URI string instead.'''  )

        return super().create_config_id(_UpperCAmelCase							, custom_features=_UpperCAmelCase  )





     @property
     def 						lowerCamelCase							(	self  )		->				Optional[int]:
        lowerCamelCase									={
            """index_col""": self.index_col,
            """columns""": self.columns,
            """params""": self.params,
            """coerce_float""": self.coerce_float,
            """parse_dates""": self.parse_dates,
        }
        return pd_read_sql_kwargs




class 		lowerCAmelCase_				(  datasets.ArrowBasedBuilder ):
     __lowerCamelCase       :    List[Any] 	=     SqlConfig





     def 						lowerCamelCase							(	self  )		->				str:
        return datasets.DatasetInfo(features=self.config.features  )





     def 						lowerCamelCase							(	self							, _UpperCAmelCase  )		->				Dict:
        return [datasets.SplitGenerator(name=datasets.Split.TRAIN							, gen_kwargs={}  )]





     def 						lowerCamelCase							(	self							, _UpperCAmelCase  )		->				pa.Table:
        if self.config.features is not None:
           lowerCamelCase									=self.config.features.arrow_schema
           if all(not require_storage_cast(_UpperCAmelCase  ) for feature in self.config.features.values()  ):
              # cheaper cast
              lowerCamelCase									=pa.Table.from_arrays([pa_table[field.name] for field in schema]							, schema=_UpperCAmelCase  )
           else:
              # more expensive cast; allows str <-> int/float or str to Audio for example
              lowerCamelCase									=table_cast(_UpperCAmelCase							, _UpperCAmelCase  )
        return pa_table





     def 						lowerCamelCase							(	self  )		->				Optional[Any]:
        lowerCamelCase									=self.config.chunksize
        lowerCamelCase									=pd.read_sql(
            self.config.sql							, self.config.con							, chunksize=_UpperCAmelCase							, **self.config.pd_read_sql_kwargs  )
        lowerCamelCase									=[sql_reader] if chunksize is None else sql_reader
        for chunk_idx, df in enumerate(_UpperCAmelCase  ):
           lowerCamelCase									=pa.Table.from_pandas(_UpperCAmelCase  )
           yield chunk_idx, self._cast_table(_UpperCAmelCase  )







from ...configuration_utils import PretrainedConfig
from ...utils import logging


_UpperCAmelCase					:						Any         =     logging.get_logger(__name__)

_UpperCAmelCase					:						Dict         =     {
    'ZinengTang/tvlt-base': 'https://huggingface.co/ZinengTang/tvlt-base/blob/main/config.json',
}


class 		lowerCAmelCase_				(  UpperCamelCase ):
     __lowerCamelCase       :    Any 	=     '''tvlt'''





     def __init__(	self							, _UpperCAmelCase=224							, _UpperCAmelCase=2048							, _UpperCAmelCase=128							, _UpperCAmelCase=[16, 16]							, _UpperCAmelCase=[16, 16]							, _UpperCAmelCase=3							, _UpperCAmelCase=1							, _UpperCAmelCase=8							, _UpperCAmelCase=768							, _UpperCAmelCase=12							, _UpperCAmelCase=12							, _UpperCAmelCase=3072							, _UpperCAmelCase="gelu"							, _UpperCAmelCase=0.0							, _UpperCAmelCase=0.0							, _UpperCAmelCase=0.02							, _UpperCAmelCase=1E-6							, _UpperCAmelCase=True							, _UpperCAmelCase=False							, _UpperCAmelCase=16							, _UpperCAmelCase=512							, _UpperCAmelCase=8							, _UpperCAmelCase=2048							, _UpperCAmelCase=0.75							, _UpperCAmelCase=0.15							, _UpperCAmelCase="frame-level"							, _UpperCAmelCase=True							, _UpperCAmelCase=True							, _UpperCAmelCase="classification"							, **_UpperCAmelCase							, )		->				List[Any]:
        super().__init__(**_UpperCAmelCase  )

        if audio_mask_type not in ("frame-level", "patch_level"):
           raise ValueError(
               """audio_mask_type must be one of two acceptable strategies - {'frame_level', 'patch-level') """
               F'''got {audio_mask_type}'''  )

        lowerCamelCase									=image_size
        lowerCamelCase									=spectrogram_length
        lowerCamelCase									=frequency_length
        lowerCamelCase									=image_patch_size
        lowerCamelCase									=audio_patch_size
        lowerCamelCase									=num_image_channels
        lowerCamelCase									=num_audio_channels
        lowerCamelCase									=num_frames

        lowerCamelCase									=hidden_size
        lowerCamelCase									=num_hidden_layers
        lowerCamelCase									=num_attention_heads
        lowerCamelCase									=intermediate_size
        lowerCamelCase									=hidden_act
        lowerCamelCase									=hidden_dropout_prob
        lowerCamelCase									=attention_probs_dropout_prob
        lowerCamelCase									=initializer_range
        lowerCamelCase									=layer_norm_eps
        lowerCamelCase									=qkv_bias
        lowerCamelCase									=use_mean_pooling

        lowerCamelCase									=decoder_num_attention_heads
        lowerCamelCase									=decoder_hidden_size
        lowerCamelCase									=decoder_num_hidden_layers
        lowerCamelCase									=decoder_intermediate_size
        lowerCamelCase									=pixel_mask_ratio
        lowerCamelCase									=audio_mask_ratio
        lowerCamelCase									=audio_mask_type

        lowerCamelCase									=task_matching
        lowerCamelCase									=task_mae
        lowerCamelCase									=loss_type