+
    œ°³jzB  ã                   ó  € R t ^ RIHt ^RIHt ^RIHt ^RIHtH	t	H
t
Ht ^RIHtHt ^RIHtHt ]! 4       '       d   ^ RItRt ! R	 R
]
RR7      t ! R R]RR7      tRR ltR tR tR t] ! R R]	4      4       tR.tR# )z
Processor class for IDEFICS.
)Úurlparse)ÚBatchFeature)Ú
ImageInput)ÚProcessingKwargsÚProcessorMixinÚ
TextKwargsÚUnpack)ÚPreTokenizedInputÚ	TextInput)Úauto_docstringÚis_torch_availableNú<image>c                   ó0   a € ] tR t^'t o RtV 3R ltRtV tR# )ÚIdeficsTextKwargsa7  
add_eos_token (`bool`, *optional*, defaults to `False`):
    Whether to add an end-of-sequence token at the end of the text input. When enabled, an EOS token is
    appended to mark the end of the text sequence, which is useful for generation tasks.
add_end_of_utterance_token (`bool`, *optional*):
    Whether to add an end-of-utterance token to mark the end of a user's message in conversational contexts.
    This token helps the model distinguish between different utterances in a multi-turn conversation and is
    particularly important for chat-based models.
c                óN   <€ V ^8„  d   Qh/ S[ R,          ;R&   S[ R,          ;R&   # )é   NÚadd_eos_tokenÚadd_end_of_utterance_token)Úbool)ÚformatÚ__classdict__s   "€Úo/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/idefics/processing_idefics.pyÚ__annotate__ÚIdeficsTextKwargs.__annotate__'   s'   ø‡ ‚ ñ ˜$•;Ññ ñ !% t¥Ñ+ò ó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r   s   @r   r   r   '   s   ø‡ € ñ÷ ƒ r   r   F)Útotalc                   óH   a € ] tR t^6t o RRRRRRR/RRR	//tV 3R
 ltRtV tR# )ÚIdeficsProcessorKwargsÚtext_kwargsÚadd_special_tokensFÚpaddingÚlongestr   Úcommon_kwargsÚreturn_tensorsÚptc                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   r(   )r   )r   r   s   "€r   r   Ú#IdeficsProcessorKwargs.__annotate__6   s   ø‡ ‚ Ù"Ñ"ò r   r   N)r   r   r   r   Ú	_defaultsr!   r"   r#   r$   s   @r   r'   r'   6   s9   ø‡ € ð 	Ø  %Ø�yØ˜Uð
ð
 	Ð*¨DÐ1ð€I÷ ƒ r   r'   c                 ó°   € VR8w  d   VR8X  d   RW V8¬  &   VR8X  d:   V R8H  p^ W&   \         P                  P                  P                  WR7      p^ WCR3&   X# )é   r.   ©Únum_classes:NNNéÿÿÿÿ)ÚtorchÚnnÚ
functionalÚone_hot)Úincremental_maskr-   r5   Ú	negativesÚ	attn_masks   &&&  r   Ú$incremental_to_binary_attention_maskr>   C   sm   € à�bÔØ˜TÔ!Ø@BÐ°Ñ<Ñ=ð ˜ÔØ$¨Ñ*ˆ	Ø&'ÐÑ#Ü—H‘H×'Ñ'×/Ñ/Ð0@Ð/ÓZˆ	Ø"#ˆ	˜Q�,ÑàÐr   c                 ó*   € VR 8X  d   \        W4      # R# )r.   N)Ú,image_attention_mask_for_packed_input_ids_pt)Ú	input_idsÚ	tokenizerr-   s   &&&r   Ú)image_attention_mask_for_packed_input_idsrC   T   s   € Ø˜ÔÜ;¸IÓQÐQñ r   c                 ó†  € \         P                  ! V RR7      p\         P                  ! V RR7      pVP                  \        4      pVP                  p\        V P                  ^ 4      4       Ff  pRpRp\        W,          4       FJ  w  ršW¤8X  d   V^,          pWrV,          V	&   RpMWrV,          V	&   V'       d   RW&,          V	&   W¥8X  g   KH  RpKL  	  Kh  	  \        V P                  ^ 4      4       FÌ  pRpRp\        W,          P                  ^ 4      ^,
          RR4       FW  p	W,          V	,          p
W¤8X  d   V^,          pWsV,          V	&   RpMWsV,          V	&   W¥8X  d   RpV'       g   KL  RW6,          V	&   KY  	  W6,          R8g  pW6,          V;;,          V,          uu&   W6,          V;;,          R,          uu&   KÎ  	  W#3# )r3   )Ú
fill_valueFTr6   )r7   Ú	full_likeÚconvert_tokens_to_idsÚIMAGE_TOKENÚeos_token_idÚrangeÚsizeÚ	enumerate)rA   rB   Úimage_attention_maskÚnext_image_attention_maskÚimage_token_idÚeod_token_idÚ	batch_idxÚcountÚseen_eodÚidxÚtoken_idÚnon_negative_indicess   &&          r   r@   r@   Y   s¦  € Ü Ÿ?š?¨9ÀÔDÐÜ %§¢°	ÀbÔ IÐØ×4Ñ4´[ÓA€NØ×)Ñ)€LÜ˜9Ÿ>™>¨!Ó,Ö-ˆ	ØˆØˆÜ& yÕ';Ö<‰MˆCØÔ)Ø˜•
�Ø7< YÕ/°Ñ4Ø ‘à7< YÕ/°Ñ4çØ79Ð$Õ/°Ñ4àÖ'Ø’ó =ñ .ô" ˜9Ÿ>™>¨!Ó,Ö-ˆ	ØˆØˆÜ˜Õ-×2Ñ2°1Ó5¸Õ9¸2¸rÖBˆCØ Õ+¨CÕ0ˆHØÔ)Ø˜•
�Ø<A¨)Õ4°SÑ9Ø ‘à<A¨)Õ4°SÑ9àÔ'Ø�ç‰xØ<>Ð)Õ4°SÓ9ñ Cð  9ÕCÀrÑIÐØ!Õ,Ð-A×BÀeÕKÓBØ!Õ,Ð-A×BÀbÕHÕBñ) .ð,  Ð:Ð:r   c                ól   € RV 9   d   R# \        V 4      p\        VP                  VP                  .4      # )z�Checks if the passed string contains a valid url and nothing else. e.g. if space is included it's immediately
invalidated the urlÚ F)r   ÚallÚschemeÚnetloc)ÚstringÚresults   & r   Úis_urlr^   ˆ   s0   € ð ˆf„}ÙÜ�fÓ€FÜ�—‘˜vŸ}™}Ð-Ó.Ð.r   c                   ój   a a€ ] tR t^‘t o]tRV 3R llt]RV3R lR ll4       t]	R 4       t
RtVtV ;t# )ÚIdeficsProcessorc                ó~  <€ \         SV `  W4       \        VR4      '       d   VP                  MVP	                  \
        4      V n        V P                  P                  V P                  P                  V P                  P                  3V n	        RV P                  P                  P                  R. 4      9   V n        R# )z×
