




'''simple docstring'''







import copy
import os
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Dict, Mapping, Optional, Union


if TYPE_CHECKING:
   from ...processing_utils import ProcessorMixin
   from ...utils import TensorType

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


A     =logging.get_logger(__name__)

A     ={
    'google/owlvit-base-patch32': 'https://huggingface.co/google/owlvit-base-patch32/resolve/main/config.json',
    'google/owlvit-base-patch16': 'https://huggingface.co/google/owlvit-base-patch16/resolve/main/config.json',
    'google/owlvit-large-patch14': 'https://huggingface.co/google/owlvit-large-patch14/resolve/main/config.json',
}


class 			_a  (	__a ):
       __a				:     Optional[int]   				=					"""owlvit_text_model"""
       def __init__(	self						:	Tuple   ,				lowercase						:	Union[str, Any]=49_408   ,				lowercase						:	str=512   ,				lowercase						:	int=2_048   ,				lowercase						:	Optional[Any]=12   ,				lowercase						:	Any=8   ,				lowercase						:	Optional[int]=16   ,				lowercase						:	Union[str, Any]="quick_gelu"   ,				lowercase						:	Dict=1E-5   ,				lowercase						:	Tuple=0.0   ,				lowercase						:	str=0.02   ,				lowercase						:	Dict=1.0   ,				lowercase						:	str=0   ,				lowercase						:	List[str]=49_406   ,				lowercase						:	int=49_407   ,				**lowercase						:	List[Any]   ,				):



           '''simple docstring'''

           super().__init__(pad_token_id=lowercase   ,				bos_token_id=lowercase   ,				eos_token_id=lowercase   ,				**lowercase				)

           UpperCAmelCase			       =		vocab_size
           UpperCAmelCase			       =		hidden_size
           UpperCAmelCase			       =		intermediate_size
           UpperCAmelCase			       =		num_hidden_layers
           UpperCAmelCase			       =		num_attention_heads
           UpperCAmelCase			       =		max_position_embeddings
           UpperCAmelCase			       =		hidden_act
           UpperCAmelCase			       =		layer_norm_eps
           UpperCAmelCase			       =		attention_dropout
           UpperCAmelCase			       =		initializer_range
           UpperCAmelCase			       =		initializer_factor







       @classmethod
       def     A      (	cls						:	int   ,				lowercase						:	Union[str, os.PathLike]   ,				**lowercase						:	List[Any]				):



           '''simple docstring'''

           cls._set_token_in_kwargs(lowercase				)

           UpperCAmelCase       ,     UpperCAmelCase			       =		cls.get_config_dict(lowercase   ,				**lowercase				)

           # get the text config dict if we are loading from OwlViTConfig
           if config_dict.get('''model_type'''				) == "owlvit":
               UpperCAmelCase			       =		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 			_a  (	__a ):
       __a				:     Dict   				=					"""owlvit_vision_model"""
       def __init__(	self						:	Tuple   ,				lowercase						:	str=768   ,				lowercase						:	Dict=3_072   ,				lowercase						:	int=12   ,				lowercase						:	Tuple=12   ,				lowercase						:	Optional[int]=3   ,				lowercase						:	Optional[int]=768   ,				lowercase						:	Optional[int]=32   ,				lowercase						:	Union[str, Any]="quick_gelu"   ,				lowercase						:	Dict=1E-5   ,				lowercase						:	List[Any]=0.0   ,				lowercase						:	List[Any]=0.02   ,				lowercase						:	str=1.0   ,				**lowercase						:	str   ,				):



           '''simple docstring'''

           super().__init__(**lowercase				)

           UpperCAmelCase			       =		hidden_size
           UpperCAmelCase			       =		intermediate_size
           UpperCAmelCase			       =		num_hidden_layers
           UpperCAmelCase			       =		num_attention_heads
           UpperCAmelCase			       =		num_channels
           UpperCAmelCase			       =		image_size
           UpperCAmelCase			       =		patch_size
           UpperCAmelCase			       =		hidden_act
           UpperCAmelCase			       =		layer_norm_eps
           UpperCAmelCase			       =		attention_dropout
           UpperCAmelCase			       =		initializer_range
           UpperCAmelCase			       =		initializer_factor







       @classmethod
       def     A      (	cls						:	Optional[Any]   ,				lowercase						:	Union[str, os.PathLike]   ,				**lowercase						:	int				):



           '''simple docstring'''

           cls._set_token_in_kwargs(lowercase				)

           UpperCAmelCase       ,     UpperCAmelCase			       =		cls.get_config_dict(lowercase   ,				**lowercase				)

           # get the vision config dict if we are loading from OwlViTConfig
           if config_dict.get('''model_type'''				) == "owlvit":
               UpperCAmelCase			       =		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 			_a  (	__a ):
       __a				:     Dict   				=					"""owlvit"""
       __a				:     Optional[Any]   				=					True
       def __init__(	self						:	Tuple   ,				lowercase						:	Tuple=None   ,				lowercase						:	Optional[Any]=None   ,				lowercase						:	List[str]=512   ,				lowercase						:	Any=2.6592   ,				lowercase						:	List[Any]=True   ,				**lowercase						:	str   ,				):



           '''simple docstring'''

           super().__init__(**lowercase				)

           if text_config is None:
               UpperCAmelCase			       =		{}
               logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.'''				)

           if vision_config is None:
               UpperCAmelCase			       =		{}
               logger.info('''vision_config is None. initializing the OwlViTVisionConfig with default values.'''				)

           UpperCAmelCase			       =		OwlViTTextConfig(**lowercase				)
           UpperCAmelCase			       =		OwlViTVisionConfig(**lowercase				)

           UpperCAmelCase			       =		projection_dim
           UpperCAmelCase			       =		logit_scale_init_value
           UpperCAmelCase			       =		return_dict
           UpperCAmelCase			       =		1.0
       @classmethod
       def     A      (	cls						:	Tuple   ,				lowercase						:	Union[str, os.PathLike]   ,				**lowercase						:	List[str]				):



           '''simple docstring'''

           cls._set_token_in_kwargs(lowercase				)

           UpperCAmelCase       ,     UpperCAmelCase			       =		cls.get_config_dict(lowercase   ,				**lowercase				)

           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				)
       @classmethod
       def     A      (	cls						:	List[str]   ,				lowercase						:	Dict   ,				lowercase						:	Dict   ,				**lowercase						:	Dict				):



           '''simple docstring'''

           UpperCAmelCase			       =		{}
           UpperCAmelCase			       =		text_config
           UpperCAmelCase			       =		vision_config

           return cls.from_dict(lowercase   ,				**lowercase				)







       def     A      (	self						:	Dict				):



           '''simple docstring'''

           UpperCAmelCase			       =		copy.deepcopy(self.__dict__				)
           UpperCAmelCase			       =		self.text_config.to_dict()
           UpperCAmelCase			       =		self.vision_config.to_dict()
           UpperCAmelCase			       =		self.__class__.model_type
           return output






class 			_a  (	__a ):
       @property
       def     A      (	self						:	Optional[Any]				):



           '''simple docstring'''

           return OrderedDict(
               [
                   ('''input_ids''', {0: '''batch''', 1: '''sequence'''}),
                   ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
                   ('''attention_mask''', {0: '''batch''', 1: '''sequence'''}),
               ]				)
       @property
       def     A      (	self						:	str				):



           '''simple docstring'''

           return OrderedDict(
               [
                   ('''logits_per_image''', {0: '''batch'''}),
                   ('''logits_per_text''', {0: '''batch'''}),
                   ('''text_embeds''', {0: '''batch'''}),
                   ('''image_embeds''', {0: '''batch'''}),
               ]				)
       @property
       def     A      (	self						:	Any				):



           '''simple docstring'''

           return 1E-4
       def     A      (	self						:	Tuple   ,				lowercase						:	"ProcessorMixin"   ,				lowercase						:	int = -1   ,				lowercase						:	int = -1   ,				lowercase						:	Optional["TensorType"] = None   ,				):



           '''simple docstring'''

           UpperCAmelCase			       =		super().generate_dummy_inputs(
               processor.tokenizer   ,				batch_size=lowercase   ,				seq_length=lowercase   ,				framework=lowercase				)
           UpperCAmelCase			       =		super().generate_dummy_inputs(
               processor.image_processor   ,				batch_size=lowercase   ,				framework=lowercase				)
           return {**text_input_dict, **image_input_dict}







       @property
       def     A      (	self						:	List[Any]				):



           '''simple docstring'''

           return 14










"""simple docstring"""


import argparse
import hashlib  # hashlib is only used inside the Test class
import struct






class 					lowercase:







 '''simple docstring'''





 def __init__(				self:		List[Any],      a_:		List[str]		):




   '''simple docstring'''



   _snake_case							:		int								=  data
   _snake_case							:		Dict								=  [0X67452301, 0Xefcdab89, 0X98badcfe, 0X10325476, 0Xc3d2e1f0]


 @staticmethod
 def  UpperCamelCase_   (				a_:		Optional[Any],      a_:		Dict		):




   '''simple docstring'''



   return ((n << b) | (n >> (32 - b))) & 0Xffffffff


 def  UpperCamelCase_   (				self:		List[Any]		):




   '''simple docstring'''



   _snake_case							:		Union[str, Any]								=  B"""\x80""" + B"""\x00""" * (63 - (len(self.data		) + 8) % 64)
   _snake_case							:		Optional[int]								=  self.data + padding + struct.pack(""">Q""",      8 * len(self.data		)		)
   return padded_data


 def  UpperCamelCase_   (				self:		Union[str, Any]		):




   '''simple docstring'''



   return [
       self.padded_data[i : i + 64] for i in range(0,      len(self.padded_data		),      64		)
   ]


 def  UpperCamelCase_   (				self:		Optional[Any],      a_:		List[Any]		):




   '''simple docstring'''



   _snake_case							:		List[str]								=  list(struct.unpack(""">16L""",      a_		)		) + [0] * 64
   for i in range(16,      80		):
     _snake_case							:		List[Any]								=  self.rotate((w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]),      1		)
   return w


 def  UpperCamelCase_   (				self:		int		):




   '''simple docstring'''



   _snake_case							:		Union[str, Any]								=  self.padding()
   _snake_case							:		str								=  self.split_blocks()
   for block in self.blocks:
     _snake_case							:		Any								=  self.expand_block(a_		)
     _snake_case		,					_snake_case		,					_snake_case		,					_snake_case		,					_snake_case							:		Optional[int]								=  self.h
     for i in range(0,      80		):
       if 0 <= i < 20:
         _snake_case							:		int								=  (b & c) | ((~b) & d)
         _snake_case							:		str								=  0X5a827999
       elif 20 <= i < 40:
         _snake_case							:		Optional[int]								=  b ^ c ^ d
         _snake_case							:		str								=  0X6ed9eba1
       elif 40 <= i < 60:
         _snake_case							:		List[Any]								=  (b & c) | (b & d) | (c & d)
         _snake_case							:		List[Any]								=  0X8f1bbcdc
       elif 60 <= i < 80:
         _snake_case							:		List[Any]								=  b ^ c ^ d
         _snake_case							:		int								=  0Xca62c1d6
       _snake_case		,					_snake_case		,					_snake_case		,					_snake_case		,					_snake_case							:		Optional[int]								=  (
           self.rotate(a_,      5		) + f + e + k + expanded_block[i] & 0Xffffffff,
           a,
           self.rotate(a_,      30		),
           c,
           d,
       )
     _snake_case							:		Union[str, Any]								=  (
         self.h[0] + a & 0Xffffffff,
         self.h[1] + b & 0Xffffffff,
         self.h[2] + c & 0Xffffffff,
         self.h[3] + d & 0Xffffffff,
         self.h[4] + e & 0Xffffffff,
     )
   return ("{:08x}" * 5).format(*self.h		)







def 					UpperCAmelCase__       ():
  """simple docstring"""

  _snake_case							:		Any								=  B"""Test String"""
  assert SHAaHash(snake_case__    ).final_hash() == hashlib.shaa(snake_case__    ).hexdigest()  # noqa: S324


def 					UpperCAmelCase__       ():
  """simple docstring"""

  _snake_case							:		List[Any]								=  argparse.ArgumentParser(description="""Process some strings or files"""    )
  parser.add_argument(
      """--string"""		,   dest="""input_string"""		,   default="""Hello World!! Welcome to Cryptography"""		,   help="""Hash the string"""		,   )
  parser.add_argument("""--file"""		,   dest="""input_file"""		,   help="""Hash contents of a file"""    )
  _snake_case							:		Union[str, Any]								=  parser.parse_args()
  _snake_case							:		List[Any]								=  args.input_string
  # In any case hash input should be a bytestring
  if args.input_file:
    with open(args.input_file		,   """rb"""    ) as f:
      _snake_case							:		str								=  f.read()
  else:
    _snake_case							:		int								=  bytes(snake_case__		,   """utf-8"""    )
  print(SHAaHash(snake_case__    ).final_hash()    )


if __name__ == "__main__":
     main()
     import doctest

     doctest.testmod()


