+
    œ°³j+t  ã            	       ó”  € R t ^ RIt^ RIt^ RIt^RIHt ^RIHt ^RIH	t	H
t
HtHtHt ^RIHt ^RIHtHt ^RIHt ]]]]3,          ,          ]]]]]]3,          ,          ,          ]]]]]3,          ,          ,          ,          ]]]]]]3,          ,          ,          ,          t]]R,          ]]R,          ]]R,          ]]R,          ,          ,          ,          ,          ,          ,          ,          t ! R R	]	R
R7      t ! R R]R
R7      t ! R R]
R
R7      t] ! R R]4      4       tR R ltR R lt R t!R t"R t#RR lt$R.t%R# )zProcessor class for KOSMOS-2.N)ÚBatchFeature)Ú
ImageInput)ÚImagesKwargsÚProcessingKwargsÚProcessorMixinÚ
TextKwargsÚUnpack)Ú
AddedToken)ÚBatchEncodingÚ	TextInput)Úauto_docstringc                   ó0   a € ] tR t^'t o RtV 3R ltRtV tR# )ÚKosmos2ImagesKwargsa‹  
bboxes (`Union[list[tuple[int]], list[tuple[float]], list[list[tuple[int]]], list[list[tuple[float]]]]`, *optional*):
    The bounding bboxes associated to `texts`.
num_image_tokens (`int`, *optional* defaults to 64):
    The number of (consecutive) places that are used to mark the placeholders to store image information.
    This should be the same as `latent_query_num` in the instance of `Kosmos2Config` you are using.
first_image_token_id (`int`, *optional*):
    The token id that will be used for the first place of the subsequence that is reserved to store image
    information. If unset, will default to `self.tokenizer.unk_token_id + 1`.
c                óZ   <€ V ^8„  d   Qh/ S[ R,          ;R&   S[;R&   S[R,          ;R&   # )é   NÚbboxesÚnum_image_tokensÚfirst_image_token_id)Ú
NestedListÚint)ÚformatÚ__classdict__s   "€Úo/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/models/kosmos2/processing_kosmos2.pyÚ__annotate__Ú Kosmos2ImagesKwargs.__annotate__'   s5   ø‡ ‚ ñ ˜ÕÑñ ñ Ññ ñ  �*Ñ$ò ó    © N©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__©r   s   @r   r   r   '   s   ø‡ € ñ	÷ ƒ r   r   F)Útotalc                   ó0   a € ] tR t^8t o RtV 3R ltRtV tR# )ÚKosmos2TextKwargsz‡
add_eos_token (`bool`, defaults to `False`):
Whether or not to include `EOS` token id in the encoding when `add_special_tokens=True`.
c                ó&   <€ V ^8„  d   Qh/ S[ ;R&   # )r   Úadd_eos_token)Úbool)r   r   s   "€r   r   ÚKosmos2TextKwargs.__annotate__8   s   ø‡ ‚ ñ Ñò r   r   Nr   r&   s   @r   r)   r)   8   s   ø‡ € ñ÷ ƒ r   r)   c                   ó`   a € ] tR t^At o RRRRRR^ RRRRR	RR
RRRRR/	RR^@//tV 3R ltRtV tR# )ÚKosmos2ProcessorKwargsÚtext_kwargsÚadd_special_tokensTÚpaddingFÚstrideÚreturn_overflowing_tokensÚreturn_special_tokens_maskÚreturn_offsets_mappingÚreturn_token_type_idsÚverboser+   Úimages_kwargsr   c                ó2   <€ V ^8„  d   Qh/ S[ ;R&   S[;R&   # )r   r0   r9   )r)   r   )r   r   s   "€r   r   Ú#Kosmos2ProcessorKwargs.__annotate__A   s   ø‡ ‚ Ù"Ñ"ñ á&Ñ&ò r   r   N)r   r   r    r!   Ú	_defaultsr#   r$   r%   r&   s   @r   r/   r/   A   sY   ø‡ € ð 	Ø  $Ø�uØ�aØ'¨Ø(¨%Ø$ eØ# UØ�tØ˜Uð

ð 	Ø ð
ð€I÷ ƒ r   r/   c                   óÄ   a a€ ] tR t^Vt o]tRV 3R llt]RV3R lR ll4       tR t	R t
RV3R lR lltRR ltRR	 lt]R
 4       tV3R lR ltV3R lR ltRtVtV ;t# )ÚKosmos2Processorc                óú  <€ RVn         RV n        RV n        RV n        RV n        RV n        RV n        RV n        R	V n        R
V n	        RV n
        RV n        V P                  V P                  V P                  V P                  V P
                  V P                  V P                  V P                  V P                  V P                  V P                  .V n        W0n        \        V P                  4       Uu. uF!  pR\        V4      P!                  ^4       R2NK#  	  pp. pV P                  V,            F!  pVP#                  \%        VRRRR7      4       K#  	  VP'                  V4       \(        S	V `U  W4       R# u upi )zv
num_patch_index_tokens (`int`, *optional*, defaults to 1024):
    The number of tokens that represent patch indices.
