





"""simple docstring"""



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

from ...utils import logging


a_			=      logging.get_logger(__name__)






class 		__snake_case (		SCREAMING_SNAKE_CASE__					):





 """simple docstring"""


 _lowerCamelCase				=					CLIPConfig

 _lowerCamelCase				=					["""CLIPEncoderLayer"""]

 def __init__(   self ,						__lowerCamelCase  ):



     '''simple docstring'''




     super().__init__(__lowerCamelCase  )

     __A   :						int									=					CLIPVisionModelWithProjection(config.vision_config  )

     __A   :						Union[str, Any]									=					nn.Linear(config.vision_config.projection_dim ,						1  )
     __A   :						Tuple									=					nn.Linear(config.vision_config.projection_dim ,						1  )







 @torch.no_grad()
 def  UpperCamelCase__(   self ,						__lowerCamelCase ,						__lowerCamelCase ,						__lowerCamelCase=0.5 ,						__lowerCamelCase=0.5  ):



     '''simple docstring'''




     __A   :						Tuple									=					self.vision_model(__lowerCamelCase  )[0]

     __A   :						Optional[Any]									=					self.p_head(__lowerCamelCase  )
     __A   :						int									=					nsfw_detected.flatten()
     __A   :						str									=					nsfw_detected > p_threshold
     __A   :						Tuple									=					nsfw_detected.tolist()

     if any(__lowerCamelCase  ):
         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(__lowerCamelCase  ):
         if nsfw_detected_:
             __A   :						Union[str, Any]									=					np.zeros(images[idx].shape  )

     __A   :						Optional[Any]									=					self.w_head(__lowerCamelCase  )
     __A   :						Any									=					watermark_detected.flatten()
     __A   :						Any									=					watermark_detected > w_threshold
     __A   :						Dict									=					watermark_detected.tolist()

     if any(__lowerCamelCase  ):
         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(__lowerCamelCase  ):
         if watermark_detected_:
             __A   :						List[str]									=					np.zeros(images[idx].shape  )

     return images, nsfw_detected, watermark_detected











"""simple docstring"""



from typing import TYPE_CHECKING

from ...file_utils import _LazyModule, is_tokenizers_available, is_torch_available
from ...utils import OptionalDependencyNotAvailable


a_			=      {"""configuration_gpt_neox""": ["""GPT_NEOX_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GPTNeoXConfig"""]}

try:
       if not is_tokenizers_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a_			=      ["""GPTNeoXTokenizerFast"""]

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       a_			=      [
           """GPT_NEOX_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """GPTNeoXForCausalLM""",
           """GPTNeoXForQuestionAnswering""",
           """GPTNeoXForSequenceClassification""",
           """GPTNeoXForTokenClassification""",
           """GPTNeoXLayer""",
           """GPTNeoXModel""",
           """GPTNeoXPreTrainedModel""",
       ]


if TYPE_CHECKING:
       from .configuration_gpt_neox import GPT_NEOX_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTNeoXConfig

       try:
              if not is_tokenizers_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tokenization_gpt_neox_fast import GPTNeoXTokenizerFast

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_gpt_neox import (
                  GPT_NEOX_PRETRAINED_MODEL_ARCHIVE_LIST,
                  GPTNeoXForCausalLM,
                  GPTNeoXForQuestionAnswering,
                  GPTNeoXForSequenceClassification,
                  GPTNeoXForTokenClassification,
                  GPTNeoXLayer,
                  GPTNeoXModel,
                  GPTNeoXPreTrainedModel,
              )


else:
       import sys

       a_			=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)




