





'''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


A						    =							logging.get_logger(__name__)

# Dynamically import the Transformers module to grab the attribute classes of the processor form their names.
A						    =							direct_transformers_import(Path(__file__).parent)


A						    =							{
    '''AutoTokenizer''': '''PreTrainedTokenizerBase''',
    '''AutoFeatureExtractor''': '''FeatureExtractionMixin''',
    '''AutoImageProcessor''': '''ImageProcessingMixin''',
}



class 							__SCREAMING_SNAKE_CASE			(       lowerCAmelCase__      ):
      '''simple docstring'''



      lowerCAmelCase__       :      Union[str, Any] 		=		["feature_extractor", "tokenizer"]
      # Names need to be attr_class for attr in attributes
      lowerCAmelCase__       :      Union[str, Any] 		=		None
      lowerCAmelCase__       :      Dict 		=		None
      lowerCAmelCase__       :      Any 		=		None

      def __init__(							self    : Dict   ,*UpperCamelCase    : List[str]   ,**UpperCamelCase    : Optional[int]  )		->  Optional[int]:
           # 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(UpperCamelCase   ,self.attributes  ):
                if attribute_name in kwargs:
                     raise TypeError(F'''Got multiple values for argument {attribute_name}.'''  )
                else:
                     _lowercase							:      Dict  						=							arg

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

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

                setattr(self   ,UpperCamelCase   ,UpperCamelCase  )

      def __repr__(							self    : Optional[int]  )		->  int:
           _lowercase							:      Union[str, Any]  						=							[F'''- {name}: {repr(getattr(self   ,UpperCamelCase  )  )}''' for name in self.attributes]
           _lowercase							:      int  						=							'\n'.join(UpperCamelCase  )
           return F'''{self.__class__.__name__}:\n{attributes_repr}'''

      def   _lowerCamelCase		(							self    : str   ,UpperCamelCase    : Dict   ,UpperCamelCase    : bool = False   ,**UpperCamelCase    : List[Any]  )		->  List[Any]:
           os.makedirs(UpperCamelCase   ,exist_ok=UpperCamelCase  )

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

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

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

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

      @classmethod
      def   _lowerCamelCase		(							cls    : List[Any]   ,UpperCamelCase    : Union[str, os.PathLike]   ,UpperCamelCase    : Optional[Union[str, os.PathLike]] = None   ,UpperCamelCase    : bool = False   ,UpperCamelCase    : bool = False   ,UpperCamelCase    : Optional[Union[str, bool]] = None   ,UpperCamelCase    : str = "main"   ,**UpperCamelCase    : List[Any]   ,)		->  List[Any]:
           _lowercase							:      Tuple  						=							cache_dir
           _lowercase							:      Any  						=							force_download
           _lowercase							:      Union[str, Any]  						=							local_files_only
           _lowercase							:      str  						=							revision

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

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

           _lowercase							:      Union[str, Any]  						=							cls._get_arguments_from_pretrained(UpperCamelCase   ,**UpperCamelCase  )
           return cls(*UpperCamelCase  )

      @classmethod
      def   _lowerCamelCase		(							cls    : Dict   ,UpperCamelCase    : List[str]="AutoProcessor"  )		->  int:
           if not isinstance(UpperCamelCase   ,UpperCamelCase  ):
                _lowercase							:      Optional[int]  						=							auto_class.__name__

           import transformers.models.auto as auto_module

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

           _lowercase							:      str  						=							auto_class

      @classmethod
      def   _lowerCamelCase		(							cls    : Optional[Any]   ,UpperCamelCase    : Optional[int]   ,**UpperCamelCase    : Optional[int]  )		->  List[Any]:
           _lowercase							:      Dict  						=							[]
           for attribute_name in cls.attributes:
                _lowercase							:      int  						=							getattr(cls   ,F'''{attribute_name}_class'''  )
                if isinstance(UpperCamelCase   ,UpperCamelCase  ):
                     _lowercase							:      int  						=							tuple(getattr(UpperCamelCase   ,UpperCamelCase  ) if n is not None else None for n in class_name  )
                     _lowercase							:      str  						=							kwargs.get('use_fast'   ,UpperCamelCase  )
                     if use_fast and classes[1] is not None:
                          _lowercase							:      Optional[int]  						=							classes[1]
                     else:
                          _lowercase							:      str  						=							classes[0]
                else:
                     _lowercase							:      Dict  						=							getattr(UpperCamelCase   ,UpperCamelCase  )

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



      @property
      def   _lowerCamelCase		(							self    : List[str]  )		->  Optional[int]:
           _lowercase							:      Dict  						=							getattr(self   ,self.attributes[0]  )
           return getattr(UpperCamelCase   ,'model_input_names'   ,UpperCamelCase  )

A						    =							copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
    A						    =							ProcessorMixin.push_to_hub.__doc__.format(
        object='''processor''', object_class='''AutoProcessor''', object_files='''processor files'''
    )






'''simple docstring'''







import warnings

from ...utils import logging
from .image_processing_mobilenet_va import MobileNetVaImageProcessor


A						    =							logging.get_logger(__name__)



class 							__SCREAMING_SNAKE_CASE			(       lowerCAmelCase__      ):
      '''simple docstring'''



      def __init__(							self    : Tuple   ,*UpperCamelCase    : str   ,**UpperCamelCase    : List[Any]  )		->  None:
           warnings.warn(
               'The class MobileNetV2FeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
               ' Please use MobileNetV2ImageProcessor instead.'   ,UpperCamelCase   ,)
           super().__init__(*UpperCamelCase   ,**UpperCamelCase  )