




from typing import Optional, Tuple

import jax
import jax.numpy as jnp
from flax import linen as nn
from flax.core.frozen_dict import FrozenDict
from transformers import CLIPConfig, FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPVisionModule





def        __UpperCAmelCase						(							lowerCamelCase_ :     str  ,							lowerCamelCase_ :     List[Any]  ,							lowerCamelCase_ :     Optional[Any]=1E-12  )       ->  str:







			"""simple docstring"""





			SCREAMING_SNAKE_CASE_   : Any					  =      jnp.divide(emb_a.T  ,							jnp.clip(jnp.linalg.norm(lowerCamelCase_  ,							axis=1  )  ,							a_min=lowerCamelCase_  )  ).T
			SCREAMING_SNAKE_CASE_   : Any					  =      jnp.divide(emb_a.T  ,							jnp.clip(jnp.linalg.norm(lowerCamelCase_  ,							axis=1  )  ,							a_min=lowerCamelCase_  )  ).T
			return jnp.matmul(lowerCamelCase_  ,							norm_emb_a.T  )







class 				lowerCAmelCase_       (					nn.Module							):
				__a     :       CLIPConfig
				__a     :       jnp.dtype						=     jnp.floataa






				def 		snake_case	(			self ):
							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      FlaxCLIPVisionModule(self.config.vision_config )
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      nn.Dense(self.config.projection_dim      ,use_bias=snake_case__      ,dtype=self.dtype )

							SCREAMING_SNAKE_CASE_   : Optional[int]					  =      self.param('concept_embeds'      ,jax.nn.initializers.ones      ,(17, self.config.projection_dim) )
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      self.param(
							    'special_care_embeds'      ,jax.nn.initializers.ones      ,(3, self.config.projection_dim) )

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      self.param('concept_embeds_weights'      ,jax.nn.initializers.ones      ,(17,) )
							SCREAMING_SNAKE_CASE_   : Tuple					  =      self.param('special_care_embeds_weights'      ,jax.nn.initializers.ones      ,(3,) )






				def __call__(			self      ,snake_case__ ):
							SCREAMING_SNAKE_CASE_   : Tuple					  =      self.vision_model(snake_case__ )[1]
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      self.visual_projection(snake_case__ )

							SCREAMING_SNAKE_CASE_   : int					  =      jax_cosine_distance(snake_case__      ,self.special_care_embeds )
							SCREAMING_SNAKE_CASE_   : Any					  =      jax_cosine_distance(snake_case__      ,self.concept_embeds )

							# increase this value to create a stronger `nfsw` filter
							# at the cost of increasing the possibility of filtering benign image inputs
							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      0.0

							SCREAMING_SNAKE_CASE_   : Tuple					  =      special_cos_dist - self.special_care_embeds_weights[None, :] + adjustment
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      jnp.round(snake_case__      ,3 )
							SCREAMING_SNAKE_CASE_   : List[str]					  =      jnp.any(special_scores > 0      ,axis=1      ,keepdims=snake_case__ )
							# Use a lower threshold if an image has any special care concept
							SCREAMING_SNAKE_CASE_   : Dict					  =      is_special_care * 0.01

							SCREAMING_SNAKE_CASE_   : List[str]					  =      cos_dist - self.concept_embeds_weights[None, :] + special_adjustment
							SCREAMING_SNAKE_CASE_   : Dict					  =      jnp.round(snake_case__      ,3 )
							SCREAMING_SNAKE_CASE_   : Union[str, Any]					  =      jnp.any(concept_scores > 0      ,axis=1 )

							return has_nsfw_concepts







class 				lowerCAmelCase_       (					lowercase_							):
				__a     :       Union[str, Any]						=     CLIPConfig
				__a     :       Optional[int]						=     """clip_input"""
				__a     :       Any						=     FlaxStableDiffusionSafetyCheckerModule






				def __init__(			self      ,snake_case__      ,snake_case__ = None      ,snake_case__ = 0      ,snake_case__ = jnp.floataa      ,snake_case__ = True      ,**snake_case__      ,):







							if input_shape is None:
										SCREAMING_SNAKE_CASE_   : Dict					  =      (1, 224, 224, 3)
							SCREAMING_SNAKE_CASE_   : List[str]					  =      self.module_class(config=snake_case__      ,dtype=snake_case__      ,**snake_case__ )
							super().__init__(snake_case__      ,snake_case__      ,input_shape=snake_case__      ,seed=snake_case__      ,dtype=snake_case__      ,_do_init=_do_init )






				def 		snake_case	(			self      ,snake_case__      ,snake_case__      ,snake_case__ = None ):
							SCREAMING_SNAKE_CASE_   : List[Any]					  =      jax.random.normal(snake_case__      ,snake_case__ )

							SCREAMING_SNAKE_CASE_  ,    SCREAMING_SNAKE_CASE_   : int					  =      jax.random.split(snake_case__ )
							SCREAMING_SNAKE_CASE_   : List[str]					  =      {'params': params_rng, 'dropout': dropout_rng}

							SCREAMING_SNAKE_CASE_   : Optional[Any]					  =      self.module.init(snake_case__      ,snake_case__ )['params']

							return random_params






				def __call__(			self      ,snake_case__      ,snake_case__ = None      ,):
							SCREAMING_SNAKE_CASE_   : str					  =      jnp.transpose(snake_case__      ,(0, 2, 3, 1) )

							return self.module.apply(
							    {'params': params or self.params}      ,jnp.array(snake_case__      ,dtype=jnp.floataa )      ,rngs={}      ,)







'''simple docstring'''

def _SCREAMING_SNAKE_CASE (A			)			->			bool:






       """simple docstring"""







       lowercase__      =					[int(A			) for i in ip_va_address.split('''.'''			) if i.isdigit()]
       return len(A			) == 4 and all(0 <= int(A			) <= 254 for octet in octets			)


if __name__ == "__main__":
 lowerCamelCase				:  Optional[Any]    		=      input().strip()
 lowerCamelCase				:  Union[str, Any]    		=      'valid' if is_ip_va_address_valid(ip) else 'invalid'
 print(f"""{ip} is a {valid_or_invalid} IP v4 address.""")




