






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






def 				__lowerCAmelCase(       _SCREAMING_SNAKE_CASE				)							-> bool:




    """simple docstring"""




    if not isinstance(_SCREAMING_SNAKE_CASE							,     _SCREAMING_SNAKE_CASE				):
        raise ValueError('check_bouncy() accepts only integer arguments'				)
    _A     =							str(_SCREAMING_SNAKE_CASE				)
    _A     =							''.join(sorted(_SCREAMING_SNAKE_CASE				)				)
    return sorted_str_n != str_n and sorted_str_n[::-1] != str_n





def 				__lowerCAmelCase(       _SCREAMING_SNAKE_CASE = 99				)							-> int:




    """simple docstring"""




    if not 0 < percent < 100:
        raise ValueError('solution() only accepts values from 0 to 100'				)
    _A     =							0
    _A     =							1

    while True:
        if check_bouncy(_SCREAMING_SNAKE_CASE				):
            bouncy_num += 1
        if (bouncy_num / num) * 100 >= percent:
            return num
        num += 1


if __name__ == "__main__":
 from doctest import testmod

 testmod()
 print(f"{solution(99)}")





