


"""simple docstring"""


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

from ...utils import logging


A     :   str			    =			logging.get_logger(__name__)
class   _UpperCamelCase  (   lowerCAmelCase__		):
							'''simple docstring'''







							__UpperCAmelCase						:    List[str]				      =CLIPConfig

							__UpperCAmelCase						:    Dict				      =["""CLIPEncoderLayer"""]

							def __init__(     self    ,   __a	):
										super().__init__(__a	)

										__lowerCAmelCase				    =			CLIPVisionModelWithProjection(config.vision_config	)

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



							@torch.no_grad()
							def 			snake_case				(     self    ,   __a    ,   __a    ,   __a=0.5    ,   __a=0.5	):
										__lowerCAmelCase				    =			self.vision_model(__a	)[0]

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

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

										return images, nsfw_detected, watermark_detected





def lowerCamelCase  (   SCREAMING_SNAKE_CASE = 1  ,			SCREAMING_SNAKE_CASE = 1_000	):
    '''simple docstring'''







    __UpperCamelCase     :Union[str, Any]			  =		1
    __UpperCamelCase     :Any			  =		0

    for divide_by_number in range(SCREAMING_SNAKE_CASE  ,			digit + 1	):
        __UpperCamelCase     :list[int]			  =		[]
        __UpperCamelCase     :Optional[int]			  =		numerator
        for _ in range(1  ,			digit + 1	):
            if now_divide in has_been_divided:
                if longest_list_length < len(SCREAMING_SNAKE_CASE	):
                    __UpperCamelCase     :Optional[Any]			  =		len(SCREAMING_SNAKE_CASE	)
                    __UpperCamelCase     :int			  =		divide_by_number
            else:
                has_been_divided.append(SCREAMING_SNAKE_CASE	)
                __UpperCamelCase     :Any			  =		now_divide * 10 % divide_by_number

    return the_digit


# Tests
if __name__ == "__main__":
    import doctest

    doctest.testmod()





