




from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType


class        UpperCamelCase_					(				lowercase__  ):

    '''simple docstring'''






    UpperCAmelCase__													=   ['''image_processor''', '''tokenizer''']
    UpperCAmelCase__													=   '''BlipImageProcessor'''
    UpperCAmelCase__													=   ('''BertTokenizer''', '''BertTokenizerFast''')


    def __init__(    self   :			str      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			Union[str, Any])		->Optional[Any]:





           '''simple docstring'''

           A__   				=					False
           super().__init__(UpperCAmelCase__      ,				UpperCAmelCase__)
           A__   				=					self.image_processor


    def __call__(    self   :			List[str]      ,				UpperCAmelCase__   :			ImageInput = None      ,				UpperCAmelCase__   :			Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None      ,				UpperCAmelCase__   :			bool = True      ,				UpperCAmelCase__   :			Union[bool, str, PaddingStrategy] = False      ,				UpperCAmelCase__   :			Union[bool, str, TruncationStrategy] = None      ,				UpperCAmelCase__   :			Optional[int] = None      ,				UpperCAmelCase__   :			int = 0      ,				UpperCAmelCase__   :			Optional[int] = None      ,				UpperCAmelCase__   :			Optional[bool] = None      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			bool = False      ,				UpperCAmelCase__   :			bool = True      ,				UpperCAmelCase__   :			Optional[Union[str, TensorType]] = None      ,				**UpperCAmelCase__   :			List[Any]      ,				)		->int:





           '''simple docstring'''

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

           # Get only text
           if images is None:
                  A__   				=					self.tokenizer
                  A__   				=					self.tokenizer(
                      text=UpperCAmelCase__      ,				add_special_tokens=UpperCAmelCase__      ,				padding=UpperCAmelCase__      ,				truncation=UpperCAmelCase__      ,				max_length=UpperCAmelCase__      ,				stride=UpperCAmelCase__      ,				pad_to_multiple_of=UpperCAmelCase__      ,				return_attention_mask=UpperCAmelCase__      ,				return_overflowing_tokens=UpperCAmelCase__      ,				return_special_tokens_mask=UpperCAmelCase__      ,				return_offsets_mapping=UpperCAmelCase__      ,				return_token_type_ids=UpperCAmelCase__      ,				return_length=UpperCAmelCase__      ,				verbose=UpperCAmelCase__      ,				return_tensors=UpperCAmelCase__      ,				**UpperCAmelCase__      ,				)
                  return text_encoding

           # add pixel_values
           A__   				=					self.image_processor(UpperCAmelCase__      ,				return_tensors=UpperCAmelCase__)

           if text is not None:
                  A__   				=					self.tokenizer(
                      text=UpperCAmelCase__      ,				add_special_tokens=UpperCAmelCase__      ,				padding=UpperCAmelCase__      ,				truncation=UpperCAmelCase__      ,				max_length=UpperCAmelCase__      ,				stride=UpperCAmelCase__      ,				pad_to_multiple_of=UpperCAmelCase__      ,				return_attention_mask=UpperCAmelCase__      ,				return_overflowing_tokens=UpperCAmelCase__      ,				return_special_tokens_mask=UpperCAmelCase__      ,				return_offsets_mapping=UpperCAmelCase__      ,				return_token_type_ids=UpperCAmelCase__      ,				return_length=UpperCAmelCase__      ,				verbose=UpperCAmelCase__      ,				return_tensors=UpperCAmelCase__      ,				**UpperCAmelCase__      ,				)
           else:
                  A__   				=					None

           if text_encoding is not None:
                  encoding_image_processor.update(UpperCAmelCase__)

           return encoding_image_processor


    def  SCREAMING_SNAKE_CASE							(    self   :			Union[str, Any]      ,				*UpperCAmelCase__   :			int      ,				**UpperCAmelCase__   :			Any)		->str:





           '''simple docstring'''

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


    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple      ,				*UpperCAmelCase__   :			List[Any]      ,				**UpperCAmelCase__   :			Tuple)		->List[str]:





           '''simple docstring'''

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





    @property
    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Any:





           '''simple docstring'''

           A__   				=					self.tokenizer.model_input_names
           A__   				=					self.image_processor.model_input_names
           return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))








from argparse import ArgumentParser

from . import BaseTransformersCLICommand







def SCREAMING_SNAKE_CASE       ( lowercase_		)     -> str:



       """simple docstring"""

       return DownloadCommand(args.model				,       args.cache_dir				,       args.force				,       args.trust_remote_code		)


class        UpperCamelCase_					(				UpperCAmelCase__  ):

    '''simple docstring'''






    @staticmethod
    def  SCREAMING_SNAKE_CASE							(    UpperCAmelCase__   :			ArgumentParser)		->Any:





           '''simple docstring'''

           A__   				=					parser.add_parser('''download''')
           download_parser.add_argument(
               '''--cache-dir'''      ,				type=UpperCAmelCase__      ,				default=UpperCAmelCase__      ,				help='''Path to location to store the models''')
           download_parser.add_argument(
               '''--force'''      ,				action='''store_true'''      ,				help='''Force the model to be download even if already in cache-dir''')
           download_parser.add_argument(
               '''--trust-remote-code'''      ,				action='''store_true'''      ,				help='''Whether or not to allow for custom models defined on the Hub in their own modeling files. Use only if you\'ve reviewed the code as it will execute on your local machine'''      ,				)
           download_parser.add_argument('''model'''      ,				type=UpperCAmelCase__      ,				help='''Name of the model to download''')
           download_parser.set_defaults(func=UpperCAmelCase__)


    def __init__(    self   :			Dict      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			bool      ,				UpperCAmelCase__   :			bool)		->int:





           '''simple docstring'''

           A__   				=					model
           A__   				=					cache
           A__   				=					force
           A__   				=					trust_remote_code





    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Union[str, Any]:





           '''simple docstring'''

           from ..models.auto import AutoModel, AutoTokenizer

           AutoModel.from_pretrained(
               self._model      ,				cache_dir=self._cache      ,				force_download=self._force      ,				trust_remote_code=self._trust_remote_code)
           AutoTokenizer.from_pretrained(
               self._model      ,				cache_dir=self._cache      ,				force_download=self._force      ,				trust_remote_code=self._trust_remote_code)


