

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

from ...utils import logging


SCREAMING_SNAKE_CASE_        =      logging.get_logger(__name__)

class 				a  (	UpperCAmelCase				):
						_lowercase    						=			CLIPConfig

						_lowercase    						=			["CLIPEncoderLayer"]


						def __init__(       self						,					A_	):







										'''simple docstring'''


										super().__init__(A_	)

										_UpperCAmelCase       :		Tuple 		=    CLIPVisionModelWithProjection(config.vision_config	)

										_UpperCAmelCase       :		str 		=    nn.Linear(config.vision_config.projection_dim						,					1	)
										_UpperCAmelCase       :		List[Any] 		=    nn.Linear(config.vision_config.projection_dim						,					1	)





						@torch.no_grad()
						def        _UpperCAmelCase				(       self						,					A_						,					A_						,					A_=0.5						,					A_=0.5	):







										'''simple docstring'''


										_UpperCAmelCase       :		str 		=    self.vision_model(A_	)[0]

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

										_UpperCAmelCase       :		Tuple 		=    self.w_head(A_	)
										_UpperCAmelCase       :		Optional[Any] 		=    watermark_detected.flatten()
										_UpperCAmelCase       :		str 		=    watermark_detected > w_threshold
										_UpperCAmelCase       :		Optional[int] 		=    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_:
																		_UpperCAmelCase       :		Dict 		=    np.zeros(images[idx].shape	)

										return images, nsfw_detected, watermark_detected





from ...configuration_utils import PretrainedConfig
from ...utils import logging


SCREAMING_SNAKE_CASE_        =      logging.get_logger(__name__)

SCREAMING_SNAKE_CASE_        =      {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/config.json'}

class 				a  (	UpperCAmelCase				):
						_lowercase    						=			"openai-gpt"
						_lowercase    						=			{
						    "max_position_embeddings": "n_positions",
						    "hidden_size": "n_embd",
						    "num_attention_heads": "n_head",
						    "num_hidden_layers": "n_layer",
						}


						def __init__(       self						,					A_=40478						,					A_=512						,					A_=768						,					A_=12						,					A_=12						,					A_="gelu"						,					A_=0.1						,					A_=0.1						,					A_=0.1						,					A_=1e-5						,					A_=0.02						,					A_="cls_index"						,					A_=True						,					A_=None						,					A_=True						,					A_=0.1						,					**A_						,					):







										'''simple docstring'''


										_UpperCAmelCase       :		Any 		=    vocab_size
										_UpperCAmelCase       :		str 		=    n_positions
										_UpperCAmelCase       :		List[Any] 		=    n_embd
										_UpperCAmelCase       :		Dict 		=    n_layer
										_UpperCAmelCase       :		Any 		=    n_head
										_UpperCAmelCase       :		int 		=    afn
										_UpperCAmelCase       :		int 		=    resid_pdrop
										_UpperCAmelCase       :		Tuple 		=    embd_pdrop
										_UpperCAmelCase       :		Optional[Any] 		=    attn_pdrop
										_UpperCAmelCase       :		Any 		=    layer_norm_epsilon
										_UpperCAmelCase       :		List[str] 		=    initializer_range
										_UpperCAmelCase       :		Union[str, Any] 		=    summary_type
										_UpperCAmelCase       :		List[Any] 		=    summary_use_proj
										_UpperCAmelCase       :		Optional[Any] 		=    summary_activation
										_UpperCAmelCase       :		int 		=    summary_first_dropout
										_UpperCAmelCase       :		List[str] 		=    summary_proj_to_labels
										super().__init__(**A_	)


