



'''simple docstring'''





from typing import List, Optional, Union

import numpy as np
import PIL.Image

from ...image_processing_utils import BaseImageProcessor, BatchFeature
from ...image_transforms import rescale, resize, to_channel_dimension_format
from ...image_utils import (
    ChannelDimension,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


A					:       Any									=     logging.get_logger(__name__)





class 				lowerCAmelCase_						(			a_		):
    __UpperCAmelCase				=			['pixel_values']





    def __init__(							self							:							int,							_snake_case							:							Optional[int] = True,							_snake_case							:							Tuple = 32,							_snake_case							:							List[Any]=PILImageResampling.BILINEAR,							_snake_case							:							int = True,							**_snake_case							:							Any,							):



       '''simple docstring'''







       snake_case       :				List[Any]		    =do_resize
       snake_case       :				Optional[Any]		    =do_rescale
       snake_case       :				List[Any]		    =size_divisor
       snake_case       :				str		    =resample
       super().__init__(**_snake_case      )





    def 	__snake_case  (							self							:							List[Any],							_snake_case							:							Any,							_snake_case							:							Any,							_snake_case							:							str,							_snake_case							:							str = None,							**_snake_case							:							int      ):



       '''simple docstring'''







       snake_case       :				Optional[int]		    =get_image_size(_snake_case      )
       # Rounds the height and width down to the closest multiple of size_divisor
       snake_case       :				Dict		    =height // size_divisor * size_divisor
       snake_case       :				List[str]		    =width // size_divisor * size_divisor
       snake_case       :				Optional[Any]		    =resize(_snake_case,							(new_h, new_w),							resample=_snake_case,							data_format=_snake_case,							**_snake_case      )
       return image





    def 	__snake_case  (							self							:							Any,							_snake_case							:							Optional[Any],							_snake_case							:							str,							_snake_case							:							Dict = None,							**_snake_case							:							Dict      ):



       '''simple docstring'''







       return rescale(image=_snake_case,							scale=_snake_case,							data_format=_snake_case,							**_snake_case      )






    def 	__snake_case  (							self							:							int,							_snake_case							:							str,							_snake_case							:							Optional[int] = None,							_snake_case							:							Tuple = None,							_snake_case							:							List[str]=None,							_snake_case							:							Optional[Any] = None,							_snake_case							:							str = None,							_snake_case							:							str = ChannelDimension.FIRST,							**_snake_case							:							List[Any],							):



       '''simple docstring'''







       snake_case       :				Any		    =do_resize if do_resize is not None else self.do_resize
       snake_case       :				Optional[int]		    =do_rescale if do_rescale is not None else self.do_rescale
       snake_case       :				List[Any]		    =size_divisor if size_divisor is not None else self.size_divisor
       snake_case       :				Optional[Any]		    =resample if resample is not None else self.resample

       if do_resize and size_divisor is None:
          raise ValueError('''size_divisor is required for resizing'''      )

       snake_case       :				str		    =make_list_of_images(_snake_case      )

       if not valid_images(_snake_case      ):
          raise ValueError('''Invalid image(s)'''      )

       # All transformations expect numpy arrays.
       snake_case       :				Any		    =[to_numpy_array(_snake_case      ) for img in images]

       if do_resize:
          snake_case       :				List[str]		    =[self.resize(_snake_case,							size_divisor=_snake_case,							resample=_snake_case      ) for image in images]

       if do_rescale:
          snake_case       :				Union[str, Any]		    =[self.rescale(_snake_case,							scale=1 / 255      ) for image in images]

       snake_case       :				Any		    =[to_channel_dimension_format(_snake_case,							_snake_case      ) for image in images]

       snake_case       :				str		    ={'pixel_values': images}
       return BatchFeature(data=_snake_case,							tensor_type=_snake_case      )









'''simple docstring'''






import inspect
import re
from hashlib import shaaaa
from typing import Dict, List

from .arrow import arrow
from .audiofolder import audiofolder
from .csv import csv
from .imagefolder import imagefolder
from .json import json
from .pandas import pandas
from .parquet import parquet
from .sql import sql  # noqa F401
from .text import text





def lowerCamelCase__     (		__lowerCamelCase			:				List[str]				):







   '''simple docstring'''




   _UpperCAmelCase  :  int				       =[]
   for line in lines:
      _UpperCAmelCase  :  Dict				       =re.sub(R'#.*'			,       ''			,       __lowerCamelCase				)  # remove comments
      if line:
         filtered_lines.append(__lowerCamelCase				)
   _UpperCAmelCase  :  str				       ='\n'.join(__lowerCamelCase				)

   # Make a hash from all this code
   _UpperCAmelCase  :  str				       =full_str.encode('utf-8'				)
   return shaaaa(__lowerCamelCase				).hexdigest()


# get importable module names and hash for caching
lowercase				={
    'csv': (csv.__name__, _hash_python_lines(inspect.getsource(csv).splitlines())),
    'json': (json.__name__, _hash_python_lines(inspect.getsource(json).splitlines())),
    'pandas': (pandas.__name__, _hash_python_lines(inspect.getsource(pandas).splitlines())),
    'parquet': (parquet.__name__, _hash_python_lines(inspect.getsource(parquet).splitlines())),
    'arrow': (arrow.__name__, _hash_python_lines(inspect.getsource(arrow).splitlines())),
    'text': (text.__name__, _hash_python_lines(inspect.getsource(text).splitlines())),
    'imagefolder': (imagefolder.__name__, _hash_python_lines(inspect.getsource(imagefolder).splitlines())),
    'audiofolder': (audiofolder.__name__, _hash_python_lines(inspect.getsource(audiofolder).splitlines())),
}

# Used to infer the module to use based on the data files extensions
lowercase				={
    '.csv': ('csv', {}),
    '.tsv': ('csv', {'sep': '\t'}),
    '.json': ('json', {}),
    '.jsonl': ('json', {}),
    '.parquet': ('parquet', {}),
    '.arrow': ('arrow', {}),
    '.txt': ('text', {}),
}
_EXTENSION_TO_MODULE.update({ext: ('imagefolder', {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ('imagefolder', {}) for ext in imagefolder.ImageFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext: ('audiofolder', {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
_EXTENSION_TO_MODULE.update({ext.upper(): ('audiofolder', {}) for ext in audiofolder.AudioFolder.EXTENSIONS})
lowercase				={'imagefolder', 'audiofolder'}

# Used to filter data files based on extensions given a module name
lowercase				={}
for _ext, (_module, _) in _EXTENSION_TO_MODULE.items():
 _MODULE_TO_EXTENSIONS.setdefault(_module, []).append(_ext)

_MODULE_TO_EXTENSIONS["imagefolder"].append('.zip')




_MODULE_TO_EXTENSIONS["audiofolder"].append('.zip')