Fz</doc>z<image>z</image>z</chunk>z</line>z<phrase>z	</phrase>z<object>z	</object>ú</delimiter_of_multi_objects/>z<grounding>ú<patch_index_Ú>T)ÚlstripÚrstripÚ
normalizedN)r7   Ú	eod_tokenÚ	boi_tokenÚ	eoi_tokenÚ	eoc_tokenÚ	eol_tokenÚ	bop_tokenÚ	eop_tokenÚ	boo_tokenÚ	eoo_tokenÚ	dom_tokenÚ	grd_tokenÚ
tag_tokensÚnum_patch_index_tokensÚrangeÚstrÚzfillÚappendr	   Ú
add_tokensÚsuperÚ__init__)
ÚselfÚimage_processorÚ	tokenizerrR   ÚkwargsÚxÚpatch_index_tokensÚtokens_to_addÚtokenÚ	__class__s
   &&&&*    €r   rY   ÚKosmos2Processor.__init__Z   sJ  ø€ ð
 +0ˆ	Ô'à!ˆŒà"ˆŒØ#ˆŒà#ˆŒØ"ˆŒà#ˆŒØ$ˆŒà#ˆŒØ$ˆŒà9ˆŒà&ˆŒð �N‰NØ�N‰NØ�N‰NØ�N‰NØ�N‰NØ�N‰NØ�N‰NØ�N‰NØ�N‰NØ�N‰NØ�N‰Nð
