

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


__snake_case							:			List[str]      		= logging.get_logger(__name__)

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


__snake_case							:			Optional[int]      		= {
    """AutoTokenizer""": """PreTrainedTokenizerBase""",
    """AutoFeatureExtractor""": """FeatureExtractionMixin""",
    """AutoImageProcessor""": """ImageProcessingMixin""",
}



class 					A__(lowerCamelCase_       ):
      """simple docstring"""






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





      def __init__(						self     ,			*_lowercase     ,			**_lowercase						)    ->   str:







         for key in kwargs:
            if key not in self.attributes:
               raise TypeError(F'''Unexpected keyword argument {key}.'''						)
         for arg, attribute_name in zip(_lowercase     ,			self.attributes						):
            if attribute_name in kwargs:
               raise TypeError(F'''Got multiple values for argument {attribute_name}.'''						)
            else:
               a_	:	List[Any]          =   arg

         if len(_lowercase						) != len(self.attributes						):
            raise ValueError(
                F'''This processor requires {len(self.attributes						)} arguments: {", ".join(self.attributes						)}. Got '''
                F'''{len(_lowercase						)} 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_	:	Tuple          =   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_	:	Optional[Any]          =   AUTO_TO_BASE_CLASS_MAPPING.get(_lowercase     ,			_lowercase						)
            if isinstance(_lowercase     ,			_lowercase						):
               a_	:	List[Any]          =   tuple(getattr(_lowercase     ,			_lowercase						) for n in class_name if n is not None						)
            else:
               a_	:	Optional[int]          =   getattr(_lowercase     ,			_lowercase						)

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

            setattr(self     ,			_lowercase     ,			_lowercase						)





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





      def  UpperCamelCase__				(						self     ,			_lowercase     ,			_lowercase = False     ,			**_lowercase						)    ->   str:
         os.makedirs(_lowercase     ,			exist_ok=_lowercase						)

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

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

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

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





      @classmethod
      def  UpperCamelCase__				(						cls     ,			_lowercase     ,			_lowercase = None     ,			_lowercase = False     ,			_lowercase = False     ,			_lowercase = None     ,			_lowercase = "main"     ,			**_lowercase     ,			)    ->   List[Any]:
         a_	:	List[Any]          =   cache_dir
         a_	:	Dict          =   force_download
         a_	:	int          =   local_files_only
         a_	:	Tuple          =   revision

         a_	:	Union[str, Any]          =   kwargs.pop("""use_auth_token"""     ,			_lowercase						)
         if use_auth_token is not None:
            warnings.warn(
                """The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers."""     ,			_lowercase						)
            if token is not None:
               raise ValueError(
                   """`token` and `use_auth_token` are both specified. Please set only the argument `token`."""						)
            a_	:	List[str]          =   use_auth_token

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

         a_	:	List[Any]          =   cls._get_arguments_from_pretrained(_lowercase     ,			**_lowercase						)
         return cls(*_lowercase						)





      @classmethod
      def  UpperCamelCase__				(						cls     ,			_lowercase="AutoProcessor"						)    ->   List[Any]:







         if not isinstance(_lowercase     ,			_lowercase						):
            a_	:	int          =   auto_class.__name__

         import transformers.models.auto as auto_module

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

         a_	:	str          =   auto_class





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

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





      @property
      def  UpperCamelCase__				(						self						)    ->   Tuple:
         a_	:	str          =   getattr(self     ,			self.attributes[0]						)
         return getattr(_lowercase     ,			"""model_input_names"""     ,			_lowercase						)







__snake_case							:			Dict      		= copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
 __snake_case							:			Union[str, Any]      		= ProcessorMixin.push_to_hub.__doc__.format(
     object="""processor""", object_class="""AutoProcessor""", object_files="""processor files"""
 )





# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


__snake_case							:			Any      		= {
    """configuration_convnextv2""": [
        """CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """ConvNextV2Config""",
    ]
}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__snake_case							:			Dict      		= [
	    """CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST""",
	    """ConvNextV2ForImageClassification""",
	    """ConvNextV2Model""",
	    """ConvNextV2PreTrainedModel""",
	    """ConvNextV2Backbone""",
	]


if TYPE_CHECKING:
	from .configuration_convnextva import (
	    CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
	    ConvNextVaConfig,
	)

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_convnextva import (
		    CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST,
		    ConvNextVaBackbone,
		    ConvNextVaForImageClassification,
		    ConvNextVaModel,
		    ConvNextVaPreTrainedModel,
		)

else:
	import sys

	__snake_case							:			Dict      		= _LazyModule(__name__, globals()["""__file__"""], _import_structure)


