






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        lowerCAmelCase_				(      lowercase	):







				"""simple docstring"""




				_snake_case				:   Any        =			CLIPConfig

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







				def __init__( self     :Union[str, Any]  ,     lowerCamelCase__     :CLIPConfig     ):
					super().__init__(lowerCamelCase__     )

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

					UpperCamelCase__ :Optional[int]						=      nn.Linear(config.vision_config.projection_dim  ,     1     )
					UpperCamelCase__ :Optional[Any]						=      nn.Linear(config.vision_config.projection_dim  ,     1     )







				@torch.no_grad()
				def 				__a   ( self     :Optional[Any]  ,     lowerCamelCase__     :Any  ,     lowerCamelCase__     :Tuple  ,     lowerCamelCase__     :Optional[int]=0.5  ,     lowerCamelCase__     :Tuple=0.5     ):
					UpperCamelCase__ :Optional[int]						=      self.vision_model(lowerCamelCase__     )[0]

					UpperCamelCase__ :str						=      self.p_head(lowerCamelCase__     )
					UpperCamelCase__ :List[Any]						=      nsfw_detected.flatten()
					UpperCamelCase__ :Optional[int]						=      nsfw_detected > p_threshold
					UpperCamelCase__ :Dict						=      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_:
							UpperCamelCase__ :List[str]						=      np.zeros(images[idx].shape     )

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

					return images, nsfw_detected, watermark_detected





from typing import TYPE_CHECKING

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


lowerCamelCase__					:  Optional[int]      							=				{'configuration_mmbt': ['MMBTConfig']}

try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowerCamelCase__					:  Any      							=				['MMBTForClassification', 'MMBTModel', 'ModalEmbeddings']


if TYPE_CHECKING:
   from .configuration_mmbt import MMBTConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_mmbt import MMBTForClassification, MMBTModel, ModalEmbeddings

else:
   import sys

   lowerCamelCase__					:  str      							=				_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)