





'''simple docstring'''

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

from ...utils import logging


__lowerCAmelCase							:     Optional[int]		     =logging.get_logger(__name__)






class 					UpperCAmelCase     (	__UpperCamelCase    ):
 __lowercase       		=    CLIPConfig

 __lowercase       		=    ["CLIPEncoderLayer"]
 def __init__(    self				:str						,	lowercase_				:CLIPConfig							)->							int:
     super().__init__(_lowerCAmelCase							)

     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 					UpperCAmelCase_							(    self				:List[str]						,	lowercase_				:Union[str, Any]						,	lowercase_				:List[str]						,	lowercase_				:Tuple=0.5						,	lowercase_				:List[str]=0.5							)->							Dict:
     A__    =      self.vision_model(_lowerCAmelCase							)[0]

     A__    =      self.p_head(_lowerCAmelCase							)
     A__    =      nsfw_detected.flatten()
     A__    =      nsfw_detected > p_threshold
     A__    =      nsfw_detected.tolist()

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

     A__    =      self.w_head(_lowerCAmelCase							)
     A__    =      watermark_detected.flatten()
     A__    =      watermark_detected > w_threshold
     A__    =      watermark_detected.tolist()

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

     return images, nsfw_detected, watermark_detected










'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__lowerCAmelCase							:     Any		     ={
    "configuration_swinv2": ["SWINV2_PRETRAINED_CONFIG_ARCHIVE_MAP", "Swinv2Config"],
}


try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __lowerCAmelCase							:     Tuple		     =[
      "SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST",
      "Swinv2ForImageClassification",
      "Swinv2ForMaskedImageModeling",
      "Swinv2Model",
      "Swinv2PreTrainedModel",
  ]


if TYPE_CHECKING:
  from .configuration_swinva import SWINV2_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinvaConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_swinva import (
        SWINV2_PRETRAINED_MODEL_ARCHIVE_LIST,
        SwinvaForImageClassification,
        SwinvaForMaskedImageModeling,
        SwinvaModel,
        SwinvaPreTrainedModel,
    )


else:
  import sys

  __lowerCAmelCase							:     List[Any]		     =_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



