
    fTh!                         % S SK JrJr  S SKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJrJr  \R                   " \5      rS
SSS.r\\\4   \S'    " S S\SS9r " S S\5      rS/rg)    )MappingSequence)Optional   )BatchFeature)
ImageInput)Unpack)logging   )Gemma3ProcessorGemma3ProcessorKwargszNo Dangerous Content: The image shall not contain content that facilitates or encourages activities that could cause real-world harm (e.g., building firearms and explosive devices, promotion of terrorism, instructions for suicide).zNo Sexually Explicit content: The image shall not contain content that depicts explicit or graphic sexual acts (e.g., pornography, erotic nudity, depictions of rape or sexual assault).zNo Violence/Gore content: The image shall not contain content that depicts shocking, sensational, or gratuitous violence (e.g., excessive blood and gore, gratuitous violence against animals, extreme injury or moment of death).)	dangeroussexualviolenceDEFAULT_SHIELDGEMMA2_POLICIESc                   X    \ rS rSr% \\\      \S'   \\\\4      \S'   SS0SS0S.r	S	r
g
)ShieldGemma2ProcessorKwargs1   policiescustom_policiespaddingTdo_pan_and_scanF)text_kwargsimages_kwargs N)__name__
__module____qualname____firstlineno__r   r   str__annotations__r   	_defaults__static_attributes__r       p/var/www/auris/envauris/lib/python3.13/site-packages/transformers/models/shieldgemma2/processing_shieldgemma2.pyr   r   1   sD    x}%%gc3h/00 t
 u
	Ir$   r   F)totalc                   x   ^  \ rS rSr SU 4S jjr    SS\S\\   S\4U 4S jjjr	S r
S r\S	 5       rS
rU =r$ )ShieldGemma2Processor>   c                 T   > [         TU ]  " XX440 UD6  Uc  [        U l        gXPl        g)a  A processor for the ShieldGemma 2 model.

Args:
    image_processor: The image processor to use, typically a `Gemma3ImageProcessorFast` instance.
    tokenizer: The tokenizer to use, typically a `GemmaTokenizerFast` instance.
    chat_template: The chat template to use with this processor. Typically, this is unset as the processor
        configuration on Hugging Face Hub includes this value already.
    image_seq_length: The number of soft tokens per image. Typically, this is unset as the processor
        configuration on Hugging Face Hub includes this value already.
    policy_definitions: A mapping from policy name to its description in text used as the default policies to
        classify images against. The policy descriptions are included in the text of the prompts generated by
        this processor. Typically, this is unset as the processor configuration on Hugging Face Hub includes
        the base policies ShieldGemma was trained on.
N)super__init__r   policy_definitions)selfimage_processor	tokenizerchat_templateimage_seq_lengthr-   kwargs	__class__s          r%   r,   ShieldGemma2Processor.__init__?   s.    " 	]_X^_%&CD#&8#r$   imagesr3   returnc           	        > AAAU(       d  [        S5      e[        U[        5      (       d  U/nU R                  (       d  [        S5      eUR	                  S0 5      nUR                  S5      SL a  [        R                  S5        SUS'   UR	                  S0 5      nS	U;  a*  UR                  S	S5      US	'   UR                  S
S5      US
'   0 U R                  EUR                  S0 5      EnUR                  S5      =n	c  [        UR                  5       5      n	/ n
/ nU H<  nU	 H3  nU
R                  SSS0SX   S./S./5        UR                  U/5        M5     M>     U R                  U
SS9n[        TU ]<  " SXS.UD6$ )a
  Generates a batch of inputs from the provided images.

ShieldGemma was trained to classify image content for policy compliance using a specific prompt construction.
This processor generates a batch of such prompts from the provided images by:

1.  Creating a list of conversations, one for each `<image, policy>` pair;
2.  Converting these conversations to text using `self.apply_chat_template()`; and
3.  Encoding the conversations and images using the same techniques as `Gemma3Processor`.

Args:
    images: A single image or a list of images to include in the batch.
    text: Not supported.
    videos: Not supported.
    audio: Not supported.
    kwargs: An optional dictionary of keyword arguments to configure the
        processor. Possible values include:

        *   `custom_policies`: Additional policy definitions that augment the `self.policy_definitions` passed
            into the constructor. Note that `custom_policies` that share a key with `self.policy_definitions`
            will override the policy description
        *   `policies`: (Optional) a list of keys in the joint `self.policy_definitions | custom_policies`
            dictionary of specific interest for the provided images. If empty or None, prompts will be
            generated for every key in the joint dictionary.

Returns:
    A `BatchFeature` containing `input_ids`, `pixel_values`, etc. where each Tensor is of shape
    `(len(images) * len(policies), )`, and the order within the batch will be
    img1_policy1, ... img1_policyN, ... imgM_policyN.
z&ShieldGemma 2 needs images to classifyz:ShieldGemma 2 requires the use of a specific chat templater   r   Tz+ShieldGemma2 does not support pan and scan.Fr   r   padding_sideleftr   r   usertypeimagetext)r<   r>   )rolecontent)tokenize)r6   r>   r   )
ValueError
isinstancer   r1   
setdefaultgetloggerwarning_oncepopr-   listkeysappendapply_chat_templater+   __call__)r.   r6   r>   videosaudior3   r   r   r-   r   messagesexpanded_imagesimgpolicyr4   s                 r%   rM   ShieldGemma2Processor.__call__V   s   J &%EFFFH--XF!!YZZ ))/2>./47 MN/4M+, ''r:K'%+ZZ	4%@K	"*0**^V*LK'1
%%1
jj*B/1

 

:..H7.3356H C" %+!' 1)/9K9S T(
  &&u- #  ''5'AwLLVLLr$   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to GemmaTokenizerFast's [`~PreTrainedTokenizer.batch_decode`]. Please
refer to the docstring of this method for more information.
)r0   batch_decoder.   argsr3   s      r%   rV   "ShieldGemma2Processor.batch_decode   s    
 ~~**D;F;;r$   c                 :    U R                   R                  " U0 UD6$ )z
This method forwards all its arguments to GemmaTokenizerFast's [`~PreTrainedTokenizer.decode`]. Please refer to
the docstring of this method for more information.
)r0   decoderW   s      r%   r[   ShieldGemma2Processor.decode   s    
 ~~$$d5f55r$   c                     U R                   R                  S/-   nU R                  R                  n[        [        R                  X-   5      5      $ )Ntoken_type_ids)r0   model_input_namesr/   rI   dictfromkeys)r.   tokenizer_input_namesimage_processor_input_namess      r%   r_   'ShieldGemma2Processor.model_input_names   sE     $ @ @DTCU U&*&:&:&L&L#DMM"7"UVWWr$   )r-   )N   N)NNNN)r   r   r   r   r,   r   r	   r   r   rM   rV   r[   propertyr_   r#   __classcell__)r4   s   @r%   r(   r(   >   sp    gk92 "VMVM 45VM 
VM VMp<6 X Xr$   r(   N)collections.abcr   r   typingr   feature_extraction_utilsr   image_utilsr   processing_utilsr	   utilsr
   gemma3.processing_gemma3r   r   
get_loggerr   rF   r   r    r!   r   r(   __all__r   r$   r%   <module>rq      s     . -  4 % &  M 
		H	%	1	:
	/4 wsCx0 *
"7u 
BXO BXJ #
#r$   