



"""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							:   str      =    logging.get_logger(__name__)



class 			A__   (  __SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	CLIPConfig

	SCREAMING_SNAKE_CASE          =	['CLIPEncoderLayer']

	def __init__(     self:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		CLIPConfig)				->       Any:

				"""simple docstring"""

				super().__init__(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Any												=       CLIPVisionModelWithProjection(config.vision_config)

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







	@torch.no_grad()
	def 							_SCREAMING_SNAKE_CASE   (     self:		List[str]       ,			_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			_SCREAMING_SNAKE_CASE:		int       ,			_SCREAMING_SNAKE_CASE:		Dict=0.5       ,			_SCREAMING_SNAKE_CASE:		str=0.5)				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  Optional[int]												=       self.vision_model(_SCREAMING_SNAKE_CASE)[0]

				__lowerCAmelCase      :  Dict												=       self.p_head(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  Union[str, Any]												=       nsfw_detected.flatten()
				__lowerCAmelCase      :  int												=       nsfw_detected > p_threshold
				__lowerCAmelCase      :  Optional[Any]												=       nsfw_detected.tolist()

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

				__lowerCAmelCase      :  Tuple												=       self.w_head(_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase      :  int												=       watermark_detected.flatten()
				__lowerCAmelCase      :  Any												=       watermark_detected > w_threshold
				__lowerCAmelCase      :  Tuple												=       watermark_detected.tolist()

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

				return images, nsfw_detected, watermark_detected




"""simple docstring"""






from ..utils import DummyObject, requires_backends



class 			A__   (  metaclass=__SCREAMING_SNAKE_CASE							):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE          =	['torch', 'torchsde']

	def __init__(     self:		int       ,			*_SCREAMING_SNAKE_CASE:		Optional[Any]       ,			**_SCREAMING_SNAKE_CASE:		str)				->       Dict:

				"""simple docstring"""

				requires_backends(self       ,			["torch", "torchsde"])

	@classmethod
	def 							_SCREAMING_SNAKE_CASE   (     cls:		Optional[Any]       ,			*_SCREAMING_SNAKE_CASE:		Optional[int]       ,			**_SCREAMING_SNAKE_CASE:		Optional[int])				->       Optional[Any]:

				"""simple docstring"""

				requires_backends(cls       ,			["torch", "torchsde"])







	@classmethod
	def 							_SCREAMING_SNAKE_CASE   (     cls:		Dict       ,			*_SCREAMING_SNAKE_CASE:		List[Any]       ,			**_SCREAMING_SNAKE_CASE:		Any)				->       Optional[int]:

				"""simple docstring"""

				requires_backends(cls       ,			["torch", "torchsde"])