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


snake_case    =		logging.get_logger(__name__)

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


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




class      UpperCamelCase	(       __magic_name__      ):

				"""simple docstring"""



				UpperCAmelCase_				:      int						  =				["feature_extractor", "tokenizer"]
				# Names need to be attr_class for attr in attributes
				UpperCAmelCase_				:      str						  =				None
				UpperCAmelCase_				:      str						  =				None
				UpperCAmelCase_				:      List[Any]						  =				None


				def __init__(				self		,	*lowercase__		,	**lowercase__			)    ->    Any:
									"""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(lowercase__		,	self.attributes			):
														if attribute_name in kwargs:
																			raise TypeError(f'''Got multiple values for argument {attribute_name}.'''			)
														else:
																			SCREAMING_SNAKE_CASE				=	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():
														SCREAMING_SNAKE_CASE				=	getattr(self		,	f'''{attribute_name}_class'''			)
														# Nothing is ever going to be an instance of "AutoXxx", in that case we check the base class.
														SCREAMING_SNAKE_CASE				=	AUTO_TO_BASE_CLASS_MAPPING.get(lowercase__		,	lowercase__			)
														if isinstance(lowercase__		,	lowercase__			):
																			SCREAMING_SNAKE_CASE				=	tuple(getattr(lowercase__		,	lowercase__			) for n in class_name if n is not None			)
														else:
																			SCREAMING_SNAKE_CASE				=	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]:
									"""simple docstring"""







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


				def 							A					(				self		,	lowercase__		,	lowercase__ = False		,	**lowercase__			)    ->    Optional[Any]:
									"""simple docstring"""







									os.makedirs(lowercase__		,	exist_ok=lowercase__			)

									if push_to_hub:
														SCREAMING_SNAKE_CASE				=	kwargs.pop('commit_message'		,	lowercase__			)
														SCREAMING_SNAKE_CASE				=	kwargs.pop('repo_id'		,	save_directory.split(os.path.sep			)[-1]			)
														SCREAMING_SNAKE_CASE				=	self._create_repo(lowercase__		,	**lowercase__			)
														SCREAMING_SNAKE_CASE				=	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:
														SCREAMING_SNAKE_CASE				=	[getattr(self		,	lowercase__			) for attribute_name in self.attributes]
														SCREAMING_SNAKE_CASE				=	[(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:
														SCREAMING_SNAKE_CASE				=	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:
																			SCREAMING_SNAKE_CASE				=	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 							A					(				cls		,	lowercase__		,	lowercase__ = None		,	lowercase__ = False		,	lowercase__ = False		,	lowercase__ = None		,	lowercase__ = "main"		,	**lowercase__		,	)    ->    Dict:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE				=	cache_dir
									SCREAMING_SNAKE_CASE				=	force_download
									SCREAMING_SNAKE_CASE				=	local_files_only
									SCREAMING_SNAKE_CASE				=	revision

									SCREAMING_SNAKE_CASE				=	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`.'			)
														SCREAMING_SNAKE_CASE				=	use_auth_token

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

									SCREAMING_SNAKE_CASE				=	cls._get_arguments_from_pretrained(lowercase__		,	**lowercase__			)
									return cls(*lowercase__			)


				@classmethod
				def 							A					(				cls		,	lowercase__="AutoProcessor"			)    ->    List[str]:
									"""simple docstring"""







									if not isinstance(lowercase__		,	lowercase__			):
														SCREAMING_SNAKE_CASE				=	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.'''			)

									SCREAMING_SNAKE_CASE				=	auto_class


				@classmethod
				def 							A					(				cls		,	lowercase__		,	**lowercase__			)    ->    Any:
									"""simple docstring"""







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

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




				@property
				def 							A					(				self			)    ->    int:
									"""simple docstring"""







									SCREAMING_SNAKE_CASE				=	getattr(self		,	self.attributes[0]			)
									return getattr(lowercase__		,	'model_input_names'		,	lowercase__			)






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


"""simple docstring"""




def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_			):
					if not isinstance(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			):
										SCREAMING_SNAKE_CASE				=	(
										    'operation can not be conducted on a object of type '
										    f'''{type(SCREAMING_SNAKE_CASE_			).__name__}'''
										)
										raise TypeError(SCREAMING_SNAKE_CASE_			)
					SCREAMING_SNAKE_CASE				=	''
					for _ in range(0,     3_2			):
										bit_string += str(number % 2			)
										SCREAMING_SNAKE_CASE				=	number >> 1
					return bit_string

def   UpperCamelCase_  (		SCREAMING_SNAKE_CASE_			):
					if number < 0:
										raise ValueError('the value of input must be positive'			)
					elif isinstance(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			):
										raise TypeError('Input value must be a \'int\' type'			)
					elif isinstance(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			):
										raise TypeError('\'<\' not supported between instances of \'str\' and \'int\''			)
					SCREAMING_SNAKE_CASE				=	0
					# iterator over [1 to 32],since we are dealing with 32 bit integer
					for _ in range(1,     3_3			):
										# left shift the bits by unity
										SCREAMING_SNAKE_CASE				=	result << 1
										# get the end bit
										SCREAMING_SNAKE_CASE				=	number % 2
										# right shift the bits by unity
										SCREAMING_SNAKE_CASE				=	number >> 1
										# add that bit to our ans
										SCREAMING_SNAKE_CASE				=	result | end_bit
					return get_reverse_bit_string(SCREAMING_SNAKE_CASE_			)


if __name__ == "__main__":
	import doctest

	doctest.testmod()
