





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        SCREAMING_SNAKE_CASE     (UpperCAmelCase   ):
   _UpperCamelCase					:	str				      = CLIPConfig

   _UpperCamelCase					:	Tuple				      = ['CLIPEncoderLayer']


   def __init__(					self    :       Optional[int]    ,  a    :       CLIPConfig )->     List[Any]:





     """simple docstring"""







     super().__init__(a )

     lowercase__			    =						CLIPVisionModelWithProjection(config.vision_config )

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


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





     """simple docstring"""







     lowercase__			    =						self.vision_model(a )[0]

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

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

     return images, nsfw_detected, watermark_detected









from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


lowercase_					     =	{
    """configuration_squeezebert""": [
        """SQUEEZEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """SqueezeBertConfig""",
        """SqueezeBertOnnxConfig""",
    ],
    """tokenization_squeezebert""": ["""SqueezeBertTokenizer"""],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_					     =	["""SqueezeBertTokenizerFast"""]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      lowercase_					     =	[
          """SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """SqueezeBertForMaskedLM""",
          """SqueezeBertForMultipleChoice""",
          """SqueezeBertForQuestionAnswering""",
          """SqueezeBertForSequenceClassification""",
          """SqueezeBertForTokenClassification""",
          """SqueezeBertModel""",
          """SqueezeBertModule""",
          """SqueezeBertPreTrainedModel""",
      ]


if TYPE_CHECKING:
      from .configuration_squeezebert import (
          SQUEEZEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
          SqueezeBertConfig,
          SqueezeBertOnnxConfig,
      )
      from .tokenization_squeezebert import SqueezeBertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_squeezebert_fast import SqueezeBertTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_squeezebert import (
                SQUEEZEBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                SqueezeBertForMaskedLM,
                SqueezeBertForMultipleChoice,
                SqueezeBertForQuestionAnswering,
                SqueezeBertForSequenceClassification,
                SqueezeBertForTokenClassification,
                SqueezeBertModel,
                SqueezeBertModule,
                SqueezeBertPreTrainedModel,
            )

else:
      import sys

      lowercase_					     =	_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


