





'''simple docstring'''

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

from ...utils import logging


lowercase__						:      Dict	=    logging.get_logger(__name__)
class     __lowerCAmelCase					(   _UpperCamelCase			):






       """simple docstring"""
       _snake_case     :					List[Any]						    =   CLIPConfig

       _snake_case     :					List[Any]						    =   ['CLIPEncoderLayer']





       def __init__(							self       :		Any	,			lowerCAmelCase__       :		List[Any]					)   ->					Tuple:

            '''simple docstring'''




            super().__init__(_SCREAMING_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 snake_case__						(							self       :		List[str]	,			lowerCAmelCase__       :		int	,			lowerCAmelCase__       :		Dict	,			lowerCAmelCase__       :		Union[str, Any]=0.5	,			lowerCAmelCase__       :		Any=0.5					)   ->					Optional[int]:

            '''simple docstring'''




            _UpperCamelCase       =	self.vision_model(_SCREAMING_SNAKE_CASE					)[0]

            _UpperCamelCase       =	self.p_head(_SCREAMING_SNAKE_CASE					)
            _UpperCamelCase       =	nsfw_detected.flatten()
            _UpperCamelCase       =	nsfw_detected > p_threshold
            _UpperCamelCase       =	nsfw_detected.tolist()

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

            _UpperCamelCase       =	self.w_head(_SCREAMING_SNAKE_CASE					)
            _UpperCamelCase       =	watermark_detected.flatten()
            _UpperCamelCase       =	watermark_detected > w_threshold
            _UpperCamelCase       =	watermark_detected.tolist()

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

            return images, nsfw_detected, watermark_detected










'''simple docstring'''

from cva import destroyAllWindows, imread, imshow, waitKey







def  a__    (    lowercase :					str				)		->		Optional[int]:





     """simple docstring"""

     _UpperCamelCase   ,    _UpperCamelCase       =	img.shape[0], img.shape[1]

     # converting each pixel's color to its negative
     for i in range(lowercase				):
          for j in range(lowercase				):
               _UpperCamelCase       =	[255, 255, 255] - img[i][j]

     return img


if __name__ == "__main__":
   # read original image
   lowercase__						:      Optional[int]	=    imread('image_data/lena.jpg', 1)

   # convert to its negative
   lowercase__						:      Union[str, Any]	=    convert_to_negative(img)

   # show result image
   imshow('negative of original image', img)
   waitKey(0)
   destroyAllWindows()