ˆŒð '=Ô#ÜJOÐPT×PkÑPkÔJlÓmÑJlÀQ ¬c°!«f¯l©l¸1«oÐ->¸aÓ@ÑJlÐÐmàˆØ—_‘_Ð'9×9Ð9ˆEØ× Ñ ¤¨E¸$ÀuÐY^Ô!_Ö`ñ :à×Ñ˜]Ô+ä‰Ñ˜Ö4ùò ns   Ã3'E8c                óp   <€ V ^8„  d   QhRS[ R,          RS[S[S[,          ,          RS[S[,          RS[/# )r   ÚimagesNÚtextr]   Úreturn)r   r   Úlistr   r/   r   )r   r   s   "€r   r   ÚKosmos2Processor.__annotate__Œ   sM   ø€ ÷ Jñ Já˜TÕ!ðJñ ™$™y�/Õ)ðJñ Ñ/Õ0ð	Jñ
 
ñJr   c           
     ó&  € Vf   Vf   \        R4      hV P                  ! \        3RV P                  P                  /VB pVR,          P                  RR 4      pVR,          P                  R^@4      pVR,          P                  RR 4      pVR,          P                  RR	4      pVR,          R
,          p	VR,          R,          p
VR,          P                  RR 4      p\        4       pVe,   V P                  ! V3/ VR,          B pVP                  V4       VEe   V P                  W!WVR7      pV	'       dx   V'       gp   \        V\        4      '       d   V P                  P                   V 2pM>\        V\        4      '       d)   V Uu. uF  qàP                  P                   V 2NK  	  ppVR,          R
,          ;'       d    TVR,          R
&   Vf   T
MR	VR,          R&   Vf   TMR VR,          R&   V P                  ! RRV/VR,          B pVP                  V4       W”R,          R
&   W¤R,          R&   W´R,          R&   VEe!   VEe   Vf   V P                  P                  ^,           pT	p\!        V4      ^,           p\        \#        WwV,           4      4      p^ .^.V,          ,           ^ .,           p. p. pVR,          p\        V\        4      '       d   V.pVR,          .VR&   V F”  pVR V V,           VVV,           R  ,           pVP%                  V4       \&        P&                  ! V4      pV'       d   ^ .V,           pV^ .\)        V4      \)        V4      ,
          ,          ,          pVP%                  V4       K–  	  \        V\        4      '       Edf   \+        \-        XP.                  4       UUu. uF  w  ppV\)        V4      3NK  	  uppR R7      pV^ ,          w  ppVR,          w  ppVR,          R
,          ;'       d    TVR,          R
&   R VR,          R&   V P                  ! RRVV,          ./VR,          B p\)        VP.                  ^ ,          4      pVV8w  Ed–   V P                  P0                  R8X  d±   V Uu. uF8  pVV P                  P2                  .V\)        V4      ,
          ,          ,           NK:  	  ppV Uu. uF$  pV^ .V\)        V4      ,
          ,          ,           NK&  	  ppVR,           Uu. uF$  pV^ .V\)        V4      ,
          ,          ,           NK&  	  upVR&   MÊV P                  P0                  R8X  d°   V Uu. uF8  pV P                  P2                  .V\)        V4      ,
          ,          V,           NK:  	  ppV Uu. uF$  p^ .V\)        V4      ,
          ,          V,           NK&  	  ppVR,           Uu. uF$  p^ .V\)        V4      ,
          ,          V,           NK&  	  upVR&   \        V\        4      '       d*   Vf&   V^ ,          pVR,          ^ ,          VR&   V^ ,          pVP                  \5        RVRVR,          RV/VR7      4       V# u upi u uppi u upi u upi u upi u upi u upi u upi )Nz*You have to specify either images or text.Útokenizer_init_kwargsr9   r   r   r   r0   r+   Fr1   r2   Úreturn_tensors)r   rf   Ú	input_idsÚattention_maskc                 ó   € V R,          # ©é   éÿÿÿÿr   )r^   s   &r   Ú<lambda>Ú+Kosmos2Processor.__call__.<locals>.<lambda>æ   s   € ÐdeÐfhÖdir   )ÚkeyÚrightÚleftÚimage_embeds_position_mask)ÚdataÚtensor_typer   rr   )Ú
ValueErrorÚ_merge_kwargsr/   r\   Úinit_kwargsÚpopÚ
setdefaultr   r[   ÚupdateÚpreprocess_examplesÚ
isinstancerT   Ú	bos_tokenrh   Úunk_token_idr   rS   rV   ÚcopyÚlenÚsortedÚ	enumeraterm   Úpadding_sideÚpad_token_idr
   )rZ   re   rf   r]   Úoutput_kwargsr   r   r   r+   r1   r2   rl   ÚencodingÚimage_encodingÚsÚtext_encodingÚwith_bosÚstart_indexÚimage_token_idsÚbase_image_embeds_position_maskrm   rx   Úall_input_idsÚtext_idsÚmaskÚidxr^   Úsorted_lengthÚ_Úmin_len_not_paddedÚmax_len_paddeds   &&&,                           r   Ú__call__ÚKosmos2Processor.__call__‹   s…  € ð Š>˜dšlÜÐIÓJÐJà×*Ò*Ü"ñ
à"&§.¡.×"<Ñ"<ð
ð ñ
ˆð ˜Õ/×3Ñ3°H¸dÓCˆØ(¨Õ9×=Ñ=Ð>PÐRTÓUÐØ,¨_Õ=×AÑAÐBXÐZ^Ó_ÐØ% mÕ4×8Ñ8¸È%ÓPˆà*¨=Õ9Ð:NÕOÐØ Õ.¨yÕ9ˆØ& }Õ5×@Ñ@ÐAQÐSWÓXˆä“>ˆàÒØ!×1Ò1°&Ñ[¸MÈ/Õ<ZÑ[ˆNØ�O‰O˜NÔ+àÓØ×+Ñ+¨D¸&Ð+ÓdˆDç!¯-Ü˜d¤C×(Ò(Ø"Ÿn™n×6Ñ6Ð7¸°vÐ>‘DÜ ¤d×+Ò+ÙFJÓKÁdÀŸ~™~×7Ñ7Ð8¸¸Ó<Ád�DÐKà˜mÕ,Ð-AÕB×TÐTÀ}ð ˜-Õ(Ð)=Ñ>ð BHÂ±gÐUZˆM˜-Õ(¨Ñ3ØOUÊ~¹^ÐcgˆM˜-Õ(Ð)9Ñ:Ø ŸNšNÑU°ÐU¸ÀmÕ8TÑUˆMØ�O‰O˜MÔ*à=O�mÕ$Ð%9Ñ:Ø29�mÕ$ YÑ/Ø9G�mÕ$Ð%5Ñ6àÓ Ó 2à#Ò+Ø'+§~¡~×'BÑ'BÀQÕ'FÐ$ð *ˆHô ˜h›-¨!Õ+ˆKô #¤5Ð)=ÐVfÕ?fÓ#gÓhˆOØ/0¨c°Q°CÐ:JÕ4JÕ.JÈaÈSÕ.PÐ+ð ˆIØ)+Ð&Ø$ [Õ1ˆMä˜$¤×$Ò$Ø!. �Ø.6Ð7GÕ.HÐ-I�Ð)Ñ*Û)�à# L [Ð1°OÕCÀhÈ{Ð]mÕOmÐOoÐFpÕp�Ø× Ñ  Ô*ä—y’yÐ!@ÓA�ßà˜3 �:�Dà˜˜œs 8›}¬s°4«yÕ8Õ9Õ9�Ø*×1Ñ1°$Ö7ñ *ô ˜$¤×%Ó%Ü &Ü1:¸=×;RÑ;RÔ1SÔTÑ1S¡v s¨A�cœ3˜q›6“]Ñ1SÒTÑZiô!�ð )6°aÕ(8Ñ%�Ð%Ø& rÕ*‘��Qà! -Õ0Ð1EÕF×XÐXÈ=ð ˜mÕ,Ð-AÑBð BF�˜mÕ,Ð-=Ñ>à $§¢Ñ `°T¸#µY°KÐ `À=ÐQ^ÕC_Ñ `�Ü!$ ]×%<Ñ%<¸QÕ%?Ó!@�à%¨Õ7Ø—~‘~×2Ñ2°gÔ=ÙluÓ$vÑluÐgh Q¨$¯.©.×*EÑ*EÐ)FÈ.Ô[^Ð_`Ó[aÕJaÕ)b×%bÐ%bÑlu˜	Ð$váIcó6ÙIcÀA˜A   ~¼¸A»Õ'>Õ ?×?Ð?ÑIcð 3ð 6ð JRÐRbÖIcó6ÙIcÀA˜A   ~¼¸A»Õ'>Õ ?×?Ð?ÑIcñ6˜Ð!1Ò2ð Ÿ™×4Ñ4¸Ô>ÙluÓ$vÑluÐgh d§n¡n×&AÑ&AÐ%BÀnÔWZÐ[\ÓW]ÕF]Õ%^Ðab×%bÐ%bÑlu˜	Ð$váIcó6ÙIcÀA˜Q˜C >´C¸³FÕ#:Õ;¸a×?Ð?ÑIcð 3ð 6ð JRÐRbÖIcó6ÙIcÀA˜Q˜C >´C¸³FÕ#:Õ;¸a×?Ð?ÑIcñ6˜Ð!1Ñ2ô
 ˜$¤×$Ò$¨Ò)?Ø% a�L�	Ø-5Ð6FÕ-GÈÕ-J�Ð)Ñ*Ø-GÈÕ-JÐ*ð �O‰OÜà# YØ(¨(Ð3CÕ*DØ4Ð6Pðð
 !/ôô	ð ˆùòK Lùój Uùò %wùò6ùò6ùò %wùò6ùò6s0   Æ
