import warnings
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 		_lowerCamelCase		(   UpperCamelCase_    ):
    __a  =      ["image_processor", "tokenizer"]
    __a  =      "FlavaImageProcessor"
    __a  =      ("BertTokenizer", "BertTokenizerFast")
    def __init__(  self , lowerCAmelCase=None , lowerCAmelCase=None , **lowerCAmelCase   )       ->					str:
     SCREAMING_SNAKE_CASE__:   List[Any]=      None
     if "feature_extractor" in kwargs:
      warnings.warn(
          '''The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'''
          ''' instead.''' , lowerCAmelCase , )
      SCREAMING_SNAKE_CASE__:   Optional[Any]=      kwargs.pop('''feature_extractor'''   )

     SCREAMING_SNAKE_CASE__:   str=      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__(lowerCAmelCase , lowerCAmelCase   )
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      self.image_processor
    def __call__(  self , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = True , lowerCAmelCase = False , lowerCAmelCase = False , lowerCAmelCase = None , lowerCAmelCase = 0 , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = None , lowerCAmelCase = False , lowerCAmelCase = False , lowerCAmelCase = False , lowerCAmelCase = False , lowerCAmelCase = True , lowerCAmelCase = None , **lowerCAmelCase , )       ->					List[Any]:

     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:
      SCREAMING_SNAKE_CASE__:   Any=      self.tokenizer(
          text=lowerCAmelCase , add_special_tokens=lowerCAmelCase , padding=lowerCAmelCase , truncation=lowerCAmelCase , max_length=lowerCAmelCase , stride=lowerCAmelCase , pad_to_multiple_of=lowerCAmelCase , return_token_type_ids=lowerCAmelCase , return_attention_mask=lowerCAmelCase , return_overflowing_tokens=lowerCAmelCase , return_special_tokens_mask=lowerCAmelCase , return_offsets_mapping=lowerCAmelCase , return_length=lowerCAmelCase , verbose=lowerCAmelCase , return_tensors=lowerCAmelCase , **lowerCAmelCase , )
     if images is not None:
      SCREAMING_SNAKE_CASE__:   Tuple=      self.image_processor(
          lowerCAmelCase , return_image_mask=lowerCAmelCase , return_codebook_pixels=lowerCAmelCase , return_tensors=lowerCAmelCase , **lowerCAmelCase , )

     if text is not None and images is not None:
      encoding.update(lowerCAmelCase   )
      return encoding
     elif text is not None:
      return encoding
     else:
      return BatchEncoding(data=dict(**lowerCAmelCase   ) , tensor_type=lowerCAmelCase   )
    def 						UpperCamelCase_				(  self , *lowerCAmelCase , **lowerCAmelCase   )       ->					Dict:
     return self.tokenizer.batch_decode(*lowerCAmelCase , **lowerCAmelCase   )
    def 						UpperCamelCase_				(  self , *lowerCAmelCase , **lowerCAmelCase   )       ->					Any:
     return self.tokenizer.decode(*lowerCAmelCase , **lowerCAmelCase   )
    @property
    def 						UpperCamelCase_				(  self   )       ->					Tuple:
     SCREAMING_SNAKE_CASE__:   List[str]=      self.tokenizer.model_input_names
     SCREAMING_SNAKE_CASE__:   str=      self.image_processor.model_input_names
     return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names   )   )
    @property
    def 						UpperCamelCase_				(  self   )       ->					Union[str, Any]:
     warnings.warn(
         '''`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.''' , lowerCAmelCase , )
     return self.image_processor_class



    @property
    def 						UpperCamelCase_				(  self   )       ->					Optional[Any]:
     warnings.warn(
         '''`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.''' , lowerCAmelCase , )
     return self.image_processor


import unittest

from diffusers.pipelines.pipeline_utils import is_safetensors_compatible






