





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


__A       : str						    = logging.get_logger(__name__)

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


__A       : Tuple						    = {
    "AutoTokenizer": "PreTrainedTokenizerBase",
    "AutoFeatureExtractor": "FeatureExtractionMixin",
    "AutoImageProcessor": "ImageProcessingMixin",
}







class     lowerCamelCase(	__snake_case  ):
     '''simple docstring'''


     __magic_name__        = ['feature_extractor', 'tokenizer']
     # Names need to be attr_class for attr in attributes
     __magic_name__        = None
     __magic_name__        = None
     __magic_name__        = None




     def __init__(						self							,    *snake_case_							,    **snake_case_       ):
         # Sanitize args and kwargs
         for key in kwargs:
             if key not in self.attributes:
                 raise TypeError(F"Unexpected keyword argument {key}."       )
         for arg, attribute_name in zip(snake_case_							,    self.attributes       ):
             if attribute_name in kwargs:
                 raise TypeError(F"Got multiple values for argument {attribute_name}."       )
             else:
                 _A    =       arg

         if len(snake_case_       ) != len(self.attributes       ):
             raise ValueError(
                 F"This processor requires {len(self.attributes       )} arguments: {', '.join(self.attributes       )}. Got "
                 F"{len(snake_case_       )} 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():
             _A    =       getattr(self							,    F"{attribute_name}_class"       )
             # Nothing is ever going to be an instance of "AutoXxx", in that case we check the base class.
             _A    =       AUTO_TO_BASE_CLASS_MAPPING.get(snake_case_							,    snake_case_       )
             if isinstance(snake_case_							,    snake_case_       ):
                 _A    =       tuple(getattr(snake_case_							,    snake_case_       ) for n in class_name if n is not None       )
             else:
                 _A    =       getattr(snake_case_							,    snake_case_       )

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

             setattr(self							,    snake_case_							,    snake_case_       )




     def __repr__(						self       ):
         _A    =       [F"- {name}: {repr(getattr(self							,    snake_case_       )       )}" for name in self.attributes]
         _A    =       '\n'.join(snake_case_       )
         return F"{self.__class__.__name__}:\n{attributes_repr}"




     def 					lowerCAmelCase__		(						self							,    snake_case_							,    snake_case_ = False							,    **snake_case_       ):
         os.makedirs(snake_case_							,    exist_ok=snake_case_       )

         if push_to_hub:
             _A    =       kwargs.pop('commit_message'							,    snake_case_       )
             _A    =       kwargs.pop('repo_id'							,    save_directory.split(os.path.sep       )[-1]       )
             _A    =       self._create_repo(snake_case_							,    **snake_case_       )
             _A    =       self._get_files_timestamps(snake_case_       )
         # 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:
             _A    =       [getattr(self							,    snake_case_       ) for attribute_name in self.attributes]
             _A    =       [(a.init_kwargs if isinstance(snake_case_							,    snake_case_       ) else a) for a in attrs]
             custom_object_save(self							,    snake_case_							,    config=snake_case_       )

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

         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:
                 _A    =       getattr(self							,    snake_case_       )
                 if isinstance(snake_case_							,    snake_case_       ):
                     del attribute.init_kwargs["auto_map"]

         if push_to_hub:
             self._upload_modified_files(
                 snake_case_							,    snake_case_							,    snake_case_							,    commit_message=snake_case_							,    token=kwargs.get('use_auth_token'       )							,    )




     @classmethod
     def 					lowerCAmelCase__		(						cls							,    snake_case_							,    snake_case_ = None							,    snake_case_ = False							,    snake_case_ = False							,    snake_case_ = None							,    snake_case_ = "main"							,    **snake_case_							,    ):
         _A    =       cache_dir
         _A    =       force_download
         _A    =       local_files_only
         _A    =       revision

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

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

         _A    =       cls._get_arguments_from_pretrained(snake_case_							,    **snake_case_       )
         return cls(*snake_case_       )




     @classmethod
     def 					lowerCAmelCase__		(						cls							,    snake_case_="AutoProcessor"       ):
         if not isinstance(snake_case_							,    snake_case_       ):
             _A    =       auto_class.__name__

         import transformers.models.auto as auto_module

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

         _A    =       auto_class




     @classmethod
     def 					lowerCAmelCase__		(						cls							,    snake_case_							,    **snake_case_       ):
         _A    =       []
         for attribute_name in cls.attributes:
             _A    =       getattr(cls							,    F"{attribute_name}_class"       )
             if isinstance(snake_case_							,    snake_case_       ):
                 _A    =       tuple(getattr(snake_case_							,    snake_case_       ) if n is not None else None for n in class_name       )
                 _A    =       kwargs.get('use_fast'							,    snake_case_       )
                 if use_fast and classes[1] is not None:
                     _A    =       classes[1]
                 else:
                     _A    =       classes[0]
             else:
                 _A    =       getattr(snake_case_							,    snake_case_       )

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




     @property
     def 					lowerCAmelCase__		(						self       ):
         _A    =       getattr(self							,    self.attributes[0]       )
         return getattr(snake_case_							,    'model_input_names'							,    snake_case_       )




__A       : Optional[Any]						    = copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
 __A       : Tuple						    = ProcessorMixin.push_to_hub.__doc__.format(
     object="processor", object_class="AutoProcessor", object_files="processor files"
 )












from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__A       : Dict						    = {"configuration_hubert": ["HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "HubertConfig"]}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __A       : List[str]						    = [
     "HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "HubertForCTC",
     "HubertForSequenceClassification",
     "HubertModel",
     "HubertPreTrainedModel",
 ]


try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __A       : Tuple						    = [
     "TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "TFHubertForCTC",
     "TFHubertModel",
     "TFHubertPreTrainedModel",
 ]

if TYPE_CHECKING:
 from .configuration_hubert import HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, HubertConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_hubert import (
      HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      HubertForCTC,
      HubertForSequenceClassification,
      HubertModel,
      HubertPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_hubert import (
      TF_HUBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFHubertForCTC,
      TFHubertModel,
      TFHubertPreTrainedModel,
  )


else:
 import sys

 __A       : Dict						    = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)





