

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

from ...utils import logging


__UpperCAmelCase    				=     logging.get_logger(__name__)





class A__    ( A ):



 """simple docstring"""







 _lowercase     :					Optional[int]      =						CLIPConfig

 _lowercase     :					Union[str, Any]      =						['''CLIPEncoderLayer''']

 def __init__(		self :	Any     ,						A_ :	CLIPConfig       ):






      '''simple docstring'''




      super().__init__(A_       )

      _lowerCAmelCase   :					List[Any]        =    CLIPVisionModelWithProjection(config.vision_config       )

      _lowerCAmelCase   :					int        =    nn.Linear(config.vision_config.projection_dim     ,						1       )
      _lowerCAmelCase   :					int        =    nn.Linear(config.vision_config.projection_dim     ,						1       )


 @torch.no_grad()
 def    __magic_name__       (		self :	Union[str, Any]     ,						A_ :	Union[str, Any]     ,						A_ :	Tuple     ,						A_ :	int=0.5     ,						A_ :	Dict=0.5       ):






      '''simple docstring'''




      _lowerCAmelCase   :					int        =    self.vision_model(A_       )[0]

      _lowerCAmelCase   :					List[Any]        =    self.p_head(A_       )
      _lowerCAmelCase   :					Optional[Any]        =    nsfw_detected.flatten()
      _lowerCAmelCase   :					str        =    nsfw_detected > p_threshold
      _lowerCAmelCase   :					str        =    nsfw_detected.tolist()

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

      _lowerCAmelCase   :					Union[str, Any]        =    self.w_head(A_       )
      _lowerCAmelCase   :					List[str]        =    watermark_detected.flatten()
      _lowerCAmelCase   :					Union[str, Any]        =    watermark_detected > w_threshold
      _lowerCAmelCase   :					str        =    watermark_detected.tolist()

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

      return images, nsfw_detected, watermark_detected









from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tensorflow_text_available, is_torch_available


__UpperCAmelCase    				=     {
    'configuration_ernie': ['ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP', 'ErnieConfig', 'ErnieOnnxConfig'],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __UpperCAmelCase    				=     [
      'ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST',
      'ErnieForCausalLM',
      'ErnieForMaskedLM',
      'ErnieForMultipleChoice',
      'ErnieForNextSentencePrediction',
      'ErnieForPreTraining',
      'ErnieForQuestionAnswering',
      'ErnieForSequenceClassification',
      'ErnieForTokenClassification',
      'ErnieModel',
      'ErniePreTrainedModel',
  ]

if TYPE_CHECKING:
  from .configuration_ernie import ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP, ErnieConfig, ErnieOnnxConfig

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_ernie import (
        ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST,
        ErnieForCausalLM,
        ErnieForMaskedLM,
        ErnieForMultipleChoice,
        ErnieForNextSentencePrediction,
        ErnieForPreTraining,
        ErnieForQuestionAnswering,
        ErnieForSequenceClassification,
        ErnieForTokenClassification,
        ErnieModel,
        ErniePreTrainedModel,
    )

else:
  import sys

  __UpperCAmelCase    				=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






