




"""simple docstring"""






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

from ...utils import logging


lowercase__     						=						logging.get_logger(__name__)






class lowerCAmelCase__	(     lowercase						):






			'''simple docstring'''



			lowerCamelCase__      =			CLIPConfig

			lowerCamelCase__      =			["""CLIPEncoderLayer"""]
			def __init__(  self  ,      lowercase  ):
							super().__init__(lowercase  )

							_lowerCamelCase     :			List[str]    =    CLIPVisionModelWithProjection(config.vision_config  )

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






			@torch.no_grad()
			def 					A_    (  self  ,      lowercase  ,      lowercase  ,      lowercase=0.5  ,      lowercase=0.5  ):
							_lowerCamelCase     :			Dict    =    self.vision_model(lowercase  )[0]

							_lowerCamelCase     :			Any    =    self.p_head(lowercase  )
							_lowerCamelCase     :			str    =    nsfw_detected.flatten()
							_lowerCamelCase     :			int    =    nsfw_detected > p_threshold
							_lowerCamelCase     :			Union[str, Any]    =    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_:
															_lowerCamelCase     :			Dict    =    np.zeros(images[idx].shape  )

							_lowerCamelCase     :			Dict    =    self.w_head(lowercase  )
							_lowerCamelCase     :			Tuple    =    watermark_detected.flatten()
							_lowerCamelCase     :			Dict    =    watermark_detected > w_threshold
							_lowerCamelCase     :			Dict    =    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_:
															_lowerCamelCase     :			List[str]    =    np.zeros(images[idx].shape  )

							return images, nsfw_detected, watermark_detected





"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowercase__     						=						{"""configuration_ibert""": ["""IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""", """IBertConfig""", """IBertOnnxConfig"""]}

try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			lowercase__     						=						[
			    """IBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
			    """IBertForMaskedLM""",
			    """IBertForMultipleChoice""",
			    """IBertForQuestionAnswering""",
			    """IBertForSequenceClassification""",
			    """IBertForTokenClassification""",
			    """IBertModel""",
			    """IBertPreTrainedModel""",
			]

if TYPE_CHECKING:
			from .configuration_ibert import IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, IBertConfig, IBertOnnxConfig

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_ibert import (
						    IBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
						    IBertForMaskedLM,
						    IBertForMultipleChoice,
						    IBertForQuestionAnswering,
						    IBertForSequenceClassification,
						    IBertForTokenClassification,
						    IBertModel,
						    IBertPreTrainedModel,
						)

else:
			import sys

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