





'''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 					a_     (				snake_case_       ):

    '''simple docstring'''
    UpperCamelCase     = CLIPConfig

    UpperCamelCase     = ['''CLIPEncoderLayer''']


    def __init__(		self ,		A       )		->   Optional[Any]:
        super().__init__(A       )

        _SCREAMING_SNAKE_CASE									=			CLIPVisionModelWithProjection(config.vision_config       )

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





    @torch.no_grad()
    def 			snake_case_(		self ,		A ,		A ,		A=0.5 ,		A=0.5       )		->   List[str]:
        _SCREAMING_SNAKE_CASE									=			self.vision_model(A       )[0]

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

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

        return images, nsfw_detected, watermark_detected









"""simple docstring"""


import os
from typing import Dict, List, Tuple, TypeVar, Union


A_						=				TypeVar('''T''')

A_						=				Union[List[T], Tuple[T, ...]]
A_						=				Union[T, List[T], Dict[str, T]]
A_						=				Union[str, bytes, os.PathLike]


