






"""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    (					UpperCamelCase		):
							snake_case_  =				['feature_extractor', 'tokenizer']
							# Names need to be attr_class for attr in attributes
							snake_case_  =				None
							snake_case_  =				None
							snake_case_  =				None


							def __init__(      self   :    str      ,     *snake_case   :    List[str]      ,     **snake_case   :    Optional[int]				):
													'''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(snake_case      ,     self.attributes				):
																			if attribute_name in kwargs:
																									raise TypeError(F'Got multiple values for argument {attribute_name}.'				)
																			else:
																									A__    :	Dict			=	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__    :	List[str]			=	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__    :	Dict			=	AUTO_TO_BASE_CLASS_MAPPING.get(snake_case      ,     snake_case				)
																			if isinstance(snake_case      ,     snake_case				):
																									A__    :	int			=	tuple(getattr(snake_case      ,     snake_case				) for n in class_name if n is not None				)
																			else:
																									A__    :	List[str]			=	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   :    Union[str, Any]				):
													'''simple docstring'''





													A__    :	List[Any]			=	[F'- {name}: {repr(getattr(self      ,     snake_case				)				)}' for name in self.attributes]
													A__    :	Union[str, Any]			=	"""\n""".join(snake_case				)
													return F'{self.__class__.__name__}:\n{attributes_repr}'


							def     _UpperCamelCase							(      self   :    Union[str, Any]      ,     snake_case   :    List[str]      ,     snake_case   :    bool = False      ,     **snake_case   :    Tuple				):
													'''simple docstring'''





													os.makedirs(snake_case      ,     exist_ok=snake_case				)

													if push_to_hub:
																			A__    :	Dict			=	kwargs.pop("""commit_message"""      ,     snake_case				)
																			A__    :	int			=	kwargs.pop("""repo_id"""      ,     save_directory.split(os.path.sep				)[-1]				)
																			A__    :	str			=	self._create_repo(snake_case      ,     **snake_case				)
																			A__    :	int			=	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__    :	Any			=	[getattr(self      ,     snake_case				) for attribute_name in self.attributes]
																			A__    :	List[str]			=	[(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__    :	Optional[int]			=	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__    :	Tuple			=	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     _UpperCamelCase							(      cls   :    Any      ,     snake_case   :    Union[str, os.PathLike]      ,     snake_case   :    Optional[Union[str, os.PathLike]] = None      ,     snake_case   :    bool = False      ,     snake_case   :    bool = False      ,     snake_case   :    Optional[Union[str, bool]] = None      ,     snake_case   :    str = "main"      ,     **snake_case   :    Optional[Any]      ,     ):
													'''simple docstring'''





													A__    :	Dict			=	cache_dir
													A__    :	Union[str, Any]			=	force_download
													A__    :	List[str]			=	local_files_only
													A__    :	Any			=	revision

													A__    :	Optional[Any]			=	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__    :	Optional[int]			=	use_auth_token

													if token is not None:
																			# change to `token` in a follow-up PR
																			A__    :	Union[str, Any]			=	token

													A__    :	Any			=	cls._get_arguments_from_pretrained(snake_case      ,     **snake_case				)
													return cls(*snake_case				)


							@classmethod
							def     _UpperCamelCase							(      cls   :    List[str]      ,     snake_case   :    Optional[Any]="AutoProcessor"				):
													'''simple docstring'''





													if not isinstance(snake_case      ,     snake_case				):
																			A__    :	List[Any]			=	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__    :	Optional[Any]			=	auto_class


							@classmethod
							def     _UpperCamelCase							(      cls   :    List[str]      ,     snake_case   :    Dict      ,     **snake_case   :    int				):
													'''simple docstring'''





													A__    :	Union[str, Any]			=	[]
													for attribute_name in cls.attributes:
																			A__    :	Optional[int]			=	getattr(cls      ,     F'{attribute_name}_class'				)
																			if isinstance(snake_case      ,     snake_case				):
																									A__    :	Optional[Any]			=	tuple(getattr(snake_case      ,     snake_case				) if n is not None else None for n in class_name				)
																									A__    :	List[str]			=	kwargs.get("""use_fast"""      ,     snake_case				)
																									if use_fast and classes[1] is not None:
																															A__    :	List[str]			=	classes[1]
																									else:
																															A__    :	Any			=	classes[0]
																			else:
																									A__    :	Any			=	getattr(snake_case      ,     snake_case				)

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


							@property
							def     _UpperCamelCase							(      self   :    Dict				):
													'''simple docstring'''





													A__    :	Dict			=	getattr(self      ,     self.attributes[0]				)
													return getattr(snake_case      ,     """model_input_names"""      ,     snake_case				)




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



def   _lowerCAmelCase		(				UpperCAmelCase__							:       float,    UpperCAmelCase__							:       float,    UpperCAmelCase__							:       float   )		->list[int]:
						if hue < 0 or hue > 3_6_0:
												raise Exception("""hue should be between 0 and 360"""   )

						if saturation < 0 or saturation > 1:
												raise Exception("""saturation should be between 0 and 1"""   )

						if value < 0 or value > 1:
												raise Exception("""value should be between 0 and 1"""   )

						A__    :	int			=	value * saturation
						A__    :	Any			=	hue / 6_0
						A__    :	Any			=	chroma * (1 - abs(hue_section % 2 - 1   ))
						A__    :	Optional[Any]			=	value - chroma

						if hue_section >= 0 and hue_section <= 1:
												A__    :	Dict			=	round(2_5_5 * (chroma + match_value)   )
												A__    :	Optional[Any]			=	round(2_5_5 * (second_largest_component + match_value)   )
												A__    :	Any			=	round(2_5_5 * (match_value)   )
						elif hue_section > 1 and hue_section <= 2:
												A__    :	Optional[int]			=	round(2_5_5 * (second_largest_component + match_value)   )
												A__    :	Union[str, Any]			=	round(2_5_5 * (chroma + match_value)   )
												A__    :	Union[str, Any]			=	round(2_5_5 * (match_value)   )
						elif hue_section > 2 and hue_section <= 3:
												A__    :	Tuple			=	round(2_5_5 * (match_value)   )
												A__    :	List[str]			=	round(2_5_5 * (chroma + match_value)   )
												A__    :	Union[str, Any]			=	round(2_5_5 * (second_largest_component + match_value)   )
						elif hue_section > 3 and hue_section <= 4:
												A__    :	Any			=	round(2_5_5 * (match_value)   )
												A__    :	Dict			=	round(2_5_5 * (second_largest_component + match_value)   )
												A__    :	List[Any]			=	round(2_5_5 * (chroma + match_value)   )
						elif hue_section > 4 and hue_section <= 5:
												A__    :	Any			=	round(2_5_5 * (second_largest_component + match_value)   )
												A__    :	Dict			=	round(2_5_5 * (match_value)   )
												A__    :	Tuple			=	round(2_5_5 * (chroma + match_value)   )
						else:
												A__    :	Tuple			=	round(2_5_5 * (chroma + match_value)   )
												A__    :	Optional[int]			=	round(2_5_5 * (match_value)   )
												A__    :	str			=	round(2_5_5 * (second_largest_component + match_value)   )

						return [red, green, blue]




def   _lowerCAmelCase		(				UpperCAmelCase__							:       int,    UpperCAmelCase__							:       int,    UpperCAmelCase__							:       int   )		->list[float]:
						if red < 0 or red > 2_5_5:
												raise Exception("""red should be between 0 and 255"""   )

						if green < 0 or green > 2_5_5:
												raise Exception("""green should be between 0 and 255"""   )

						if blue < 0 or blue > 2_5_5:
												raise Exception("""blue should be between 0 and 255"""   )

						A__    :	int			=	red / 2_5_5
						A__    :	List[str]			=	green / 2_5_5
						A__    :	Optional[int]			=	blue / 2_5_5
						A__    :	Optional[int]			=	max(UpperCAmelCase__,    UpperCAmelCase__,    UpperCAmelCase__   )
						A__    :	Tuple			=	value - min(UpperCAmelCase__,    UpperCAmelCase__,    UpperCAmelCase__   )
						A__    :	Any			=	0 if value == 0 else chroma / value

						if chroma == 0:
												A__    :	Optional[Any]			=	0.0
						elif value == float_red:
												A__    :	Optional[Any]			=	6_0 * (0 + (float_green - float_blue) / chroma)
						elif value == float_green:
												A__    :	Tuple			=	6_0 * (2 + (float_blue - float_red) / chroma)
						else:
												A__    :	int			=	6_0 * (4 + (float_red - float_green) / chroma)

						A__    :	Optional[int]			=	(hue + 3_6_0) % 3_6_0

						return [hue, saturation, value]




def   _lowerCAmelCase		(				UpperCAmelCase__							:       list[float],    UpperCAmelCase__							:       list[float]   )		->bool:
						A__    :	Optional[Any]			=	abs(hsv_a[0] - hsv_a[0]   ) < 0.2
						A__    :	str			=	abs(hsv_a[1] - hsv_a[1]   ) < 0.002
						A__    :	Optional[int]			=	abs(hsv_a[2] - hsv_a[2]   ) < 0.002

						return check_hue and check_saturation and check_value






