






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

from ...utils import logging


snake_case : Any     		=		logging.get_logger(__name__)



class        UpperCamelCase__ (				a_):







    """simple docstring"""
    __UpperCAmelCase           = CLIPConfig

    __UpperCAmelCase           = ["""CLIPEncoderLayer"""]







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





           '''simple docstring'''

           super().__init__(UpperCamelCase_ )

           __magic_name__      				=    CLIPVisionModelWithProjection(config.vision_config )

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







    @torch.no_grad()
    def 				a__			(		self :	Tuple				,    UpperCamelCase_ :	Optional[int]				,    UpperCamelCase_ :	List[str]				,    UpperCamelCase_ :	List[str]=0.5				,    UpperCamelCase_ :	Union[str, Any]=0.5 ):





           '''simple docstring'''

           __magic_name__      				=    self.vision_model(UpperCamelCase_ )[0]

           __magic_name__      				=    self.p_head(UpperCamelCase_ )
           __magic_name__      				=    nsfw_detected.flatten()
           __magic_name__      				=    nsfw_detected > p_threshold
           __magic_name__      				=    nsfw_detected.tolist()

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

           __magic_name__      				=    self.w_head(UpperCamelCase_ )
           __magic_name__      				=    watermark_detected.flatten()
           __magic_name__      				=    watermark_detected > w_threshold
           __magic_name__      				=    watermark_detected.tolist()

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

           return images, nsfw_detected, watermark_detected







"""simple docstring"""
from datetime import datetime

import matplotlib.pyplot as plt
import torch


def 							A						(				__snake_case: Optional[int]  )    ->		Tuple:

       """simple docstring"""





       for param in module.parameters():
              __magic_name__      				=    False


def 							A						(				)    ->		Optional[Any]:

       """simple docstring"""





       __magic_name__      				=    'cuda' if torch.cuda.is_available() else 'cpu'
       if torch.backends.mps.is_available() and torch.backends.mps.is_built():
              __magic_name__      				=    'mps'
       if device == "mps":
              print(
                  'WARNING: MPS currently doesn\'t seem to work, and messes up backpropagation without any visible torch'
                  ' errors. I recommend using CUDA on a colab notebook or CPU instead if you\'re facing inexplicable issues'
                  ' with generations.'  )
       return device


def 							A						(				__snake_case: int  )    ->		List[Any]:

       """simple docstring"""





       __magic_name__      				=    plt.imshow(__snake_case  )
       fig.axes.get_xaxis().set_visible(__snake_case  )
       fig.axes.get_yaxis().set_visible(__snake_case  )
       plt.show()






def 							A						(				)    ->		List[Any]:

       """simple docstring"""





       __magic_name__      				=    datetime.now()
       __magic_name__      				=    current_time.strftime('%H:%M:%S'  )
       return timestamp