class 		_lowerCamelCase		(   unittest.TestCase    ):
    def 						UpperCamelCase_				(  self   )       ->					str:
     SCREAMING_SNAKE_CASE__:   List[Any]=      [
         '''safety_checker/pytorch_model.bin''',
         '''safety_checker/model.safetensors''',
         '''vae/diffusion_pytorch_model.bin''',
         '''vae/diffusion_pytorch_model.safetensors''',
         '''text_encoder/pytorch_model.bin''',
         '''text_encoder/model.safetensors''',
         '''unet/diffusion_pytorch_model.bin''',
         '''unet/diffusion_pytorch_model.safetensors''',
     ]
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					int:
     SCREAMING_SNAKE_CASE__:   List[str]=      [
         '''unet/diffusion_pytorch_model.bin''',
         '''unet/diffusion_pytorch_model.safetensors''',
     ]
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					Tuple:
     SCREAMING_SNAKE_CASE__:   Optional[int]=      [
         '''safety_checker/pytorch_model.bin''',
         '''safety_checker/model.safetensors''',
         '''vae/diffusion_pytorch_model.bin''',
         '''vae/diffusion_pytorch_model.safetensors''',
         '''text_encoder/pytorch_model.bin''',
         '''text_encoder/model.safetensors''',
         '''unet/diffusion_pytorch_model.bin''',
         # Removed: 'unet/diffusion_pytorch_model.safetensors',
     ]
     self.assertFalse(is_safetensors_compatible(lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					Dict:
     SCREAMING_SNAKE_CASE__:   str=      [
         '''text_encoder/pytorch_model.bin''',
         '''text_encoder/model.safetensors''',
     ]
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					str:
     SCREAMING_SNAKE_CASE__:   List[str]=      [
         '''safety_checker/pytorch_model.bin''',
         '''safety_checker/model.safetensors''',
         '''vae/diffusion_pytorch_model.bin''',
         '''vae/diffusion_pytorch_model.safetensors''',
         '''text_encoder/pytorch_model.bin''',
         # Removed: 'text_encoder/model.safetensors',
         '''unet/diffusion_pytorch_model.bin''',
         '''unet/diffusion_pytorch_model.safetensors''',
     ]
     self.assertFalse(is_safetensors_compatible(lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					List[str]:
     SCREAMING_SNAKE_CASE__:   Optional[int]=      [
         '''safety_checker/pytorch_model.fp16.bin''',
         '''safety_checker/model.fp16.safetensors''',
         '''vae/diffusion_pytorch_model.fp16.bin''',
         '''vae/diffusion_pytorch_model.fp16.safetensors''',
         '''text_encoder/pytorch_model.fp16.bin''',
         '''text_encoder/model.fp16.safetensors''',
         '''unet/diffusion_pytorch_model.fp16.bin''',
         '''unet/diffusion_pytorch_model.fp16.safetensors''',
     ]
     SCREAMING_SNAKE_CASE__:   Any=      '''fp16'''
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase , variant=lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					Any:
     SCREAMING_SNAKE_CASE__:   List[str]=      [
         '''unet/diffusion_pytorch_model.fp16.bin''',
         '''unet/diffusion_pytorch_model.fp16.safetensors''',
     ]
     SCREAMING_SNAKE_CASE__:   Dict=      '''fp16'''
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase , variant=lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					Dict:
     # pass variant but use the non-variant filenames
     SCREAMING_SNAKE_CASE__:   List[str]=      [
         '''unet/diffusion_pytorch_model.bin''',
         '''unet/diffusion_pytorch_model.safetensors''',
     ]
     SCREAMING_SNAKE_CASE__:   Union[str, Any]=      '''fp16'''
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase , variant=lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					List[Any]:
     SCREAMING_SNAKE_CASE__:   Dict=      [
         '''safety_checker/pytorch_model.fp16.bin''',
         '''safety_checker/model.fp16.safetensors''',
         '''vae/diffusion_pytorch_model.fp16.bin''',
         '''vae/diffusion_pytorch_model.fp16.safetensors''',
         '''text_encoder/pytorch_model.fp16.bin''',
         '''text_encoder/model.fp16.safetensors''',
         '''unet/diffusion_pytorch_model.fp16.bin''',
         # Removed: 'unet/diffusion_pytorch_model.fp16.safetensors',
     ]
     SCREAMING_SNAKE_CASE__:   List[Any]=      '''fp16'''
     self.assertFalse(is_safetensors_compatible(lowerCAmelCase , variant=lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					List[str]:
     SCREAMING_SNAKE_CASE__:   int=      [
         '''text_encoder/pytorch_model.fp16.bin''',
         '''text_encoder/model.fp16.safetensors''',
     ]
     SCREAMING_SNAKE_CASE__:   Any=      '''fp16'''
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase , variant=lowerCAmelCase   )   )
    def 						UpperCamelCase_				(  self   )       ->					Optional[Any]:
     # pass variant but use the non-variant filenames
     SCREAMING_SNAKE_CASE__:   Optional[int]=      [
         '''text_encoder/pytorch_model.bin''',
         '''text_encoder/model.safetensors''',
     ]
     SCREAMING_SNAKE_CASE__:   str=      '''fp16'''
     self.assertTrue(is_safetensors_compatible(lowerCAmelCase , variant=lowerCAmelCase   )   )



    def 						UpperCamelCase_				(  self   )       ->					Union[str, Any]:
     SCREAMING_SNAKE_CASE__:   Tuple=      [
         '''safety_checker/pytorch_model.fp16.bin''',
         '''safety_checker/model.fp16.safetensors''',
         '''vae/diffusion_pytorch_model.fp16.bin''',
         '''vae/diffusion_pytorch_model.fp16.safetensors''',
         '''text_encoder/pytorch_model.fp16.bin''',
         # 'text_encoder/model.fp16.safetensors',
         '''unet/diffusion_pytorch_model.fp16.bin''',
         '''unet/diffusion_pytorch_model.fp16.safetensors''',
     ]
     SCREAMING_SNAKE_CASE__:   str=      '''fp16'''
     self.assertFalse(is_safetensors_compatible(lowerCAmelCase , variant=lowerCAmelCase   )   )

