






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


lowerCamelCase_					:			Union[str, Any]     						=				logging.get_logger(__name__)

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


lowerCamelCase_					:			Tuple     						=				{
    '''AutoTokenizer''': '''PreTrainedTokenizerBase''',
    '''AutoFeatureExtractor''': '''FeatureExtractionMixin''',
    '''AutoImageProcessor''': '''ImageProcessingMixin''',
}
class  _SCREAMING_SNAKE_CASE				(		SCREAMING_SNAKE_CASE						):


			'''simple docstring'''





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






			def __init__( self				:    List[str]			,   *lowercase				:    int			,   **lowercase				:    Dict      )				->     str:

									'''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:
																					UpperCamelCase__       =			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():
															UpperCamelCase__       =			getattr(self			,   f"{attribute_name}_class"      )
															# Nothing is ever going to be an instance of "AutoXxx", in that case we check the base class.
															UpperCamelCase__       =			AUTO_TO_BASE_CLASS_MAPPING.get(lowercase			,   lowercase      )
															if isinstance(lowercase			,   lowercase      ):
																					UpperCamelCase__       =			tuple(getattr(lowercase			,   lowercase      ) for n in class_name if n is not None      )
															else:
																					UpperCamelCase__       =			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[int]      )				->     Optional[int]:

									'''simple docstring'''







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






			def 					A   ( self				:    Optional[int]			,   lowercase				:    List[str]			,   lowercase				:    bool = False			,   **lowercase				:    str      )				->     Union[str, Any]:

									'''simple docstring'''







									os.makedirs(lowercase			,   exist_ok=lowercase      )

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

									'''simple docstring'''







									UpperCamelCase__       =			cache_dir
									UpperCamelCase__       =			force_download
									UpperCamelCase__       =			local_files_only
									UpperCamelCase__       =			revision

									UpperCamelCase__       =			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`."""      )
															UpperCamelCase__       =			use_auth_token

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

									UpperCamelCase__       =			cls._get_arguments_from_pretrained(lowercase			,   **lowercase      )
									return cls(*lowercase      )






			@classmethod
			def 					A   ( cls				:    Any			,   lowercase				:    List[Any]="AutoProcessor"      )				->     List[str]:

									'''simple docstring'''







									if not isinstance(lowercase			,   lowercase      ):
															UpperCamelCase__       =			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."      )

									UpperCamelCase__       =			auto_class






			@classmethod
			def 					A   ( cls				:    Any			,   lowercase				:    Any			,   **lowercase				:    List[str]      )				->     Dict:

									'''simple docstring'''







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

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







			@property
			def 					A   ( self				:    Tuple      )				->     List[Any]:

									'''simple docstring'''







									UpperCamelCase__       =			getattr(self			,   self.attributes[0]      )
									return getattr(lowercase			,   """model_input_names"""			,   lowercase      )
lowerCamelCase_					:			Tuple     						=				copy_func(ProcessorMixin.push_to_hub)
if ProcessorMixin.push_to_hub.__doc__ is not None:
					lowerCamelCase_					:			Optional[Any]     						=				ProcessorMixin.push_to_hub.__doc__.format(
					    object='''processor''', object_class='''AutoProcessor''', object_files='''processor files'''
					)








'''simple docstring'''


from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available
@dataclass
# Copied from diffusers.pipelines.stable_diffusion.__init__.StableDiffusionPipelineOutput with Stable->Alt
class  _SCREAMING_SNAKE_CASE				(		SCREAMING_SNAKE_CASE						):


			'''simple docstring'''





			__a				:				Union[List[PIL.Image.Image], np.ndarray]
			__a				:				Optional[List[bool]]


if is_transformers_available() and is_torch_available():
					from .modeling_roberta_series import RobertaSeriesModelWithTransformation
					from .pipeline_alt_diffusion import AltDiffusionPipeline
					from .pipeline_alt_diffusion_imgaimg import AltDiffusionImgaImgPipeline
