






import numpy as np
import torch
import torch.nn as nn
from transformers import CLIPConfig, CLIPVisionModelWithProjection, PreTrainedModel

from ...utils import logging


UpperCAmelCase__							  =						logging.get_logger(__name__)






class 						lowercase_   (      lowercase  ):






      '''simple docstring'''




      __snake_case	    =    CLIPConfig

      __snake_case	    =    ['''CLIPEncoderLayer''']







      def __init__( self :		Tuple					,   __UpperCAmelCase :		CLIPConfig    )       ->Dict:




       """simple docstring"""


       super().__init__(__UpperCAmelCase    )

       a						    = CLIPVisionModelWithProjection(config.vision_config    )

       a						    = nn.Linear(config.vision_config.projection_dim					,   1    )
       a						    = nn.Linear(config.vision_config.projection_dim					,   1    )







      @torch.no_grad()
      def  __lowerCAmelCase   ( self :		Optional[int]					,   __UpperCAmelCase :		Union[str, Any]					,   __UpperCAmelCase :		Optional[int]					,   __UpperCAmelCase :		Union[str, Any]=0.5					,   __UpperCAmelCase :		str=0.5    )       ->Union[str, Any]:




       """simple docstring"""


       a						    = self.vision_model(__UpperCAmelCase    )[0]

       a						    = self.p_head(__UpperCAmelCase    )
       a						    = nsfw_detected.flatten()
       a						    = nsfw_detected > p_threshold
       a						    = nsfw_detected.tolist()

       if any(__UpperCAmelCase    ):
        logger.warning(
            '''Potential NSFW content was detected in one or more images. A black image will be returned instead.'''
            ''' Try again with a different prompt and/or seed.'''    )

       for idx, nsfw_detected_ in enumerate(__UpperCAmelCase    ):
        if nsfw_detected_:
         a						    = np.zeros(images[idx].shape    )

       a						    = self.w_head(__UpperCAmelCase    )
       a						    = watermark_detected.flatten()
       a						    = watermark_detected > w_threshold
       a						    = watermark_detected.tolist()

       if any(__UpperCAmelCase    ):
        logger.warning(
            '''Potential watermarked content was detected in one or more images. A black image will be returned instead.'''
            ''' Try again with a different prompt and/or seed.'''    )

       for idx, watermark_detected_ in enumerate(__UpperCAmelCase    ):
        if watermark_detected_:
         a						    = np.zeros(images[idx].shape    )

       return images, nsfw_detected, watermark_detected










from ... import PretrainedConfig


UpperCAmelCase__							  =						{
    "sijunhe/nezha-cn-base": "https://huggingface.co/sijunhe/nezha-cn-base/resolve/main/config.json",
}






class 						lowercase_   (      lowercase  ):






      '''simple docstring'''




      __snake_case	    =    NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP
      __snake_case	    =    '''nezha'''







      def __init__( self :		Union[str, Any]					,   __UpperCAmelCase :		List[str]=21_128					,   __UpperCAmelCase :		Any=768					,   __UpperCAmelCase :		int=12					,   __UpperCAmelCase :		Optional[int]=12					,   __UpperCAmelCase :		Tuple=3_072					,   __UpperCAmelCase :		Union[str, Any]="gelu"					,   __UpperCAmelCase :		List[str]=0.1					,   __UpperCAmelCase :		Any=0.1					,   __UpperCAmelCase :		str=512					,   __UpperCAmelCase :		List[Any]=64					,   __UpperCAmelCase :		Tuple=2					,   __UpperCAmelCase :		List[Any]=0.02					,   __UpperCAmelCase :		List[str]=1e-1_2					,   __UpperCAmelCase :		int=0.1					,   __UpperCAmelCase :		Dict=0					,   __UpperCAmelCase :		Any=2					,   __UpperCAmelCase :		Optional[Any]=3					,   __UpperCAmelCase :		int=True					,   **__UpperCAmelCase :		Optional[Any]					,   )       ->Any:




       """simple docstring"""


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

       a						    = vocab_size
       a						    = hidden_size
       a						    = num_hidden_layers
       a						    = num_attention_heads
       a						    = hidden_act
       a						    = intermediate_size
       a						    = hidden_dropout_prob
       a						    = attention_probs_dropout_prob
       a						    = max_position_embeddings
       a						    = max_relative_position
       a						    = type_vocab_size
       a						    = initializer_range
       a						    = layer_norm_eps
       a						    = classifier_dropout
       a						    = use_cache


