




"""simple docstring"""



# Copyright 2022 The HuggingFace Team and The OpenBMB 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.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


SCREAMING_SNAKE_CASE    =	{
    'configuration_cpmant': ['CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CpmAntConfig'],
    'tokenization_cpmant': ['CpmAntTokenizer'],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  SCREAMING_SNAKE_CASE    =	[
      'CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST',
      'CpmAntForCausalLM',
      'CpmAntModel',
      'CpmAntPreTrainedModel',
  ]


if TYPE_CHECKING:
  from .configuration_cpmant import CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP, CpmAntConfig
  from .tokenization_cpmant import CpmAntTokenizer

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_cpmant import (
        CPMANT_PRETRAINED_MODEL_ARCHIVE_LIST,
        CpmAntForCausalLM,
        CpmAntModel,
        CpmAntPreTrainedModel,
    )


else:
  import sys

  SCREAMING_SNAKE_CASE    =	_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)











"""simple docstring"""



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




class      UpperCAmelCase_  (						A_							):
    lowercase__						 =				['''image_processor''', '''tokenizer''']
    lowercase__						 =				'''AutoImageProcessor'''
    lowercase__						 =				'''AutoTokenizer'''




    def __init__(   self						:	str     ,			snake_case_						:	Dict     ,			snake_case_						:	List[str]				)				->							str:




     '''simple docstring'''

     super().__init__(snake_case_     ,			snake_case_				)
     A__	=    self.image_processor




    def __call__(   self						:	int     ,			snake_case_						:	Any=None     ,			snake_case_						:	Any=None     ,			snake_case_						:	Union[str, Any]=None     ,			**snake_case_						:	Optional[int]				)				->							Optional[int]:




     '''simple docstring'''

     if text is None and images is None:
      raise ValueError("You have to specify either text or images. Both cannot be none."				)

     if text is not None:
      A__	=    self.tokenizer(snake_case_     ,			return_tensors=snake_case_     ,			**snake_case_				)

     if images is not None:
      A__	=    self.image_processor(snake_case_     ,			return_tensors=snake_case_     ,			**snake_case_				)

     if text is not None and images is not None:
      A__	=    image_features.pixel_values
      return encoding
     elif text is not None:
      return encoding
     else:
      return BatchEncoding(data=dict(**snake_case_				)     ,			tensor_type=snake_case_				)




    def 							__magic_name__							(   self						:	Optional[int]     ,			*snake_case_						:	Union[str, Any]     ,			**snake_case_						:	List[Any]				)				->							int:




     '''simple docstring'''

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




    def 							__magic_name__							(   self						:	List[str]     ,			*snake_case_						:	List[str]     ,			**snake_case_						:	Optional[int]				)				->							Tuple:




     '''simple docstring'''

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




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




     '''simple docstring'''

     return ["input_ids", "attention_mask", "pixel_values"]





