






"""simple docstring"""






import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCAmelCase_   : Optional[Any]   			= logging.get_logger(__name__)

UpperCAmelCase_   : Optional[Any]   			= {
    """Salesforce/blip-vqa-base""": """https://huggingface.co/Salesforce/blip-vqa-base/resolve/main/config.json""",
    """Salesforce/blip-vqa-capfit-large""": (
        """https://huggingface.co/Salesforce/blip-vqa-base-capfit/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-base""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-base/resolve/main/config.json"""
    ),
    """Salesforce/blip-image-captioning-large""": (
        """https://huggingface.co/Salesforce/blip-image-captioning-large/resolve/main/config.json"""
    ),
    """Salesforce/blip-itm-base-coco""": """https://huggingface.co/Salesforce/blip-itm-base-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-large-coco""": """https://huggingface.co/Salesforce/blip-itm-large-coco/resolve/main/config.json""",
    """Salesforce/blip-itm-base-flikr""": """https://huggingface.co/Salesforce/blip-itm-base-flikr/resolve/main/config.json""",
    """Salesforce/blip-itm-large-flikr""": (
        """https://huggingface.co/Salesforce/blip-itm-large-flikr/resolve/main/config.json"""
    ),
}




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      __UpperCamelCase	 =  "blip_text_model"
      def __init__(						self     :  Tuple						,	lowercase_     :  str=30524						,	lowercase_     :  Union[str, Any]=768						,	lowercase_     :  Optional[Any]=768						,	lowercase_     :  Dict=3072						,	lowercase_     :  Optional[Any]=768						,	lowercase_     :  Any=12						,	lowercase_     :  Dict=8						,	lowercase_     :  str=512						,	lowercase_     :  Any="gelu"						,	lowercase_     :  str=1e-12						,	lowercase_     :  List[str]=0.0						,	lowercase_     :  Any=0.0						,	lowercase_     :  List[str]=0.02						,	lowercase_     :  int=30522						,	lowercase_     :  Any=2						,	lowercase_     :  Optional[int]=0						,	lowercase_     :  Union[str, Any]=102						,	lowercase_     :  Optional[Any]=True						,	lowercase_     :  str=True						,	**lowercase_     :  Optional[Any]						,	):




          '''simple docstring'''


          super().__init__(
              pad_token_id=lowercase_						,	bos_token_id=lowercase_						,	eos_token_id=lowercase_						,	sep_token_id=lowercase_						,	**lowercase_						,	)

          SCREAMING_SNAKE_CASE_      :  List[str]    						=		vocab_size
          SCREAMING_SNAKE_CASE_      :  Any    						=		hidden_size
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		encoder_hidden_size
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		intermediate_size
          SCREAMING_SNAKE_CASE_      :  str    						=		projection_dim
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		hidden_dropout_prob
          SCREAMING_SNAKE_CASE_      :  str    						=		num_hidden_layers
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		num_attention_heads
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		max_position_embeddings
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		layer_norm_eps
          SCREAMING_SNAKE_CASE_      :  int    						=		hidden_act
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		initializer_range
          SCREAMING_SNAKE_CASE_      :  str    						=		attention_probs_dropout_prob
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		is_decoder
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		use_cache



      @classmethod
      def _SCREAMING_SNAKE_CASE (						cls     :  Optional[Any]						,	lowercase_     :  Union[str, os.PathLike]						,	**lowercase_     :  Any):




          '''simple docstring'''


          cls._set_token_in_kwargs(lowercase_)

          SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_      :  str    						=		cls.get_config_dict(lowercase_						,	**lowercase_)

          # get the text config dict if we are loading from BlipConfig
          if config_dict.get('''model_type''') == "blip":
              SCREAMING_SNAKE_CASE_      :  str    						=		config_dict['''text_config''']

          if "model_type" in config_dict and hasattr(cls						,	'''model_type''') and config_dict["model_type"] != cls.model_type:
              logger.warning(
                  F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                  F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.')

          return cls.from_dict(lowercase_						,	**lowercase_)




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      __UpperCamelCase	 =  "blip_vision_model"
      def __init__(						self     :  Optional[Any]						,	lowercase_     :  Tuple=768						,	lowercase_     :  Tuple=3072						,	lowercase_     :  Tuple=512						,	lowercase_     :  int=12						,	lowercase_     :  Optional[int]=12						,	lowercase_     :  List[Any]=384						,	lowercase_     :  List[str]=16						,	lowercase_     :  Any="gelu"						,	lowercase_     :  Optional[int]=1e-5						,	lowercase_     :  List[str]=0.0						,	lowercase_     :  List[str]=1e-10						,	**lowercase_     :  Dict						,	):




          '''simple docstring'''


          super().__init__(**lowercase_)

          SCREAMING_SNAKE_CASE_      :  Tuple    						=		hidden_size
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		intermediate_size
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		projection_dim
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		num_hidden_layers
          SCREAMING_SNAKE_CASE_      :  Any    						=		num_attention_heads
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		patch_size
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		image_size
          SCREAMING_SNAKE_CASE_      :  Tuple    						=		initializer_range
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		attention_dropout
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		layer_norm_eps
          SCREAMING_SNAKE_CASE_      :  Dict    						=		hidden_act



      @classmethod
      def _SCREAMING_SNAKE_CASE (						cls     :  str						,	lowercase_     :  Union[str, os.PathLike]						,	**lowercase_     :  int):




          '''simple docstring'''


          cls._set_token_in_kwargs(lowercase_)

          SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		cls.get_config_dict(lowercase_						,	**lowercase_)

          # get the vision config dict if we are loading from BlipConfig
          if config_dict.get('''model_type''') == "blip":
              SCREAMING_SNAKE_CASE_      :  int    						=		config_dict['''vision_config''']

          if "model_type" in config_dict and hasattr(cls						,	'''model_type''') and config_dict["model_type"] != cls.model_type:
              logger.warning(
                  F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
                  F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.')

          return cls.from_dict(lowercase_						,	**lowercase_)




class 							lowerCAmelCase__				(			UpperCAmelCase__ ):






      '''simple docstring'''

      __UpperCamelCase	 =  "blip"
      __UpperCamelCase	 =  True
      def __init__(						self     :  List[Any]						,	lowercase_     :  str=None						,	lowercase_     :  List[str]=None						,	lowercase_     :  Tuple=512						,	lowercase_     :  Optional[Any]=2.65_92						,	lowercase_     :  Dict=256						,	**lowercase_     :  Tuple						,	):




          '''simple docstring'''


          super().__init__(**lowercase_)

          if text_config is None:
              SCREAMING_SNAKE_CASE_      :  Any    						=		{}
              logger.info('''`text_config` is `None`. Initializing the `BlipTextConfig` with default values.''')

          if vision_config is None:
              SCREAMING_SNAKE_CASE_      :  Dict    						=		{}
              logger.info('''`vision_config` is `None`. Initializing the `BlipVisionConfig` with default values.''')

          SCREAMING_SNAKE_CASE_      :  List[str]    						=		BlipTextConfig(**lowercase_)
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		BlipVisionConfig(**lowercase_)

          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		self.vision_config.hidden_size

          SCREAMING_SNAKE_CASE_      :  List[str]    						=		projection_dim
          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		logit_scale_init_value
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		1.0
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		0.02
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		image_text_hidden_size
      @classmethod
      def _SCREAMING_SNAKE_CASE (						cls     :  int						,	lowercase_     :  BlipTextConfig						,	lowercase_     :  BlipVisionConfig						,	**lowercase_     :  Any):




          '''simple docstring'''


          return cls(text_config=text_config.to_dict()						,	vision_config=vision_config.to_dict()						,	**lowercase_)



      def _SCREAMING_SNAKE_CASE (						self     :  Dict):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  int    						=		copy.deepcopy(self.__dict__)
          SCREAMING_SNAKE_CASE_      :  Optional[Any]    						=		self.text_config.to_dict()
          SCREAMING_SNAKE_CASE_      :  str    						=		self.vision_config.to_dict()
          SCREAMING_SNAKE_CASE_      :  Optional[int]    						=		self.__class__.model_type
          return output










"""simple docstring"""






from __future__ import annotations




class 							lowerCAmelCase__				:






      '''simple docstring'''

      def __init__(						self     :  Any						,	lowercase_     :  int = 0):




          '''simple docstring'''


          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		key
      def _SCREAMING_SNAKE_CASE (						self     :  Any						,	lowercase_     :  str						,	lowercase_     :  int):




          '''simple docstring'''


          assert isinstance(lowercase_						,	lowercase_) and isinstance(lowercase_						,	lowercase_)

          SCREAMING_SNAKE_CASE_      :  Dict    						=		key or self.__key or 1

          # make sure key is an appropriate size
          key %= 255

          return [chr(ord(lowercase_) ^ key) for ch in content]
      def _SCREAMING_SNAKE_CASE (						self     :  str						,	lowercase_     :  str						,	lowercase_     :  int):




          '''simple docstring'''


          assert isinstance(lowercase_						,	lowercase_) and isinstance(lowercase_						,	lowercase_)

          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		key or self.__key or 1

          # make sure key is an appropriate size
          key %= 255

          return [chr(ord(lowercase_) ^ key) for ch in content]
      def _SCREAMING_SNAKE_CASE (						self     :  Tuple						,	lowercase_     :  str						,	lowercase_     :  int = 0):




          '''simple docstring'''


          assert isinstance(lowercase_						,	lowercase_) and isinstance(lowercase_						,	lowercase_)

          SCREAMING_SNAKE_CASE_      :  int    						=		key or self.__key or 1

          # make sure key can be any size
          while key > 255:
              key -= 255

          # This will be returned
          SCREAMING_SNAKE_CASE_      :  List[str]    						=		''''''

          for ch in content:
              ans += chr(ord(lowercase_) ^ key)

          return ans
      def _SCREAMING_SNAKE_CASE (						self     :  int						,	lowercase_     :  str						,	lowercase_     :  int = 0):




          '''simple docstring'''


          assert isinstance(lowercase_						,	lowercase_) and isinstance(lowercase_						,	lowercase_)

          SCREAMING_SNAKE_CASE_      :  Union[str, Any]    						=		key or self.__key or 1

          # make sure key can be any size
          while key > 255:
              key -= 255

          # This will be returned
          SCREAMING_SNAKE_CASE_      :  List[Any]    						=		''''''

          for ch in content:
              ans += chr(ord(lowercase_) ^ key)

          return ans
      def _SCREAMING_SNAKE_CASE (						self     :  str						,	lowercase_     :  str						,	lowercase_     :  int = 0):




          '''simple docstring'''


          assert isinstance(lowercase_						,	lowercase_) and isinstance(lowercase_						,	lowercase_)

          try:
              with open(lowercase_) as fin, open('''encrypt.out'''						,	'''w+''') as fout:
                  # actual encrypt-process
                  for line in fin:
                      fout.write(self.encrypt_string(lowercase_						,	lowercase_))

          except OSError:
              return False

          return True



      def _SCREAMING_SNAKE_CASE (						self     :  Optional[int]						,	lowercase_     :  str						,	lowercase_     :  int):




          '''simple docstring'''


          assert isinstance(lowercase_						,	lowercase_) and isinstance(lowercase_						,	lowercase_)

          try:
              with open(lowercase_) as fin, open('''decrypt.out'''						,	'''w+''') as fout:
                  # actual encrypt-process
                  for line in fin:
                      fout.write(self.decrypt_string(lowercase_						,	lowercase_))

          except OSError:
              return False

          return True


# Tests
# crypt = XORCipher()
# key = 67

# # test encrypt
# print(crypt.encrypt("hallo welt",key))
# # test decrypt
# print(crypt.decrypt(crypt.encrypt("hallo welt",key), key))

# # test encrypt_string
# print(crypt.encrypt_string("hallo welt",key))

# # test decrypt_string
# print(crypt.decrypt_string(crypt.encrypt_string("hallo welt",key),key))

# if (crypt.encrypt_file("test.txt",key)):
#       print("encrypt successful")
# else:
#       print("encrypt unsuccessful")

# if (crypt.decrypt_file("encrypt.out",key)):
#       print("decrypt successful")
# else:
#       print("decrypt unsuccessful")


