

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						(							_UpperCAmelCase ):







    """simple docstring"""





    lowerCamelCase			=							CLIPConfig

    lowerCamelCase			=							['CLIPEncoderLayer']


    def __init__(      self :       int,lowercase_ :       CLIPConfig		)->    Union[str, Any]:





        '''simple docstring'''







        super().__init__(lowercase_		)

        A__          =   CLIPVisionModelWithProjection(config.vision_config		)

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


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





        '''simple docstring'''







        A__          =   self.vision_model(lowercase_		)[0]

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

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

        return images, nsfw_detected, watermark_detected






"""simple docstring"""
from collections.abc import Callable

import numpy as np

def       _snake_case						(						UpperCamelCase						:		Callable			,		UpperCamelCase						:		float			,		UpperCamelCase						:		float			,		UpperCamelCase						:		float			,		UpperCamelCase						:		float						):
 UpperCAmelCase	:					Any	=	int(np.ceil((x_end - xa) / step_size						)						)
 UpperCAmelCase	:					Optional[Any]	=	np.zeros((n + 1,)						)
 UpperCAmelCase	:					Optional[int]	=	ya
 UpperCAmelCase	:					int	=	xa

 for k in range(UpperCamelCase						):
  UpperCAmelCase	:					Optional[int]	=	y[k] + step_size * ode_func(UpperCamelCase			,		y[k]						)
  UpperCAmelCase	:					Optional[int]	=	y[k] + (
      (step_size / 2) * (ode_func(UpperCamelCase			,		y[k]						) + ode_func(x + step_size			,		UpperCamelCase						))
  )
  x += step_size

 return y


if __name__ == "__main__":
      import doctest

      doctest.testmod()
