
import os
from typing import List, Optional, Union

from ...image_processing_utils import BatchFeature
from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType
from ..auto import AutoTokenizer






class        SCREAMING_SNAKE_CASE__    (							SCREAMING_SNAKE_CASE__    ):

							"""simple docstring"""






							_snake_case     		=  ['image_processor', 'tokenizer']
							_snake_case     		=  'BlipImageProcessor'
							_snake_case     		=  'AutoTokenizer'



							def __init__(  self     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_     ,	SCREAMING_SNAKE_CASE_			)->   int:





													'''simple docstring'''






													super().__init__(snake_case__     ,	snake_case__			)

													# add QFormer tokenizer
													__UpperCamelCase       =			qformer_tokenizer



							def __call__(  self     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = True     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = 0     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = None     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = False     ,	SCREAMING_SNAKE_CASE_ = True     ,	SCREAMING_SNAKE_CASE_ = None     ,	**SCREAMING_SNAKE_CASE_     ,	)->   List[Any]:





													'''simple docstring'''






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

													__UpperCamelCase       =			BatchFeature()

													if text is not None:
																			__UpperCamelCase       =			self.tokenizer(
																			    text=snake_case__     ,	add_special_tokens=snake_case__     ,	padding=snake_case__     ,	truncation=snake_case__     ,	max_length=snake_case__     ,	stride=snake_case__     ,	pad_to_multiple_of=snake_case__     ,	return_attention_mask=snake_case__     ,	return_overflowing_tokens=snake_case__     ,	return_special_tokens_mask=snake_case__     ,	return_offsets_mapping=snake_case__     ,	return_token_type_ids=snake_case__     ,	return_length=snake_case__     ,	verbose=snake_case__     ,	return_tensors=snake_case__     ,	**snake_case__     ,	)
																			encoding.update(snake_case__			)
																			__UpperCamelCase       =			self.qformer_tokenizer(
																			    text=snake_case__     ,	add_special_tokens=snake_case__     ,	padding=snake_case__     ,	truncation=snake_case__     ,	max_length=snake_case__     ,	stride=snake_case__     ,	pad_to_multiple_of=snake_case__     ,	return_attention_mask=snake_case__     ,	return_overflowing_tokens=snake_case__     ,	return_special_tokens_mask=snake_case__     ,	return_offsets_mapping=snake_case__     ,	return_token_type_ids=snake_case__     ,	return_length=snake_case__     ,	verbose=snake_case__     ,	return_tensors=snake_case__     ,	**snake_case__     ,	)
																			__UpperCamelCase       =			qformer_text_encoding.pop('''input_ids'''			)
																			__UpperCamelCase       =			qformer_text_encoding.pop('''attention_mask'''			)

													if images is not None:
																			__UpperCamelCase       =			self.image_processor(snake_case__     ,	return_tensors=snake_case__			)
																			encoding.update(snake_case__			)

													return encoding



							def     A__		(  self     ,	*SCREAMING_SNAKE_CASE_     ,	**SCREAMING_SNAKE_CASE_			)->   Dict:





													'''simple docstring'''






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



							def     A__		(  self     ,	*SCREAMING_SNAKE_CASE_     ,	**SCREAMING_SNAKE_CASE_			)->   Dict:





													'''simple docstring'''






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



							@property
							# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
							def     A__		(  self			)->   Dict:





													'''simple docstring'''






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



							def     A__		(  self     ,	SCREAMING_SNAKE_CASE_     ,	**SCREAMING_SNAKE_CASE_			)->   Optional[int]:





													'''simple docstring'''






													if os.path.isfile(snake_case__			):
																			raise ValueError(F"Provided path ({save_directory}) should be a directory, not a file"			)
													os.makedirs(snake_case__     ,	exist_ok=snake_case__			)
													__UpperCamelCase       =			os.path.join(snake_case__     ,	'''qformer_tokenizer'''			)
													self.qformer_tokenizer.save_pretrained(snake_case__			)
													return super().save_pretrained(snake_case__     ,	**snake_case__			)



							@classmethod
							def     A__		(  cls     ,	SCREAMING_SNAKE_CASE_     ,	**SCREAMING_SNAKE_CASE_			)->   str:





													'''simple docstring'''






													__UpperCamelCase       =			AutoTokenizer.from_pretrained(snake_case__     ,	subfolder='''qformer_tokenizer'''			)
													__UpperCamelCase       =			cls._get_arguments_from_pretrained(snake_case__     ,	**snake_case__			)
													args.append(snake_case__			)
													return cls(*snake_case__			)






# coding=utf-8
# Copyright 2023 The HuggingFace Inc. team.
#
# 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.

# this script dumps information about the environment

import os
import platform
import sys


lowercase__							:							List[str]									=			"3"

print("Python version:", sys.version)

print("OS platform:", platform.platform())
print("OS architecture:", platform.machine())

try:
				import torch

				print("Torch version:", torch.__version__)
				print("Cuda available:", torch.cuda.is_available())
				print("Cuda version:", torch.version.cuda)
				print("CuDNN version:", torch.backends.cudnn.version())
				print("Number of GPUs available:", torch.cuda.device_count())
except ImportError:
				print("Torch version:", None)

try:
				import transformers

				print("transformers version:", transformers.__version__)
except ImportError:
				print("transformers version:", None)




