


# Copyright 2021 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.

import argparse

from ...utils.dataclasses import (
    ComputeEnvironment,
    DistributedType,
    DynamoBackend,
    PrecisionType,
    SageMakerDistributedType,
)
from ..menu import BulletMenu


snake_case_						:			Any													=							[
    '''EAGER''',
    '''AOT_EAGER''',
    '''INDUCTOR''',
    '''NVFUSER''',
    '''AOT_NVFUSER''',
    '''AOT_CUDAGRAPHS''',
    '''OFI''',
    '''FX2TRT''',
    '''ONNXRT''',
    '''IPEX''',
]







def 						lowerCamelCase(   a__	,a__=None	,a__=None	,a__=None):
				_SCREAMING_SNAKE_CASE			  =True
				while ask_again:
								_SCREAMING_SNAKE_CASE			  =input(a__)
								try:
												if default is not None and len(a__) == 0:
																return default
												return convert_value(a__) if convert_value is not None else result
								except Exception:
												if error_message is not None:
																print(a__)







def 						lowerCamelCase(   a__	,a__=[]	,a__=None	,a__=0):
				_SCREAMING_SNAKE_CASE			  =BulletMenu(a__	,a__)
				_SCREAMING_SNAKE_CASE			  =menu.run(default_choice=a__)
				return convert_value(a__) if convert_value is not None else result







def 						lowerCamelCase(   a__):
				_SCREAMING_SNAKE_CASE			  =int(a__)
				return ComputeEnvironment(['''LOCAL_MACHINE''', '''AMAZON_SAGEMAKER'''][value])







def 						lowerCamelCase(   a__):
				_SCREAMING_SNAKE_CASE			  =int(a__)
				return DistributedType(['''NO''', '''MULTI_CPU''', '''MULTI_XPU''', '''MULTI_GPU''', '''MULTI_NPU''', '''TPU'''][value])







def 						lowerCamelCase(   a__):
				_SCREAMING_SNAKE_CASE			  =int(a__)
				return DynamoBackend(DYNAMO_BACKENDS[value]).value







def 						lowerCamelCase(   a__):
				_SCREAMING_SNAKE_CASE			  =int(a__)
				return PrecisionType(['''no''', '''fp16''', '''bf16''', '''fp8'''][value])







def 						lowerCamelCase(   a__):
				_SCREAMING_SNAKE_CASE			  =int(a__)
				return SageMakerDistributedType(['''NO''', '''DATA_PARALLEL''', '''MODEL_PARALLEL'''][value])







def 						lowerCamelCase(   a__):
				return {"yes": True, "no": False}[value.lower()]


class 						A__							(		argparse.RawDescriptionHelpFormatter  ):




						def 							__UpperCamelCase				(       self					:      Optional[int]				,    _a					:      List[str]				,    _a					:      Union[str, Any]				,    _a					:      List[Any]				,    _a					:      Dict  )							->     Any:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =super()._format_usage(_a				,    _a				,    _a				,    _a  )
										_SCREAMING_SNAKE_CASE			  =usage.replace('''<command> [<args>] '''				,    ''''''  )
										return usage



import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding

class 						A__							(		UpperCamelCase__  ):
						UpperCAmelCase             =						["image_processor", "tokenizer"]
						UpperCAmelCase             =						"ViTImageProcessor"
						UpperCAmelCase             =						("CLIPTokenizer", "CLIPTokenizerFast")




						def __init__(       self					:      int				,    _a					:      int=None				,    _a					:      Optional[int]=None				,    **_a					:      str  )							->     List[str]:


										"""simple docstring"""





										_SCREAMING_SNAKE_CASE			  =None
										if "feature_extractor" in kwargs:
														warnings.warn(
														    '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
														    ''' instead.'''				,    _a				,    )
														_SCREAMING_SNAKE_CASE			  =kwargs.pop('''feature_extractor'''  )

										_SCREAMING_SNAKE_CASE			  =image_processor if image_processor is not None else feature_extractor
										if image_processor is None:
														raise ValueError('''You need to specify an `image_processor`.'''  )
										if tokenizer is None:
														raise ValueError('''You need to specify a `tokenizer`.'''  )

										super().__init__(_a				,    _a  )




						def __call__(       self					:      List[str]				,    _a					:      Tuple=None				,    _a					:      Optional[Any]=None				,    _a					:      List[Any]=None				,    _a					:      List[Any]=None				,    **_a					:      List[Any]  )							->     Optional[Any]:


										"""simple docstring"""





										if text is None and visual_prompt is None and images is None:
														raise ValueError('''You have to specify either text, visual prompt or images.'''  )

										if text is not None and visual_prompt is not None:
														raise ValueError('''You have to specify exactly one type of prompt. Either text or visual prompt.'''  )

										if text is not None:
														_SCREAMING_SNAKE_CASE			  =self.tokenizer(_a				,    return_tensors=_a				,    **_a  )

										if visual_prompt is not None:
														_SCREAMING_SNAKE_CASE			  =self.image_processor(_a				,    return_tensors=_a				,    **_a  )

										if images is not None:
														_SCREAMING_SNAKE_CASE			  =self.image_processor(_a				,    return_tensors=_a				,    **_a  )

										if visual_prompt is not None and images is not None:
														_SCREAMING_SNAKE_CASE			  ={
														    '''pixel_values''': image_features.pixel_values,
														    '''conditional_pixel_values''': prompt_features.pixel_values,
														}
														return encoding
										elif text is not None and images is not None:
														_SCREAMING_SNAKE_CASE			  =image_features.pixel_values
														return encoding
										elif text is not None:
														return encoding
										elif visual_prompt is not None:
														_SCREAMING_SNAKE_CASE			  ={
														    '''conditional_pixel_values''': prompt_features.pixel_values,
														}
														return encoding
										else:
														return BatchEncoding(data=dict(**_a  )				,    tensor_type=_a  )




						def 							__UpperCamelCase				(       self					:      Any				,    *_a					:      str				,    **_a					:      List[Any]  )							->     Tuple:


										"""simple docstring"""





										return self.tokenizer.batch_decode(*_a				,    **_a  )




						def 							__UpperCamelCase				(       self					:      Dict				,    *_a					:      str				,    **_a					:      List[Any]  )							->     List[Any]:


										"""simple docstring"""





										return self.tokenizer.decode(*_a				,    **_a  )




						@property
						def 							__UpperCamelCase				(       self					:      Optional[int]  )							->     int:


										"""simple docstring"""





										warnings.warn(
										    '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'''				,    _a				,    )
										return self.image_processor_class




						@property
						def 							__UpperCamelCase				(       self					:      Optional[Any]  )							->     Union[str, Any]:


										"""simple docstring"""





										warnings.warn(
										    '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'''				,    _a				,    )
										return self.image_processor