


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

from ...utils import logging


_SCREAMING_SNAKE_CASE      :			str      				=   logging.get_logger(__name__)

class   A__ (   snake_case__     ):







    """simple docstring"""

    __magic_name__        =		CLIPConfig

    __magic_name__        =		['CLIPEncoderLayer']
    def __init__(	self      , __snake_case   ):
         super().__init__(__snake_case   )

         snake_case					=    CLIPVisionModelWithProjection(config.vision_config   )

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




    @torch.no_grad()
    def 		a_      (	self      , __snake_case      , __snake_case      , __snake_case=0.5      , __snake_case=0.5   ):
         snake_case					=    self.vision_model(__snake_case   )[0]

         snake_case					=    self.p_head(__snake_case   )
         snake_case					=    nsfw_detected.flatten()
         snake_case					=    nsfw_detected > p_threshold
         snake_case					=    nsfw_detected.tolist()

         if any(__snake_case   ):
              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(__snake_case   ):
              if nsfw_detected_:
                   snake_case					=    np.zeros(images[idx].shape   )

         snake_case					=    self.w_head(__snake_case   )
         snake_case					=    watermark_detected.flatten()
         snake_case					=    watermark_detected > w_threshold
         snake_case					=    watermark_detected.tolist()

         if any(__snake_case   ):
              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(__snake_case   ):
              if watermark_detected_:
                   snake_case					=    np.zeros(images[idx].shape   )

         return images, nsfw_detected, watermark_detected








from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


_SCREAMING_SNAKE_CASE      :			Dict      				=   {"configuration_van": ["VAN_PRETRAINED_CONFIG_ARCHIVE_MAP", "VanConfig"]}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _SCREAMING_SNAKE_CASE      :			Dict      				=   [
     "VAN_PRETRAINED_MODEL_ARCHIVE_LIST",
     "VanForImageClassification",
     "VanModel",
     "VanPreTrainedModel",
 ]

if TYPE_CHECKING:
 from .configuration_van import VAN_PRETRAINED_CONFIG_ARCHIVE_MAP, VanConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_van import (
      VAN_PRETRAINED_MODEL_ARCHIVE_LIST,
      VanForImageClassification,
      VanModel,
      VanPreTrainedModel,
  )

else:
 import sys

 _SCREAMING_SNAKE_CASE      :			str      				=   _LazyModule(__name__, globals()["__file__"], _import_structure)




