



"""simple docstring"""





import os
import warnings
from pathlib import Path
from typing import Optional, Union

from .dynamic_module_utils import custom_object_save
from .tokenization_utils_base import PreTrainedTokenizerBase
from .utils import PushToHubMixin, copy_func, direct_transformers_import, logging


SCREAMING_SNAKE_CASE				:     List[Any]          =	logging.get_logger(__name__)

# Dynamically import the Transformers module to grab the attribute classes of the processor form their names.
SCREAMING_SNAKE_CASE				:     Optional[Any]          =	direct_transformers_import(Path(__file__).parent)


SCREAMING_SNAKE_CASE				:     Optional[int]          =	{
    '''AutoTokenizer''': '''PreTrainedTokenizerBase''',
    '''AutoFeatureExtractor''': '''FeatureExtractionMixin''',
    '''AutoImageProcessor''': '''ImageProcessingMixin''',
}


class       __lowerCamelCase	(   __lowercase    ):
   __UpperCamelCase									=   ['feature_extractor', 'tokenizer']
   # Names need to be attr_class for attr in attributes
   __UpperCamelCase									=   None
   __UpperCamelCase									=   None
   __UpperCamelCase									=   None







   def __init__(self       ,	*lowerCamelCase       ,	**lowerCamelCase				):




      '''simple docstring'''




      for key in kwargs:
         if key not in self.attributes:
            raise TypeError(f"""Unexpected keyword argument {key}."""				)
      for arg, attribute_name in zip(lowerCamelCase       ,	self.attributes				):
         if attribute_name in kwargs:
            raise TypeError(f"""Got multiple values for argument {attribute_name}."""				)
         else:
            _lowerCAmelCase					     =		arg

      if len(lowerCamelCase				) != len(self.attributes				):
         raise ValueError(
             f"""This processor requires {len(self.attributes				)} arguments: {", ".join(self.attributes				)}. Got """
             f"""{len(lowerCamelCase				)} arguments instead."""				)

      # Check each arg is of the proper class (this will also catch a user initializing in the wrong order)
      for attribute_name, arg in kwargs.items():
         _lowerCAmelCase					     =		getattr(self       ,	f"""{attribute_name}_class"""				)
         # Nothing is ever going to be an instance of "AutoXxx", in that case we check the base class.
         _lowerCAmelCase					     =		AUTO_TO_BASE_CLASS_MAPPING.get(lowerCamelCase       ,	lowerCamelCase				)
         if isinstance(lowerCamelCase       ,	lowerCamelCase				):
            _lowerCAmelCase					     =		tuple(getattr(lowerCamelCase       ,	lowerCamelCase				) for n in class_name if n is not None				)
         else:
            _lowerCAmelCase					     =		getattr(lowerCamelCase       ,	lowerCamelCase				)

         if not isinstance(lowerCamelCase       ,	lowerCamelCase				):
            raise ValueError(
                f"""Received a {type(lowerCamelCase				).__name__} for argument {attribute_name}, but a {class_name} was expected."""				)

         setattr(self       ,	lowerCamelCase       ,	lowerCamelCase				)







   def __repr__(self				):




      '''simple docstring'''




      _lowerCAmelCase					     =		[f"""- {name}: {repr(getattr(self       ,	lowerCamelCase				)				)}""" for name in self.attributes]
      _lowerCAmelCase					     =		"""\n""".join(lowerCamelCase				)
      return f"""{self.__class__.__name__}:\n{attributes_repr}"""







   def 							A__						(self       ,	lowerCamelCase       ,	lowerCamelCase = False       ,	**lowerCamelCase				):




      '''simple docstring'''




      os.makedirs(lowerCamelCase       ,	exist_ok=lowerCamelCase				)

      if push_to_hub:
         _lowerCAmelCase					     =		kwargs.pop("""commit_message"""       ,	lowerCamelCase				)
         _lowerCAmelCase					     =		kwargs.pop("""repo_id"""       ,	save_directory.split(os.path.sep				)[-1]				)
         _lowerCAmelCase					     =		self._create_repo(lowerCamelCase       ,	**lowerCamelCase				)
         _lowerCAmelCase					     =		self._get_files_timestamps(lowerCamelCase				)
      # If we have a custom config, we copy the file defining it in the folder and set the attributes so it can be
      # loaded from the Hub.
      if self._auto_class is not None:
         _lowerCAmelCase					     =		[getattr(self       ,	lowerCamelCase				) for attribute_name in self.attributes]
         _lowerCAmelCase					     =		[(a.init_kwargs if isinstance(lowerCamelCase       ,	lowerCamelCase				) else a) for a in attrs]
         custom_object_save(self       ,	lowerCamelCase       ,	config=lowerCamelCase				)

      for attribute_name in self.attributes:
         _lowerCAmelCase					     =		getattr(self       ,	lowerCamelCase				)
         # Include the processor class in the attribute config so this processor can then be reloaded with the
         # `AutoProcessor` API.
         if hasattr(lowerCamelCase       ,	"""_set_processor_class"""				):
            attribute._set_processor_class(self.__class__.__name__				)
         attribute.save_pretrained(lowerCamelCase				)

      if self._auto_class is not None:
         # We added an attribute to the init_kwargs of the tokenizers, which needs to be cleaned up.
         for attribute_name in self.attributes:
            _lowerCAmelCase					     =		getattr(self       ,	lowerCamelCase				)
            if isinstance(lowerCamelCase       ,	lowerCamelCase				):
               del attribute.init_kwargs["auto_map"]

      if push_to_hub:
         self._upload_modified_files(
             lowerCamelCase       ,	lowerCamelCase       ,	lowerCamelCase       ,	commit_message=lowerCamelCase       ,	token=kwargs.get("""use_auth_token"""				)       ,	)







   @classmethod
   def 							A__						(cls       ,	lowerCamelCase       ,	lowerCamelCase = None       ,	lowerCamelCase = False       ,	lowerCamelCase = False       ,	lowerCamelCase = None       ,	lowerCamelCase = "main"       ,	**lowerCamelCase       ,	):




      '''simple docstring'''




      _lowerCAmelCase					     =		cache_dir
      _lowerCAmelCase					     =		force_download
      _lowerCAmelCase					     =		local_files_only
      _lowerCAmelCase					     =		revision

      _lowerCAmelCase					     =		kwargs.pop("""use_auth_token"""       ,	lowerCamelCase				)
      if use_auth_token is not None:
         warnings.warn(
             """The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers."""       ,	lowerCamelCase				)
         if token is not None:
            raise ValueError(
                """`token` and `use_auth_token` are both specified. Please set only the argument `token`."""				)
         _lowerCAmelCase					     =		use_auth_token

      if token is not None:
         # change to `token` in a follow-up PR
         _lowerCAmelCase					     =		token

      _lowerCAmelCase					     =		cls._get_arguments_from_pretrained(lowerCamelCase       ,	**lowerCamelCase				)
      return cls(*lowerCamelCase				)







   @classmethod
   def 							A__						(cls       ,	lowerCamelCase="AutoProcessor"				):




      '''simple docstring'''




      if not isinstance(lowerCamelCase       ,	lowerCamelCase				):
         _lowerCAmelCase					     =		auto_class.__name__

      import transformers.models.auto as auto_module

      if not hasattr(lowerCamelCase       ,	lowerCamelCase				):
         raise ValueError(f"""{auto_class} is not a valid auto class."""				)

      _lowerCAmelCase					     =		auto_class







   @classmethod
   def 							A__						(cls       ,	lowerCamelCase       ,	**lowerCamelCase				):




      '''simple docstring'''




      _lowerCAmelCase					     =		[]
      for attribute_name in cls.attributes:
         _lowerCAmelCase					     =		getattr(cls       ,	f"""{attribute_name}_class"""				)
         if isinstance(lowerCamelCase       ,	lowerCamelCase				):
            _lowerCAmelCase					     =		tuple(getattr(lowerCamelCase       ,	lowerCamelCase				) if n is not None else None for n in class_name				)
            _lowerCAmelCase					     =		kwargs.get("""use_fast"""       ,	lowerCamelCase				)
            if use_fast and classes[1] is not None:
               _lowerCAmelCase					     =		classes[1]
            else:
               _lowerCAmelCase					     =		classes[0]
         else:
            _lowerCAmelCase					     =		getattr(lowerCamelCase       ,	lowerCamelCase				)

         args.append(attribute_class.from_pretrained(lowerCamelCase       ,	**lowerCamelCase				)				)
      return args







   @property
   def 							A__						(self				):




      '''simple docstring'''




      _lowerCAmelCase					     =		getattr(self       ,	self.attributes[0]				)
      return getattr(lowerCamelCase       ,	"""model_input_names"""       ,	lowerCamelCase				)





SCREAMING_SNAKE_CASE				:     Dict          =	copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
  SCREAMING_SNAKE_CASE				:     Optional[int]          =	ProcessorMixin.push_to_hub.__doc__.format(
      object='''processor''', object_class='''AutoProcessor''', object_files='''processor files'''
  )




"""simple docstring"""





def 	__UpperCAmelCase					(       snake_case_  :  float   )							->	int:






   """simple docstring"""


   return int(snake_case_   ) if x - int(snake_case_   ) <= 0 else int(snake_case_   ) + 1


if __name__ == "__main__":
  import doctest

  doctest.testmod()