


'''simple docstring'''






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

from ...utils import logging


__A   :    Optional[int]											= logging.get_logger(__name__)






class   __snake_case			(  _SCREAMING_SNAKE_CASE):







    """simple docstring"""



    lowercase  					=   CLIPConfig

    lowercase  					=   ['CLIPEncoderLayer']

    def __init__(  self       :    Optional[int]       ,		lowerCamelCase       :    CLIPConfig						)  ->    Tuple:
      super().__init__(lowerCamelCase						)

      lowerCAmelCase_     : Dict     =  CLIPVisionModelWithProjection(config.vision_config						)

      lowerCAmelCase_     : str     =  nn.Linear(config.vision_config.projection_dim       ,		1						)
      lowerCAmelCase_     : Dict     =  nn.Linear(config.vision_config.projection_dim       ,		1						)





    @torch.no_grad()
    def __lowercase  (  self       :    str       ,		lowerCamelCase       :    Optional[int]       ,		lowerCamelCase       :    Union[str, Any]       ,		lowerCamelCase       :    Tuple=0.5       ,		lowerCamelCase       :    List[Any]=0.5						)  ->    Union[str, Any]:
      lowerCAmelCase_     : Union[str, Any]     =  self.vision_model(lowerCamelCase						)[0]

      lowerCAmelCase_     : int     =  self.p_head(lowerCamelCase						)
      lowerCAmelCase_     : Any     =  nsfw_detected.flatten()
      lowerCAmelCase_     : List[Any]     =  nsfw_detected > p_threshold
      lowerCAmelCase_     : List[str]     =  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_:
          lowerCAmelCase_     : int     =  np.zeros(images[idx].shape						)

      lowerCAmelCase_     : List[str]     =  self.w_head(lowerCamelCase						)
      lowerCAmelCase_     : Any     =  watermark_detected.flatten()
      lowerCAmelCase_     : List[str]     =  watermark_detected > w_threshold
      lowerCAmelCase_     : Tuple     =  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_:
          lowerCAmelCase_     : List[str]     =  np.zeros(images[idx].shape						)

      return images, nsfw_detected, watermark_detected







'''simple docstring'''






from maths.is_square_free import is_square_free
from maths.prime_factors import prime_factors







def 							UpperCamelCase_     (       A__   :  int   ):
  '''simple docstring'''





  lowerCAmelCase_     : Any     =  prime_factors(A__   )
  if is_square_free(A__   ):
    return -1 if len(A__   ) % 2 else 1
  return 0


if __name__ == "__main__":
  import doctest

  doctest.testmod()