"Y*Î8Y/
Ò
>Y5Ó*Y:Ô*Y?Õ>ZÖ*Z	×*Zc                ó$  € Vf   R# \        V\        4      '       g   \        R4      hV Fâ  pVf   K	  \        V\        4      '       g   V.pV Fº  p\        V\        4      '       d™   \	        V4      ^8X  d=   \
        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d   Ke  \	        V4      ^8X  d=   \
        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       d   K±  \        R4      h	  Kä  	  R# )aŠ  
Check `bboxes` for a single text example. It could be
    - `None`: no bounding box associated to a text.
    - A list with each element being the bounding boxes associated to one `<phrase> ... </phrase>` pair found
      in a text. This could be:
          - `None`: no bounding box associated to a `<phrase> ... </phrase>` pair.
          - A tuple of 2 integers: A single bounding box specified by patch indices.
          - A tuple of 4 float point number: A single bounding box specified by (normalized) coordinates.
          - A list containing the above 2 tuple types: Multiple bounding boxes for a
           `<phrase> ... </phrase>` pair.
Nz@`bboxes` (for a single text example) should be `None` or a list.c              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5i©N)r‚   r   ©Ú.0r^   s   & r   Ú	<genexpr>ÚAKosmos2Processor._check_bboxes_for_single_text.<locals>.<genexpr>1  s   é € Ð.SÉ7Àa¬z¸!¼S×/AÐ/AË7ùó   ‚FTc              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5ir    )r‚   Úfloatr¡   s   & r   r£   r¤   2  s   é € Ð1XÑPWÈ1´*¸QÄ×2FÐ2FÓPWùr¥   a'  Each element in `bboxes` (for a single text example) should be either `None`, a tuple containing 2 integers or 4 float point numbers, or a list containing such tuples. Also make sure the arguments `texts` and `bboxes` passed to `preprocess_text` are both in batches or both for a single example.)r‚   rh   r{   Útupler†   Úall)rZ   r   ÚbboxÚelements   &&  r   Ú_check_bboxes_for_single_textÚ.Kosmos2Processor._check_bboxes_for_single_text  sÑ   € ð Š>ÙÜ˜F¤D×)Ò)ÜÐ_Ó`Ð`ó ˆDØŠ|ÙÜ ¤d×+Ò+Ø�v�Û�Ü! '¬5×1Ò1Ü˜“\ QÔ&¯3«3Ñ.SÉ7Ó.S¯3¯3ª3Ñ.SÉ7Ó.S×+SÔ+SÜ˜G›¨Ô)¯c«cÑ1XÑPWÓ1X¯c¯cªcÑ1XÑPWÓ1X×.XÔ.Xä$ð@óð ó  ó r   c                ó^   € VP                  4       pVe   V RV 2pV P                  W4      pV# )NÚ )ÚstripÚ_insert_patch_index_tokens)rZ   rf   Úimager   Úimg_info_tokenss   &&&&&r   Ú_preprocess_single_exampleÚ+Kosmos2Processor._preprocess_single_example;  s;   € Ø�z‰z‹|ˆØÒà%Ð& a¨ vÐ.ˆDð ×.Ñ.¨tÓ<ˆØˆr   c                ó”   <€ V ^8„  d   QhRS[ S[S[ ,          ,          RS[R,          RS[RS[R,          RS[S[S[,          ,          /# )r   Útextsre   Nr   r   rg   )r   rh   r   Ú	BboxInputr   rT   )r   r   s   "€r   r   ri   E  s^   ø€ ÷ @ñ @á™4¡	�?Õ*ð@ñ ˜TÕ!ð@ñ ð	@ñ
  �*ð@ñ 
‰t‘C�y�ñ@r   c                óœ  € V P                   .V,          pRP                  V P                   .V,           V P                  .,           4      pRp\        V\        4      '       d   RpV.pVf   R.\        V4      ,          pM\        V\        4      '       g   V.p\        V4      \        V4      8w  d%   \        R\        V4       R\        V4       R24      hV'       g   V P                  V4       V.pMSVe=   \        V\        4      '       g   \        R4      hV F  pV P                  V4       K  	  MR.\        V4      ,          p\        V4      \        V4      8w  d%   \        R	\        V4       R\        V4       R24      h\        WV4       U	U
Uu. uF  w  ršpV P                  WšW¶4      NK  	  pp
p	pV'       g
   V^ ,          pV# u upp
p	i )
aÕ  Add image and bounding box information to `texts` as image and patch index tokens.

Args:
    texts (`Union[TextInput, list[TextInput]]`): The texts to be processed.
    images (`ImageInput`, *optional*): The images associated to `texts`.
    bboxes (`Union[list[tuple[int]], list[tuple[float]], list[list[tuple[int]]], list[list[tuple[float]]]]`, *optional*):
        The bounding bboxes associated to `texts`.
    num_image_tokens (`int`, *optional*, defaults to 64):
        The number of image tokens (used as latent queries). This should corresponds to the `latent_query_num`
        attribute in `Kosmos2Config`.

