





'''simple docstring'''




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

from ...utils import logging


__SCREAMING_SNAKE_CASE     :Union[str, Any]       =				logging.get_logger(__name__)







class   A_	(  lowerCAmelCase_			):
 _lowerCamelCase  : Optional[Any]           =							CLIPConfig

 _lowerCamelCase  : Optional[Any]           =							["""CLIPEncoderLayer"""]




 def __init__(					self       :    Dict	,			snake_case_       :    CLIPConfig    ):
      super().__init__(snake_case_    )

      _UpperCAmelCase     							=   CLIPVisionModelWithProjection(config.vision_config    )

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




 @torch.no_grad()
 def      lowercase	(					self       :    List[Any]	,			snake_case_       :    Optional[int]	,			snake_case_       :    Union[str, Any]	,			snake_case_       :    Optional[int]=0.5	,			snake_case_       :    List[str]=0.5    ):
      _UpperCAmelCase     							=   self.vision_model(snake_case_    )[0]

      _UpperCAmelCase     							=   self.p_head(snake_case_    )
      _UpperCAmelCase     							=   nsfw_detected.flatten()
      _UpperCAmelCase     							=   nsfw_detected > p_threshold
      _UpperCAmelCase     							=   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_:
                _UpperCAmelCase     							=   np.zeros(images[idx].shape    )

      _UpperCAmelCase     							=   self.w_head(snake_case_    )
      _UpperCAmelCase     							=   watermark_detected.flatten()
      _UpperCAmelCase     							=   watermark_detected > w_threshold
      _UpperCAmelCase     							=   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_:
                _UpperCAmelCase     							=   np.zeros(images[idx].shape    )

      return images, nsfw_detected, watermark_detected











'''simple docstring'''




def 	UpperCAmelCase_							(					__lowercase							:      int       )		->       int:


     '''simple docstring'''



     if not isinstance(__lowercase			,     __lowercase       ) or number < 0:
          raise ValueError("Input must be a non-negative integer"       )

     _UpperCAmelCase     							=   0
     while number:
          # This way we arrive at next set bit (next 1) instead of looping
          # through each bit and checking for 1s hence the
          # loop won't run 32 times it will only run the number of `1` times
          number &= number - 1
          count += 1
     return count


if __name__ == "__main__":
  import doctest

  doctest.testmod()




