


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


__magic_name__       					=      logging.get_logger(__name__)

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


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





class    lowerCAmelCase__				(			__lowerCamelCase       ):






							"""simple docstring"""
							__UpperCAmelCase   :		List[str]  					=	['''feature_extractor''', '''tokenizer''']
							# Names need to be attr_class for attr in attributes
							__UpperCAmelCase   :		List[Any]  					=	None
							__UpperCAmelCase   :		Any  					=	None
							__UpperCAmelCase   :		Union[str, Any]  					=	None




							def __init__(   self				,							*a_				,							**a_     ):
								# 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(a_				,							self.attributes     ):
									if attribute_name in kwargs:
										raise TypeError(F"""Got multiple values for argument {attribute_name}."""     )
									else:
										lowerCamelCase_			:							Optional[Any]      =       arg

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

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

									setattr(self				,							a_				,							a_     )




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




							def 					_UpperCamelCase			(   self				,							a_				,							a_ = False				,							**a_     ):
								os.makedirs(a_				,							exist_ok=a_     )

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

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

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

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




							@classmethod
							def 					_UpperCamelCase			(   cls				,							a_				,							a_ = None				,							a_ = False				,							a_ = False				,							a_ = None				,							a_ = "main"				,							**a_				,							):
								lowerCamelCase_			:							Any      =       cache_dir
								lowerCamelCase_			:							Dict      =       force_download
								lowerCamelCase_			:							Optional[int]      =       local_files_only
								lowerCamelCase_			:							Optional[Any]      =       revision

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

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

								lowerCamelCase_			:							Dict      =       cls._get_arguments_from_pretrained(a_				,							**a_     )
								return cls(*a_     )




							@classmethod
							def 					_UpperCamelCase			(   cls				,							a_="AutoProcessor"     ):
								if not isinstance(a_				,							a_     ):
									lowerCamelCase_			:							Any      =       auto_class.__name__

								import transformers.models.auto as auto_module

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

								lowerCamelCase_			:							List[str]      =       auto_class




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

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




							@property
							def 					_UpperCamelCase			(   self     ):
								lowerCamelCase_			:							Tuple      =       getattr(self				,							self.attributes[0]     )
								return getattr(a_				,							"model_input_names"				,							a_     )




__magic_name__       					=      copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
							__magic_name__       					=      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_torch_available, is_vision_available


__magic_name__       					=      {'''configuration_detr''': ['''DETR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DetrConfig''', '''DetrOnnxConfig''']}

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__magic_name__       					=      ['''DetrFeatureExtractor''']
							__magic_name__       					=      ['''DetrImageProcessor''']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__magic_name__       					=      [
							    '''DETR_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''DetrForObjectDetection''',
							    '''DetrForSegmentation''',
							    '''DetrModel''',
							    '''DetrPreTrainedModel''',
							]


if TYPE_CHECKING:
							from .configuration_detr import DETR_PRETRAINED_CONFIG_ARCHIVE_MAP, DetrConfig, DetrOnnxConfig

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_detr import DetrFeatureExtractor
														from .image_processing_detr import DetrImageProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_detr import (
														    DETR_PRETRAINED_MODEL_ARCHIVE_LIST,
														    DetrForObjectDetection,
														    DetrForSegmentation,
														    DetrModel,
														    DetrPreTrainedModel,
														)

else:
							import sys

							__magic_name__       					=      _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

