
    biE                     z    d dl Zd dlZd dlmZ d dlmZmZmZ ddl	m
Z
  e
j                  e      Z G d de      Zy)    N)
CLIPConfigCLIPVisionModelWithProjectionPreTrainedModel   )loggingc                   ^     e Zd ZeZdgZdef fdZ ej                         dd       Z	 xZ
S )IFSafetyCheckerCLIPEncoderLayerconfigc                    t         |   |       t        |j                        | _        t        j                  |j                  j                  d      | _        t        j                  |j                  j                  d      | _	        y )N   )
super__init__r   vision_configvision_modelnnLinearprojection_dimp_headw_head)selfr   	__class__s     j/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/pipelines/deepfloyd_if/safety_checker.pyr   zIFSafetyChecker.__init__   s_     9&:N:NOii 4 4 C CQGii 4 4 C CQG    c                 x   | j                  |      d   }| j                  |      }|j                         }||kD  }|j                         }t	        |      rt
        j                  d       t        |      D ]-  \  }}|s	t        j                  ||   j                        ||<   / | j                  |      }	|	j                         }	|	|kD  }	|	j                         }	t	        |	      rt
        j                  d       t        |	      D ]-  \  }}
|
s	t        j                  ||   j                        ||<   / |||	fS )Nr   zPotential 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.zPotential 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.)r   r   flattentolistanyloggerwarning	enumeratenpzerosshaper   )r   
clip_inputimagesp_thresholdw_thresholdimage_embedsnsfw_detectedidxnsfw_detected_watermark_detectedwatermark_detected_s              r   forwardzIFSafetyChecker.forward   s@   ((4Q7L1%--/%3%,,.}NNB
 $-]#; 	:C hhvc{'8'89s	: "[[6/779/+=/668!"NNB
 )22D(E 	:$C$" hhvc{'8'89s	: }&888r   )      ?r0   )__name__
__module____qualname__r   config_class_no_split_modulesr   torchno_gradr/   __classcell__)r   s   @r   r	   r	      s;    L+,Hz H U]]_!9 !9r   r	   )numpyr"   r6   torch.nnr   transformersr   r   r   utilsr   
get_loggerr1   r   r	    r   r   <module>r?      s7       S S  
		H	%/9o /9r   