Returns:
    `Union[TextInput, list[TextInput]]`: The processed texts with image and patch index tokens.
r¯   TFNzGThe number of examples in `texts` and `images` should be the same. Got ú v.s. ú	 instead.zS`bboxes` should be `None` or a list (as a batch) when `texts` is passed as a batch.zGThe number of examples in `texts` and `bboxes` should be the same. Got )rG   ÚjoinrH   r‚   rT   r†   rh   r{   r¬   Úzipr´   )rZ   r·   re   r   r   Ú
img_tokensr³   Úbatchedr^   rf   r²   rª   Úresults   &&&&&        r   r�   Ú$Kosmos2Processor.preprocess_examplesE  sË  € ð, —n‘nÐ%Ð(8Õ8ˆ
ØŸ(™( D§N¡NÐ#3°jÕ#@ÀDÇNÁNÐCSÕ#SÓTˆð ˆÜ�eœS×!Ò!ØˆGØ�GˆEàŠ>Ø�Vœc %›jÕ(‰FÜ˜F¤D×)Ò)Ø�XˆFÜˆu‹:œ˜V›Ô$ÜØYÔZ]Ð^cÓZdÐYeÐekÔloÐpvÓlwÐkxð  yBð  Cóð ÷ Ø×.Ñ.¨vÔ6Ø�X‰FØÒÜ˜f¤d×+Ò+Ü Ð!vÓwÐwÛ�Ø×2Ñ2°1Ö5ò ð �Vœc %›jÕ(ˆFäˆv‹;œ#˜e›*Ô$ÜØYÔZ]Ð^cÓZdÐYeÐekÔloÐpvÓlwÐkxð  yBð  Cóð ô &)¨¸Ô%?õ
á%?Ñ!�˜Tð ×+Ñ+¨D¸ÖOÙ%?ð 	ò 
÷
 Ø˜A•YˆFàˆùô
s   ÆGc                óp   € VP                  V P                  4      R,          pV'       d   \        V4      # V# rp   )ÚsplitrH   Ú+clean_text_and_extract_entities_with_bboxes)rZ   rf   Úcleanup_and_extractÚcaptions   &&& r   Úpost_process_generationÚ(Kosmos2Processor.post_process_generation‡  s,   € Ø—*‘*˜TŸ^™^Ó,¨RÕ0ˆßÜ>¸wÓGÐGØˆr   c                óz   € V P                   ! V3RV/VB pV Uu. uF  qPP                  VRR7      NK  	  up# u upi )ah  
Post-process the output of the model to decode the text.

Args:
    generated_outputs (`torch.Tensor` or `np.ndarray`):
        The output of the model `generate` function. The output is expected to be a tensor of shape `(batch_size, sequence_length)`
        or `(sequence_length,)`.
    skip_special_tokens (`bool`, *optional*, defaults to `True`):
        Whether or not to remove special tokens in the output. Argument passed to the tokenizer's `batch_decode` method.
    **kwargs:
        Additional arguments to be passed to the tokenizer's `batch_decode method`.

Returns:
    `list[str]`: The decoded text.
Úskip_special_tokensF)rÅ   )Úbatch_decoderÇ   )rZ   Úgenerated_outputsrÊ   r]   Úgenerated_textsrf   s   &&&,  r   Úpost_process_image_text_to_textÚ0Kosmos2Processor.post_process_image_text_to_text�  sJ   € ð  ×+Ò+Ð,=ÑqÐSfÐqÐjpÑqˆÙZiÓjÑZiÐRV×,Ñ,¨TÀuÐ,ÖMÑZiÑjÐjùÒjs   š8c                óz   € V P                   P                  pV P                  P                  pW,           R .,           # )rx   )r\   Úmodel_input_namesr[   )rZ   Útokenizer_input_namesÚimage_processor_input_namess   &  r   rÑ   Ú"Kosmos2Processor.model_input_names   s6   € à $§¡× @Ñ @ÐØ&*×&:Ñ&:×&LÑ&LÐ#Ø$ÕBÐFbÐEcÕcÐcr   c                ó|   <€ V ^8„  d   QhRS[ RS[S[S[,          ,          S[S[S[,          ,          ,          RS[ /# )r   rf   r   rg   )rT   rh   r¨   r   r§   )r   r   s   "€r   r   ri   ¦  s=   ø€ ÷ +ñ +©sð +¹DÁÁsÅÕ<LÉtÑTYÑZ_ÕT`ÕOaÕ<að +Ñfiñ +r   c                ót  € Ve   \        V4      ^ 8X  d   V# \        \        P                  ! RVR7      4      p\        V4      \        V4      8w  d%   \	        R\        V4       R\        V4       R24      h^ p. p\        W24       Fü  w  rgVP                  4       w  r‰VP                  WV	 4       T	pVf   K2  \        V\        4      '       d   V.p. p
\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \	        R	4      hV F,  pV P                  V4      w  rÍV
P                  V R
V 24       K.  	  \        V
4      ^ 8X  d   KÖ  RP                  V
4      pVP                  RV R24       Kþ  	  V\        V4      8  d   VP                  WR  4       RP                  V4      pV# )Nz<phrase>.+?</phrase>)ÚstringzuThe number of elements in `bboxes` should be the same as the number of `<phrase> ... </phrase>` pairs in `text`. Got rº   r»   c              3   ó(   "  € T F  qR Jx € K
  	  R # 5ir    r   )r¢   Úboxs   & r   r£   Ú>Kosmos2Processor._insert_patch_index_tokens.<locals>.<genexpr>À  s   é € Ð7±$¨3 $•³$ùs   ‚FTzTThe multiple bounding boxes for a single phrase should not contain any `None` value.r¯   z  </delimiter_of_multi_objects/> z	<object> z
 </object>Ú )r†   rh   ÚreÚfinditerr{   r½   ÚspanrV   r‚   r¨   r©   Ú#_convert_bbox_to_patch_index_tokensr¼   )rZ   rf   r   Úmatched_phrasesÚcurr_posÚbufferÚmatchedrª   r™   ÚendÚpatch_index_stringsrÙ   Úpatch_index_1Úpatch_index_2Úposition_strs   &&&            r   r±   Ú+Kosmos2Processor._insert_patch_index_tokens¦  sÒ  € ØŠ>œS ›[¨AÔ-ØˆKäœrŸ{š{Ð+BÈ4ÔPÓQˆÜˆÓ¤3 v£;Ô.Üð Hô  ILð  M\ó  I]ð  H^ð  ^dô  ehð  ioó  epð  dqð  qzð  {óð ð ˆØˆÜ  Ö9‰MˆGØ—\‘\“^‰FˆAØ�M‰M˜$¨Ð,Ô-ØˆHàŠ|Ùä˜$¤×&Ò&Ø�v�Ø"$Ðç“3Ñ7±$Ó7—3—3’3Ñ7±$Ó7×7Ò7Ü Øjóð ó �Ø/3×/WÑ/WÐX[Ó/\Ñ,�Ø#×*Ñ*¨m¨_¸A¸m¸_Ð+MÖNñ ô Ð&Ó'¨1Ô,ÙØ=×BÑBÐCVÓWˆLØ�M‰M˜I l ^°:Ð>Ö?ñ/ :ð2 ”c˜$“iÔØ�M‰M˜$˜y˜/Ô*à�w‰w�v‹ˆØˆr   c                ó€   <€ V ^8„  d   QhRS[ S[S[3,          S[ S[S[S[S[3,          ,          RS[ S[S[3,          /# )r   rª   rg   )r¨   r   r§   rT   )r   r   s   "€r   r   ri   Ó  s@   ø€ ÷  ñ  Ù™#™s˜(•O¡e©E±5¹%ÁÐ,FÕ&GÕGð á	‰s‘Cˆx�ñ r   c                ó  € \        V4      ^8X  d   Vw  r#M6\        \        P                  ! V P                  4      4      p\        W4      w  r#R\        V4      P                  ^4       R2pR\        V4      P                  ^4       R2pWV3# )r   rA   rB   )r†   r   ÚmathÚsqrtrR   Úcoordinate_to_patch_indexrT   rU   )rZ   rª   Úidx_1Úidx_2Únum_patches_per_sideÚtoken_1Útoken_2s   &&     r   rß   Ú4Kosmos2Processor._convert_bbox_to_patch_index_tokensÓ  s…   € ô ˆt‹9˜Œ>Ø‰LˆE�5ô $'¤t§y¢y°×1LÑ1LÓ'MÓ#NÐ Ü4°TÓP‰LˆEà!¤# e£*×"2Ñ"2°1Ó"5Ð!6°aÐ8ˆØ!¤# e£*×"2Ñ"2°1Ó"5Ð!6°aÐ8ˆàÐÐr   )rG   rM   rK   rO   rI   rF   rH   rJ   rN   rL   rP   rR   rQ   )i   )NN)NNé@   )T)r   r   r    r!   r/   Úvalid_processor_kwargsrY   r   rœ   r¬   r´   r�   rÇ   rÎ   ÚpropertyrÑ   r±   rß   r$   r%   Ú__classcell__)rb   r   s   @@r   r>   r>   V   s�   ù‡ € à3Ð÷/5ðb ÷Jñ Jó ðJòX!òF÷@ò @ôDôkð& ñdó ðd÷
+ð +÷Z ÷  ð  r   r>   c                ó”   € V ^8„  d   QhR\         \        \        \        \        3,          R\        R\         \        \        3,          /# )r   rª   rñ   rg   )r¨   r§   r   )r   s   "r   r   r   å  s=   € ÷ ñ ¤E¬%´¼¼uÐ*DÕ$Eð Ô]`ð ÔejÔknÔpsÐksÕetñ r   c                óx  € V w  r#rEWB8”  d   WS8”  g   \        R4      h\        P                  ! W!,          4      p\        P                  ! W1,          4      p\        P                  ! WA,          ^,
          4      p\        P                  ! WQ,          ^,
          4      p	Wq,          V,           p
W‘,          V,           pW«3# )aå  Convert a bounding box to a pair of patch indices.

Args:
    bbox (`tuple[float, float, float, float]`):
        The 4 coordinates of the bounding box, with the format being (x1, y1, x2, y2) specifying the upper-left and
        lower-right corners of the box. It should have x2 > x1 and y2 > y1.
    num_patches_per_side (`int`): the number of patches along each side.

Returns:
    `tuple[int, int]`: A pair of patch indices representing the upper-left patch and lower-right patch.
zTThe coordinates in `bbox` should be `(x1, y1, x2, y2)` with `x2 > x1` and `y2 > y1`.)r{   rì   ÚfloorÚceil)rª   rñ   Úx1Úy1Úx2Úy2Úul_xÚul_yÚlr_xÚlr_yÚul_idxÚlr_idxs   &&          r   rî   rî   å  s“   € ð Ñ€RˆRàŒG˜œÜÐoÓpÐpä�:Š:�bÕ/Ó0€DÜ�:Š:�bÕ/Ó0€Dä�9Š9�RÕ.°Õ2Ó3€DÜ�9Š9�RÕ.°Õ2Ó3€DàÕ(¨4Õ/€FØÕ(¨4Õ/€Fàˆ>Ðr   c                ó<   € V ^8„  d   QhR\         R\         R\         /# )r   r  r  rñ   )r   )r   s   "r   r   r     s!   € ÷ (ñ (¤cð (´3ð (Ìcñ (r   c                óì  € RV,          pW,          pW,          pW,          pW,          pW8X  d0   WC,          pWS,          p	Wc,          V,           p
Ws,          V,           pM“WF8X  g   WW8X  d0   WC,          pWS,          p	Wc,          V,           p
Ws,          V,           pMXWC,          V^,          ,           pWS,          V^,          ,           p	Wc,          V^,          ,           p
Ws,          V^,          ,           pW‰W«3# )ak  
Given a grid of length `num_patches_per_side` and the indices of the upper-left and lower-right corners of a
bounding box, returns the normalized coordinates of the bounding box, in the form (x1, y1, x2, y2).

Args:
    ul_idx (`int`): the index of the grid cell that corresponds to the upper-left corner of the bounding box.
    lr_idx (`int`): the index of the grid cell that corresponds to the lower-right corner of the bounding box.
    num_patches_per_side (`int`): the number of patches along each side.

Returns:
    `tuple[float]`: the normalized coordinates of the bounding box, in the form (x1, y1, x2, y2).
g      ð?r   )r  r  rñ   Ú	cell_sizer  r  r  r  rý   rþ   rÿ   r   s   &&&         r   Úpatch_index_to_coordinater
    sä   € ð Ð*Õ*€Ið Õ(€DØÕ)€DàÕ(€DØÕ)€Dð ÔØÕˆØÕˆØÕ 	Õ)ˆØÕ 	Õ)‰Ø	Œ˜œØÕˆØÕˆØÕ 	Õ)ˆØÕ 	Õ)‰àÕ 	¨A¥Õ-ˆØÕ 	¨A¥Õ-ˆØÕ 	¨A¥Õ-ˆØÕ 	¨A¥Õ-ˆà�2ˆ>Ðr   c           
     óš  € Rp\         P                  ! W4      p. pV EF©  pVP                  ^4      pVP                  4       w  rgpV'       g3   RpVP                  ^ 4      ^ ,          VP                  ^ 4      ^ ,          3pVP	                  R4      p	. p
