


"""simple docstring"""





from typing import TYPE_CHECKING

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


snake_case__						:   int			 = {'''configuration_vit''': ['''VIT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ViTConfig''', '''ViTOnnxConfig''']}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 snake_case__						:   Any			 = ['''ViTFeatureExtractor''']
 snake_case__						:   Tuple			 = ['''ViTImageProcessor''']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 snake_case__						:   List[Any]			 = [
     '''VIT_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''ViTForImageClassification''',
     '''ViTForMaskedImageModeling''',
     '''ViTModel''',
     '''ViTPreTrainedModel''',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 snake_case__						:   Union[str, Any]			 = [
     '''TFViTForImageClassification''',
     '''TFViTModel''',
     '''TFViTPreTrainedModel''',
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 snake_case__						:   Tuple			 = [
     '''FlaxViTForImageClassification''',
     '''FlaxViTModel''',
     '''FlaxViTPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_vit import VIT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTConfig, ViTOnnxConfig

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_vit import ViTFeatureExtractor
  from .image_processing_vit import ViTImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_vit import (
      VIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      ViTForImageClassification,
      ViTForMaskedImageModeling,
      ViTModel,
      ViTPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel


else:
 import sys

 snake_case__						:   str			 = _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)









'''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  SCREAMING_SNAKE_CASE    (datasets.BuilderConfig							):
     lowerCAmelCase					=       None




class  SCREAMING_SNAKE_CASE    (datasets.ArrowBasedBuilder							):
     lowerCAmelCase					=       PandasConfig


     def 							SCREAMING_SNAKE_CASE  (						self):

          '''simple docstring'''






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


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase):

          '''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}')
          __A						: Dict      =       dl_manager.download_and_extract(self.config.data_files)
          if isinstance(_UpperCAmelCase						,	(str, list, tuple)):
               __A						: Union[str, Any]      =       data_files
               if isinstance(_UpperCAmelCase						,	_UpperCAmelCase):
                    __A						: Optional[int]      =       [files]
               # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
               __A						: Optional[Any]      =       [dl_manager.iter_files(_UpperCAmelCase) for file in files]
               return [datasets.SplitGenerator(name=datasets.Split.TRAIN						,	gen_kwargs={'files': files})]
          __A						: Tuple      =       []
          for split_name, files in data_files.items():
               if isinstance(_UpperCAmelCase						,	_UpperCAmelCase):
                    __A						: Dict      =       [files]
               # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
               __A						: Optional[Any]      =       [dl_manager.iter_files(_UpperCAmelCase) for file in files]
               splits.append(datasets.SplitGenerator(name=_UpperCAmelCase						,	gen_kwargs={'files': files}))
          return splits


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase):

          '''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
               __A						: List[str]      =       table_cast(_UpperCAmelCase						,	self.config.features.arrow_schema)
          return pa_table


     def 							SCREAMING_SNAKE_CASE  (						self						,	_UpperCAmelCase):

          '''simple docstring'''






          for i, file in enumerate(itertools.chain.from_iterable(_UpperCAmelCase)):
               with open(_UpperCAmelCase						,	'rb') as f:
                    __A						: Optional[int]      =       pa.Table.from_pandas(pd.read_pickle(_UpperCAmelCase))
                    yield i, self._cast_table(_UpperCAmelCase)