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

from ...utils import logging


__lowerCAmelCase												=	logging.get_logger(__name__)


class       _lowerCAmelCase   (   _A				):







							'''simple docstring'''

							lowerCAmelCase_ 						=						CLIPConfig

							lowerCAmelCase_ 						=						["CLIPEncoderLayer"]

							def __init__(self  ,  UpperCAmelCase  )					->       Dict:
														super().__init__(__SCREAMING_SNAKE_CASE  )

														_snake_case       =  CLIPVisionModelWithProjection(config.vision_config  )

														_snake_case       =  nn.Linear(config.vision_config.projection_dim  ,  1  )
														_snake_case       =  nn.Linear(config.vision_config.projection_dim  ,  1  )





							@torch.no_grad()
							def 	lowercase							(self  ,  UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase=0.5  ,  UpperCAmelCase=0.5  )					->       int:
														_snake_case       =  self.vision_model(__SCREAMING_SNAKE_CASE  )[0]

														_snake_case       =  self.p_head(__SCREAMING_SNAKE_CASE  )
														_snake_case       =  nsfw_detected.flatten()
														_snake_case       =  nsfw_detected > p_threshold
														_snake_case       =  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_:
																												_snake_case       =  np.zeros(images[idx].shape  )

														_snake_case       =  self.w_head(__SCREAMING_SNAKE_CASE  )
														_snake_case       =  watermark_detected.flatten()
														_snake_case       =  watermark_detected > w_threshold
														_snake_case       =  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_:
																												_snake_case       =  np.zeros(images[idx].shape  )

														return images, nsfw_detected, watermark_detected

'''simple docstring'''
from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


__lowerCAmelCase												=	{
    'configuration_efficientformer': [
        'EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'EfficientFormerConfig',
    ]
}

try:
				if not is_vision_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__lowerCAmelCase												=	['EfficientFormerImageProcessor']

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__lowerCAmelCase												=	[
				    'EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'EfficientFormerForImageClassification',
				    'EfficientFormerForImageClassificationWithTeacher',
				    'EfficientFormerModel',
				    'EfficientFormerPreTrainedModel',
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__lowerCAmelCase												=	[
				    'TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'TFEfficientFormerForImageClassification',
				    'TFEfficientFormerForImageClassificationWithTeacher',
				    'TFEfficientFormerModel',
				    'TFEfficientFormerPreTrainedModel',
				]

if TYPE_CHECKING:
				from .configuration_efficientformer import EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, EfficientFormerConfig

				try:
								if not is_vision_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .image_processing_efficientformer import EfficientFormerImageProcessor

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_efficientformer import (
								    EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
								    EfficientFormerForImageClassification,
								    EfficientFormerForImageClassificationWithTeacher,
								    EfficientFormerModel,
								    EfficientFormerPreTrainedModel,
								)
				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_tf_efficientformer import (
								    TF_EFFICIENTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
								    TFEfficientFormerForImageClassification,
								    TFEfficientFormerForImageClassificationWithTeacher,
								    TFEfficientFormerModel,
								    TFEfficientFormerPreTrainedModel,
								)

else:
				import sys

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