


"""simple docstring"""





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

from ...utils import logging


lowercase__				:Tuple				   =       logging.get_logger(__name__)




class 							snake_case							(			__UpperCAmelCase ):

      '''simple docstring'''



      _A     :       str         =       CLIPConfig

      _A     :       Tuple         =       ['CLIPEncoderLayer']

      def __init__(							self       :      Optional[int]						,				__lowercase       :      CLIPConfig ):


        '''simple docstring'''




        super().__init__(__lowercase )

        __UpperCAmelCase    :						str       =						CLIPVisionModelWithProjection(config.vision_config )

        __UpperCAmelCase    :						List[str]       =						nn.Linear(config.vision_config.projection_dim						,				1 )
        __UpperCAmelCase    :						List[Any]       =						nn.Linear(config.vision_config.projection_dim						,				1 )







      @torch.no_grad()
      def       A_					(							self       :      Any						,				__lowercase       :      Optional[Any]						,				__lowercase       :      int						,				__lowercase       :      Dict=0.5						,				__lowercase       :      Optional[int]=0.5 ):


        '''simple docstring'''




        __UpperCAmelCase    :						List[Any]       =						self.vision_model(__lowercase )[0]

        __UpperCAmelCase    :						int       =						self.p_head(__lowercase )
        __UpperCAmelCase    :						Tuple       =						nsfw_detected.flatten()
        __UpperCAmelCase    :						Dict       =						nsfw_detected > p_threshold
        __UpperCAmelCase    :						Tuple       =						nsfw_detected.tolist()

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

        __UpperCAmelCase    :						Tuple       =						self.w_head(__lowercase )
        __UpperCAmelCase    :						Tuple       =						watermark_detected.flatten()
        __UpperCAmelCase    :						List[Any]       =						watermark_detected > w_threshold
        __UpperCAmelCase    :						str       =						watermark_detected.tolist()

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

        return images, nsfw_detected, watermark_detected






"""simple docstring"""





def       lowerCamelCase_       (   UpperCAmelCase_ = 10_00  )						->int:





  """simple docstring"""


  return sum(2 * a * ((a - 1) // 2) for a in range(3  ,			n + 1  )  )


if __name__ == "__main__":
  print(solution())