V	 FÜ  p\         P
                  ! RV4      p\         P
                  ! RVR,          4      pV'       g   KB  V'       g   KL  V'       dF   V
P                  \        VP                  ^4      4      \        VP                  ^4      4      34       K™  V
P                  \        VP                  ^4      4      \        VP                  ^4      4      34       KÞ  	  V'       d   VP                  WuV
34       EKu  V
 F.  pRV^ ,           RV^,           R2pVP                  WõV.34       K0  	  EK¬  	  V# )	aº  Extract entities contained in `text`. The bounding bboxes is given in the form of patch indices.

This function is only intended to be used within `clean_text_and_extract_entities_with_bboxes` where further
processing happens, including converting to normalized coordinates and whitespace character cleaning up.

Examples:

```python
>>> text = "<grounding> An image of<phrase> a snowman</phrase><object><patch_index_0044><patch_index_0863></object> warming himself by<phrase> a fire</phrase><object><patch_index_0005><patch_index_0911></object>."
>>> entities = extract_entities_with_patch_indices(text)
>>> entities
[(' a snowman', (31, 41), [(44, 863)]), (' a fire', (130, 137), [(5, 911)])]
```z™(?:(<phrase>([^<]+)</phrase>))?<object>((?:<patch_index_\d+><patch_index_\d+></delimiter_of_multi_objects/>)*<patch_index_\d+><patch_index_\d+>)</object>Nr@   z<patch_index_(\d+)>:rq   NNrA   z><patch_index_rB   )	rÜ   rÝ   rÞ   ÚgroupsrÃ   ÚsearchrV   r   Úgroup)rf   ÚpatternÚmatchesÚentities_with_patch_indicesÚmatchrÞ   Ú
phrase_tagÚphraseÚmatch_contentÚpatch_index_pairsÚentity_bboxesÚpairr^   Úyrª   Úentitys   &               r   Ú#extract_entities_with_patch_indicesr  1  s|  € ð k€Gô �kŠk˜'Ó(€Gð #%Ðäˆà�z‰z˜!‹}ˆØ,1¯L©L«NÑ)ˆ
˜MßØˆFà—J‘J˜q“M !Õ$ e§j¡j°£m°AÕ&6Ð7ˆDð *×/Ñ/Ð0PÓQÐàˆÛ%ˆDä—	’	Ð0°$Ó7ˆAÜ—	’	Ð0°$°rµ(Ó;ˆAç‰q—Q‘QßØ!×(Ñ(¬#¨a¯g©g°a«j«/¼3¸q¿w¹wÀq»z»?Ð)KÖLà!×(Ñ(¬#¨a¯g©g°a«j«/¼3¸q¿w¹wÀq»z»?Ð)KÖLñ &÷ Ø'×.Ñ.°¸mÐ/L×Mã%�à(¨¨a­¨	°ÀÀQÅ¸yÈÐJ�Ø+×2Ñ2°FÀ4À&Ð3IÖJô &ñ7 ð@ 'Ð&r   c           	     ó®   € V w  pw  r4\        \        P                  ! RRVRV 4      4      p\        \        P                  ! RRVRV 4      4      pW%V33pV# )zfAdjust the positions of the entities in `text` to be relative to the text with special fields removed.ú<.*?>rÛ   N)r†   rÜ   Úsub)r  rf   Úentity_nameÚstarträ   Úadjusted_startÚadjusted_endÚadjusted_entitys   &&      r   Úadjust_entity_positionsr$  k  s[   € à &Ñ€K‘�%äœŸš ¨¨T°&°5¨\Ó:Ó;€NÜ”r—v’v˜g r¨4°°¨:Ó6Ó7€LØ"°\Ð$BÐC€OØÐr   c                óÆ  € V P                  4       p\        V 4      \        V P                  4       4      ,
          p. pV Fž  w  pw  rgp\        V4      \        VP                  4       4      ,
          p	\        V4      \        VP                  4       4      ,
          p
Wc,
          V	,           pWs,
          V
,
          pVP                  4       pVP	                  WVV3V34       K   	  W$3# )z9Remove the spaces around the text and the entities in it.)r°   r†   rC   rD   rV   )rf   ÚentitiesÚnew_textÚleading_spacesÚnew_entitiesr  r   rä   r   Úentity_name_leading_spacesÚentity_name_trailing_spacess   &&         r   Ú_cleanup_spacesr,  u  sÆ   € à�z‰z‹|€HÜ˜“Y¤ T§[¡[£]Ó!3Õ3€Nà€LÛ-5Ñ)ˆ‘\�e 6Ü%(¨Ó%5¼¸K×<NÑ<NÓ<PÓ8QÕ%QÐ"Ü&)¨+Ó&6¼¸[×=OÑ=OÓ=QÓ9RÕ&RÐ#àÕ&Ð)CÕCˆØÕ"Ð%@Õ@ˆØ!×'Ñ'Ó)ˆà×Ñ˜[°#¨,¸Ð?Ö@ñ .6ð Ð!Ð!r   c           	     ó:  € \         P                  ! RRV 4      p\        V 4      p. pV Fa  pVR,          V^,          rv\        W`4      pV U	u. uF  p	\	        V	^ ,          V	^,          V4      NK   	  p
p	VP                  WŠ3,           4       Kc  	  \        W$4      # u up	i )ay  Remove the tag tokens from `text`, extract entities in it with some cleaning up of white characters.

Examples:

```python
>>> text = "<grounding> An image of<phrase> a snowman</phrase><object><patch_index_0044><patch_index_0863></object> warming himself by<phrase> a fire</phrase><object><patch_index_0005><patch_index_0911></object>."
>>> clean_text, entities = clean_text_and_extract_entities_with_bboxes(text)
>>> clean_text
'An image of a snowman warming himself by a fire.'

>>> entities
[('a snowman', (12, 21), [(0.390625, 0.046875, 0.984375, 0.828125)]), ('a fire', (41, 47), [(0.171875, 0.015625, 0.484375, 0.890625)])]
```r  rÛ   :é    r   N)rÜ   r  r  r$  r
  rV   r,  )rf   rñ   Úprocessed_textr  r&  Úitemr  r   r#  rª   Úbboxes_in_coordss   &&         r   rÄ   rÄ   Š  s™   € ô —V’V˜G R¨Ó.€Nä"EÀdÓ"KÐØ€HÛ+ˆØ˜c� D¨¥G�Ü1°&Ó?ˆÙjpÓqÑjpÐbfÔ5°d¸1µg¸tÀA½wÐH\Ö]ÑjpÐÐqà�‰˜Ð*=Õ=Ö>ñ ,ô ˜>Ó4Ð4ùò	 rs   Á$B)é    )&r"   r…   rì   rÜ   Úimage_processing_utilsr   Úimage_utilsr   Úprocessing_utilsr   r   r   r   r   Útokenization_pythonr	   Útokenization_utils_baser
   r   Úutilsr   rh   r¨   r   r§   r¸   r   r   r)   r/   r>   rî   r
  r  r$  r,  rÄ   Ú__all__r   r   r   Ú<module>r:     sC  ðñ $ã Û Û 	å 2Ý %ß bÕ bÝ -ß ?Ý #ð 	ˆˆs�Cˆx�ÕØ
ˆ5�˜˜u eÐ+Õ,Õ-õ.à
ˆ4��c˜3�h•Õ Õ!õ"ð ˆ4��e˜U EÐ)Õ*Õ+Õ,õ-ð 
ð �%˜$•,  e¨d¥l°T¸%À$½,ÈÈeÐVZÍlÕI[Õ:[Õ5\Õ&\Õ!]Õ]Õ^€
ô%˜,¨eõ %ô"˜
¨%õ ôÐ-°Uõ ð* ôK �~ó K ó ðK õ\õ>(òZ7'òtò"ô*5ð: Ð
‚r   