





"""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 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	"""owlvit_text_model"""

 def __init__(       self   ,		__lowerCamelCase=4_9408   ,		__lowerCamelCase=512   ,		__lowerCamelCase=2048   ,		__lowerCamelCase=12   ,		__lowerCamelCase=8   ,		__lowerCamelCase=16   ,		__lowerCamelCase="quick_gelu"   ,		__lowerCamelCase=1e-5   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0_2   ,		__lowerCamelCase=1.0   ,		__lowerCamelCase=0   ,		__lowerCamelCase=4_9406   ,		__lowerCamelCase=4_9407   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




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

     __A       :		str							=	vocab_size
     __A       :		List[str]							=	hidden_size
     __A       :		Tuple							=	intermediate_size
     __A       :		Dict							=	num_hidden_layers
     __A       :		Optional[int]							=	num_attention_heads
     __A       :		Dict							=	max_position_embeddings
     __A       :		Any							=	hidden_act
     __A       :		Any							=	layer_norm_eps
     __A       :		Optional[int]							=	attention_dropout
     __A       :		List[Any]							=	initializer_range
     __A       :		List[Any]							=	initializer_factor







 @classmethod
 def    UpperCamelCase__(       cls   ,		__lowerCamelCase   ,		**__lowerCamelCase    ):



     '''simple docstring'''




     cls._set_token_in_kwargs(__lowerCamelCase    )

     __A					,			__A       :		List[str]							=	cls.get_config_dict(__lowerCamelCase   ,		**__lowerCamelCase    )

     # get the text config dict if we are loading from OwlViTConfig
     if config_dict.get('''model_type'''    ) == "owlvit":
         __A       :		Optional[Any]							=	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(__lowerCamelCase   ,		**__lowerCamelCase    )






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	"""owlvit_vision_model"""

 def __init__(       self   ,		__lowerCamelCase=768   ,		__lowerCamelCase=3072   ,		__lowerCamelCase=12   ,		__lowerCamelCase=12   ,		__lowerCamelCase=3   ,		__lowerCamelCase=768   ,		__lowerCamelCase=32   ,		__lowerCamelCase="quick_gelu"   ,		__lowerCamelCase=1e-5   ,		__lowerCamelCase=0.0   ,		__lowerCamelCase=0.0_2   ,		__lowerCamelCase=1.0   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase    )

     __A       :		Dict							=	hidden_size
     __A       :		Any							=	intermediate_size
     __A       :		Tuple							=	num_hidden_layers
     __A       :		Union[str, Any]							=	num_attention_heads
     __A       :		int							=	num_channels
     __A       :		int							=	image_size
     __A       :		Tuple							=	patch_size
     __A       :		List[str]							=	hidden_act
     __A       :		str							=	layer_norm_eps
     __A       :		Union[str, Any]							=	attention_dropout
     __A       :		str							=	initializer_range
     __A       :		List[str]							=	initializer_factor







 @classmethod
 def    UpperCamelCase__(       cls   ,		__lowerCamelCase   ,		**__lowerCamelCase    ):



     '''simple docstring'''




     cls._set_token_in_kwargs(__lowerCamelCase    )

     __A					,			__A       :		Optional[int]							=	cls.get_config_dict(__lowerCamelCase   ,		**__lowerCamelCase    )

     # get the vision config dict if we are loading from OwlViTConfig
     if config_dict.get('''model_type'''    ) == "owlvit":
         __A       :		Optional[Any]							=	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(__lowerCamelCase   ,		**__lowerCamelCase    )






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 _lowerCamelCase								=	"""owlvit"""
 _lowerCamelCase								=	True

 def __init__(       self   ,		__lowerCamelCase=None   ,		__lowerCamelCase=None   ,		__lowerCamelCase=512   ,		__lowerCamelCase=2.6_5_9_2   ,		__lowerCamelCase=True   ,		**__lowerCamelCase   ,		):



     '''simple docstring'''




     super().__init__(**__lowerCamelCase    )

     if text_config is None:
         __A       :		List[str]							=	{}
         logger.info('''text_config is None. Initializing the OwlViTTextConfig with default values.'''    )

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

     __A       :		List[str]							=	OwlViTTextConfig(**__lowerCamelCase    )
     __A       :		Optional[int]							=	OwlViTVisionConfig(**__lowerCamelCase    )

     __A       :		str							=	projection_dim
     __A       :		str							=	logit_scale_init_value
     __A       :		Tuple							=	return_dict
     __A       :		Dict							=	1.0

 @classmethod
 def    UpperCamelCase__(       cls   ,		__lowerCamelCase   ,		**__lowerCamelCase    ):



     '''simple docstring'''




     cls._set_token_in_kwargs(__lowerCamelCase    )

     __A					,			__A       :		Any							=	cls.get_config_dict(__lowerCamelCase   ,		**__lowerCamelCase    )

     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(__lowerCamelCase   ,		**__lowerCamelCase    )

 @classmethod
 def    UpperCamelCase__(       cls   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		**__lowerCamelCase    ):



     '''simple docstring'''




     __A       :		int							=	{}
     __A       :		Union[str, Any]							=	text_config
     __A       :		int							=	vision_config

     return cls.from_dict(__lowerCamelCase   ,		**__lowerCamelCase    )







 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




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






class 						__snake_case   (						SCREAMING_SNAKE_CASE__	):





 """simple docstring"""


 @property
 def    UpperCamelCase__(       self    ):



     '''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    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return OrderedDict(
         [
             ('''logits_per_image''', {0: '''batch'''}),
             ('''logits_per_text''', {0: '''batch'''}),
             ('''text_embeds''', {0: '''batch'''}),
             ('''image_embeds''', {0: '''batch'''}),
         ]    )

 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return 1e-4

 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = -1   ,		__lowerCamelCase = None   ,		):



     '''simple docstring'''




     __A       :		Tuple							=	super().generate_dummy_inputs(
         processor.tokenizer   ,		batch_size=__lowerCamelCase   ,		seq_length=__lowerCamelCase   ,		framework=__lowerCamelCase    )
     __A       :		Optional[Any]							=	super().generate_dummy_inputs(
         processor.image_processor   ,		batch_size=__lowerCamelCase   ,		framework=__lowerCamelCase    )
     return {**text_input_dict, **image_input_dict}







 @property
 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return 14











"""simple docstring"""



def 						__lowercase	(  snake_case_    :    str							,snake_case_    :    str		)  ->float:



    '''simple docstring'''







    def get_matched_characters(snake_case_    :    str							,snake_case_    :    str		) -> str:
        __A       :		Any							=	[]
        __A       :		Any							=	min(len(_stra		)							,len(_stra		)		) // 2
        for i, l in enumerate(_stra		):
            __A       :		Dict							=	int(max(0							,i - limit		)		)
            __A       :		Tuple							=	int(min(i + limit + 1							,len(_stra		)		)		)
            if l in _stra[left:right]:
                matched.append(snake_case_		)
                __A       :		Any							=	F"""{_stra[0:_stra.index(snake_case_		)]} {_stra[_stra.index(snake_case_		) + 1:]}"""

        return "".join(snake_case_		)

    # matching characters
    __A       :		int							=	get_matched_characters(snake_case_							,snake_case_		)
    __A       :		Tuple							=	get_matched_characters(snake_case_							,snake_case_		)
    __A       :		str							=	len(snake_case_		)

    # transposition
    __A       :		Dict							=	(
        len([(ca, ca) for ca, ca in zip(snake_case_							,snake_case_		) if ca != ca]		) // 2
    )

    if not match_count:
        __A       :		List[str]							=	0.0
    else:
        __A       :		Tuple							=	(
            1
            / 3
            * (
                match_count / len(snake_case_		)
                + match_count / len(snake_case_		)
                + (match_count - transpositions) / match_count
            )
        )

    # common prefix up to 4 characters
    __A       :		Tuple							=	0
    for ca, ca in zip(stra[:4]							,stra[:4]		):
        if ca == ca:
            prefix_len += 1
        else:
            break

    return jaro + 0.1 * prefix_len * (1 - jaro)


if __name__ == "__main__":
       import doctest

       doctest.testmod()
       print(jaro_winkler("""hello""", """world"""))