image_size (int, *optional*, defaults to 224):
    The size of the image to be processed.
add_end_of_utterance_token (bool, *optional*, defaults to None):
    Whether to add the end of utterance token to the text.
Úimage_tokenú<end_of_utterance>Úadditional_special_tokensN)ÚsuperÚ__init__ÚhasattrrO   rG   rH   Úimage_processorÚimage_num_channelsÚ
image_sizeÚdefault_image_dimsrB   Úspecial_tokens_mapÚgetÚ1tokenizer_was_trained_with_end_of_utterance_token)Úselfrh   rB   rj   r   ÚkwargsÚ	__class__s   &&&&&,€r   rf   ÚIdeficsProcessor.__init__•   s¦   ø€ ô 	‰Ñ˜Ô4ô �y -×0Ò0ð ×$Ò$à×0Ñ0´Ó=ð 	Ôð × Ñ ×3Ñ3Ø× Ñ ×+Ñ+Ø× Ñ ×+Ñ+ð#
ˆÔð ! D§N¡N×$EÑ$E×$IÑ$IÐJeÐgiÓ$jÑjð 	Ö>r   c                ór  <€ V ^8„  d   QhRS[ S[S[ ,          ,          S[,          S[S[,          ,          S[S[S[,          ,          ,          RS[S[,          S[S[,          ,          S[S[,          ,          S[S[S[,          ,          ,          S[S[S[,          ,          ,          RS[S[,          RS[/# )r   ÚimagesÚtextrp   Úreturn)r   ÚlistÚstrr
   r	   r   r'   r   )r   r   s   "€r   r   ÚIdeficsProcessor.__annotate__®   s°   ø€ ÷ k
ñ k
á™T¡*Õ-Õ-±Õ3±d¹3µiÕ?Á$ÁtÉCÅyÅ/ÕQðk
ñ Ù
õá
‰y�/õñ Ñ Õ
!õ"ñ ‰t‘I�Õ
õ	 ñ
 ‰tÑ%Õ&Õ
'õ(ðk
ñ Ñ/Õ0ðk
ñ 
ñk
r   c           
     ó  a(a)€ Vf   Vf   \        R4      hVf   TpEMVEe   \        V\        \        34      '       g   V.p\        V\        4      '       d   V.p\        V\        \        34      '       d%   \        V4      \        V4      8w  d   \        R4      h\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        R4      h\        V^ ,          \        \        34      '       d#   \        W4       UUu. uF
  w  rVV.VONK  	  pppM\        \        W4      4      pV P                  ! \        3RV P                  P                  /VB pVR	,          P                  R
R4      pVR	,          P                  RR4      p	V	f   V P                  p	\        ;QJ d    R X 4       F  '       g   K   RM	  RM! R X 4       4      '       g   V.pRo(Ro)Rp
V(V)3R lp. p. pV EFy  pV P                  P                   p. pRpRp\!        V4       FÙ  w  ppV^ 8”  d   \#        V'       * 4      p\        V\        4      '       d†   VP%                  R4      p\'        V4      '       d?   V P(                  P+                  V4      pWë! V4      ,          pVP-                  V4       RpK“  V	'       d   V'       d	   Wê,          pVV,          pRpK¸  Wë! V4      ,          pVP-                  V4       RpKÛ  	  V'       d   WàP                  P.                  ,          p\        V4      ^ 8”  d   V P(                  ! V3/ VR,          B pVP-                  V4       VP-                  V4       EK|  	  VR	,          P                  RR4      pV P                  ! V3/ VR	,          B pVR,          pVR,          p\1        R V 4       4      p\1        ^V4      p\3        R V 4       4      ^ 8„  p. p. p. p\        VVV4       EF  w  ppp Tp!V!P5                  V P6                  4      p"\9        V"V4      p#V RV# p$\        V$4      ^ 8”  dJ   VR8X  dB   \:        P<                  ! V.V$P?                  4       R,          O5!  p%V$V%RV$P?                  ^ 4      % M)VR8X  d#   \:        P<                  ! V.V P@                  O5!  p%VP-                  X%4       VR8X  g   KÒ  VP-                  \:        PB                  ! V!4      4       VP-                  \:        PB                  ! V4      4       EK  	  VR8X  dC   \:        PD                  ! V4      p\:        PD                  ! V4      p\:        PD                  ! V4      pV'       d*   \G        VV P                  V4      w  p&p'\I        V&VVR7      p&MQVR8X  dK   \:        P<                  ! VPJ                  ^ ,          VPJ                  ^,          ^\:        P"                  R7      p&\M        RVRVRVRX&/R7      # u uppi )a4	  
Returns:
    a dict with entries: `input_ids`, `attention_mask`, `pixel_values`, `image_attention_mask` which can be
    directly passed to `model.generate`

    Detailed explanation:

    Each entry in `text` is either a text to be passed as is or an image that will be processed.

    An image can be either an image object (`PIL.Image`) or a url from which the image can be retrieved.

When the processor encounters an image it'll inject `<fake_token_around_image><image><fake_token_around_image>`
entry into the prompt.

Example:

```python
checkpoint = "HuggingFaceM4/idefics-9b"
processor = AutoProcessor.from_pretrained(checkpoint)
url = "https://hips.hearstapps.com/hmg-prod/images/cute-photos-of-cats-in-grass-1593184777.jpg"
img = processor.image_processor.fetch_images([url])[0]

prompts = [
    "User:",
    img,
    "Describe this image.\nAssistant: An image of two kittens in grass.\n",
    "User:",
    "https://hips.hearstapps.com/hmg-prod/images/dog-puns-1581708208.jpg",
    "Describe this image.\nAssistant:",
]

inputs = processor(text=prompts, return_tensors="pt")
generated_ids = model.generate(**inputs, max_length=100)
generated_text = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
```

In this example the `prompts` will be converted into:

```
<s>User:<fake_token_around_image><image><fake_token_around_image>Describe this image.
Assistant: An image of two kittens in grass.
User:<fake_token_around_image><image><fake_token_around_image>Describe this image.
Assistant:'
```

and the two images will be massaged using [`IdeficsImageProcessor.__call__`] method and placed inside the
`pixel_values` dict entry of the return value.

This example also exemplifies that images can be passed as objects or as text urls. It can be seen that the
first image is passed as object and the second one as a url.

To do training do:

```python
image_transform = transforms.Compose(
    [
        transforms.RandomResizedCrop(
            (w, h), scale=(0.9, 1.0), interpolation=transforms.InterpolationMode.BICUBIC
        ),
        transforms.ToTensor(),
        transforms.Normalize(mean=self.image_mean, std=self.image_std),
    ]
)
inputs = processor(text=prompts, transform=image_transform, return_tensors="pt")
```

In order to help debug prompt generation enable `debug=True` which will show you what's happening.

Nz9You need to specify either `text` or `images` and `text`.a  When providing both images and text arguments, the number of text prompts should be the same as the number of images.If you want to have several images per prompt, images should be nested as such: images=[[img1, img2], [img3, img4], ...] for text=[prompt1, prompt2, ...].c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5i©N)Ú
isinstancerx   ©Ú.0Úis   & r   Ú	<genexpr>Ú,IdeficsProcessor.__call__.<locals>.<genexpr>  s   é € Ð8±4¨a”z !¤S×)Ð)³4ùs   ‚FTzQWhen using the image-text-to-text behavior, the prompts should only contain text.Útokenizer_init_kwargsr(   r   r   c              3   óN   "  € T F  p\        V\        \        34      x € K  	  R # 5ir|   )r}   rw   Útupler~   s   & r   r�   r‚   '  s   é € ÐA¹°A”:˜a¤$¬ ×/Ð/»ùs   ‚#%z<fake_token_around_image>r   rc   c                 óF   <€ V '       d
   SS,           # SS,           S,           # r|   r   )Úlast_was_imageÚ
fake_tokenrb   s   &€€r   Úimage_tokensÚ/IdeficsProcessor.__call__.<locals>.image_tokens.  s!   ø€ ßØ" ZÕ/Ð/à! KÕ/°*Õ<Ð<r   rX   Úimages_kwargsr-   r.   rA   Úattention_maskc              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir|   ©Úlen©r   Úxs   & r   r�   r‚   e  s   é € Ð8©Z¨œS ŸV˜V«Zùó   ‚c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir|   rŽ   r�   s   & r   r�   r‚   h  s   é € Ð <±¨A¤ Q§ ³ùr’   :r3   NNr4   )ÚdtypeÚpixel_valuesrM   )Údata)'Ú
ValueErrorr}   rw   r…   rx   r�   rY   ÚzipÚ_merge_kwargsr'   rB   Úinit_kwargsÚpoprn   ÚanyÚ	bos_tokenrL   r   Ústripr^   rh   Úfetch_imagesÚappendÚ	eos_tokenÚmaxÚsumrR   rO   Úminr7   ÚzerosrK   rk   ÚtensorÚstackrC   r>   Úshaper   )*ro   rt   ru   rp   ÚpromptsÚ
image_listÚsampleÚoutput_kwargsr   r   Úend_of_utterance_tokenr‰   Úall_promptsÚ
all_imagesÚ	full_textÚimage_objectsr‡   Úlast_was_textr€   ÚitemÚimager-   Útext_encodingÚ	all_textsÚall_attention_masksÚmax_num_imagesÚat_least_one_imageÚoutput_input_idsÚoutput_imagesÚoutput_attention_masksÚtext_singlerŒ   Úextracted_imagesÚpadded_input_idsÚimage_countÚlocal_max_num_imagesÚcurrent_imagesÚpadded_image_tensorrM   Ú_rˆ   rb   s*   &&&,                                    @@r   Ú__call__ÚIdeficsProcessor.__call__­   s�  ù€ ðb Š>˜dšlÜÐXÓYÐYàŠ>àŠGØÓô ˜f¤t¬U m×4Ò4Ø ˜�Ü˜$¤×$Ò$Ø�v�ä˜$¤¤u ×.Ò.´3°t³9ÄÀFÃÔ3KÜ ðqóð ÷
 “3Ñ8±4Ó8—3—3’3Ñ8±4Ó8×8Ò8Ü Ð!tÓuÐuÜ˜& �)¤d¬E ]×3Ò3äKNÈvÔK\Ô]ÑK\Ñ5G°Z˜FÐ0 ZÓ0ÑK\�Ñ]�äœs 6Ó0Ó1�à×*Ò*Ü"ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð & mÕ4×8Ñ8¸È%ÓPˆØ%2°=Õ%A×%EÑ%EÐFbÐdhÓ%iÐ"ð &Ò-Ø)-×)_Ñ)_Ð&ç‹sÑA¹ÓA�s�sŠsÑA¹ÓA×AÒAØ�iˆGà0ˆ
ØˆØ!5Ðö	=ð ˆØˆ
ÜˆFàŸ>™>×3Ñ3Ð4ˆIð ˆMØ"ˆNØ!ˆMÜ$ VÖ,‘��4Ø�q”5Ü$(¨^Ô);Ó$<�Mä˜d¤C×(Ò(ØŸ:™: c›?�DÜ˜d—|’|Ø $× 4Ñ 4× AÑ AÀ$Ó G˜Ø! \°.Ó%AÕA˜	Ø%×,Ñ,¨UÔ3Ø)-š÷ 6¿-Ø%Õ?˜IØ! TÕ)˜	Ø).šð  ¨nÓ!=Õ=�IØ!×(Ñ(¨Ô.Ø%)’Nñ+ -÷. ØŸ^™^×5Ñ5Õ5�	ä�=Ó! AÔ%Ø $× 4Ò 4°]Ñ eÀmÐTcÕFdÑ e�à×Ñ˜yÔ)Ø×Ñ˜m×,ñM ðR ' }Õ5×9Ñ9Ð:JÈDÓQˆØŸš {ÑS°mÀMÕ6RÑSˆØ! +Õ.ˆ	Ø+Ð,<Õ=Ðô Ñ8©ZÓ8Ó8ˆÜ˜Q Ó/ˆä Ñ <±Ó <Ó<¸qÑ@ÐØÐØˆØ!#Ðä=@ÀÐL_Ðak×=lÑ9ˆK˜Ð)9Ø*ÐØ*×0Ñ0°×1DÑ1DÓEˆKÜ#& {°NÓ#CÐ Ø-Ð.CÐ/CÐDˆNä�>Ó" QÔ&Ø! TÔ)Ü*/¯+ª+°nÐ*aÀ~×GZÑGZÓG\Ð]_ÕG`Ó*aÐ'ØDRÐ'Ð(@¨.×*=Ñ*=¸aÓ*@ÐAøà! TÔ)Ü*/¯+ª+°nÐ*_Àt×G^ÑG^Ó*_Ð'à× Ñ Ð!4Ô5Ø Ö%Ø ×'Ñ'¬¯ªÐ5EÓ(FÔGØ&×-Ñ-¬e¯lªl¸>Ó.J×Kñ# >mð& ˜TÔ!Ü$Ÿ{š{Ð+;Ó<ÐÜ!ŸKšK¨Ó6ˆMÜ%*§[¢[Ð1GÓ%HÐ"çÜ&OØ  $§.¡.°.ó'Ñ#Ð  !ô $HØ$ nÀ.ô$Ñ ð
  Ô%Ü',§{¢{Ø$×*Ñ*¨1Õ-Ð/?×/EÑ/EÀaÕ/HÈ!ÔSX×S]ÑS]ô(Ð$ô àÐ-Ø Ð"8Ø Ø&Ð(<ð	ô
ð 	
ùóy ^s   ÄXc                óŒ   € V P                   P                  pV P                  P                  p\        W,           R .,           4      # )rM   )rB   Úmodel_input_namesrh   rw   )ro   Útokenizer_input_namesÚimage_processor_input_namess   &  r   rÈ   Ú"IdeficsProcessor.model_input_names›  s<   € à $§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#ÜÐ)ÕGÐKaÐJbÕbÓcÐcr   )rk   rO   rn   )Néà   N)NN)r   r   r   r   r'   Úvalid_processor_kwargsrf   r   rÅ   ÚpropertyrÈ   r"   r#   Ú__classcell__)rq   r   s   @@r   r`   r`   ‘   sI   ù‡ € à3Ð÷
ð0 ÷k
ñ k
ó ðk
ðZ ñdó ÷dð dr   r`   )r6   )r    Úurllib.parser   Úfeature_extraction_utilsr   Úimage_utilsr   Úprocessing_utilsr   r   r   r   Útokenization_utils_baser	   r
   Úutilsr   r   r7   rH   r   r'   r>   rC   r@   r^   r`   Ú__all__r   r   r   Ú<module>r×      sœ   ðñõ "å 4Ý %÷ó ÷ Dß 7ñ ×ÒÛð €ô,˜
¨%õ ,ô	Ð-°Uõ 	ôò"Rò
,;ò^/ð ôMd�~ó Mdó ðMdð` Ð
‚r   