





'''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








def 						_UpperCAmelCase				(			SCREAMING_SNAKE_CASE__			:					int = 10**12				):
     __UpperCamelCase    							=1
     __UpperCamelCase    							=0

     __UpperCamelCase    							=1
     __UpperCamelCase    							=1

     while numerator <= 2 * min_total - 1:
          prev_numerator += 2 * numerator
          numerator += 2 * prev_numerator

          prev_denominator += 2 * denominator
          denominator += 2 * prev_denominator

     return (denominator + 1) // 2


if __name__ == "__main__":
   print(f"""{solution() = }""")





