+
    QV-j¯/  ã                   ó   € ^ RI t ^ RIHtHt ^ RIHt ^ RIHt ^ RIH	t	H
t
HtHtHtHt ^ RIt^RIHt ^RIHt ^RIHt ^R	IHtHtHt ^R
IHtHt ]	'       d   ^ RIt^RIH t  R R lt!] ! R R4      4       t"R R lt#R# )é    N)Ú	dataclassÚfield)ÚBytesIO)ÚPath)ÚTYPE_CHECKINGÚAnyÚClassVarÚDictÚOptionalÚUnion)Úconfig)ÚDownloadConfig)Ú
array_cast)Úis_local_pathÚis_remote_urlÚxopen)Úno_op_if_value_is_nullÚstring_to_dict)ÚFeatureTypec                ó(   € V ^8„  d   QhRRR\         /# ©é   Úpdfúpdfplumber.pdf.PDFÚreturn)Úbytes)Úformats   "Úf/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/datasets/features/pdf.pyÚ__annotate__r      s   € ÷ !ñ !Ð*ð !¬uñ !ó    c                óô   € \        4       ;_uu_ 4       pV P                   F(  pVP                  VP                  P                  4       K*  	  VP                  4       uuRRR4       #   + '       g   i     R# ; i)z-Convert a pdfplumber.pdf.PDF object to bytes.N)r   ÚpagesÚwriter   ÚstreamÚgetvalue)r   ÚbufferÚpages   &  r   Úpdf_to_bytesr(      sC   € ä	�Œ�fØ—I”IˆDØ�L‰L˜Ÿ™Ÿ™Ö)ñ à�‰Ó ÷ 
��‹ús   “AA&Á&A7	c                   ó2  a € ] tR t^t o RtRt]! RRR7      tRt]	P                  ! R]	P                  ! 4       R]	P                  ! 4       /4      t]! R RRR	7      tR
 tV 3R lR ltRV 3R lR lltV 3R lR ltV 3R lR ltRV 3R lR lltV 3R ltRtV tR# )ÚPdfaD  
**Experimental.**
Pdf [`Feature`] to read pdf documents from a pdf file.

Input: The Pdf feature accepts as input:
- A `str`: Absolute path to the pdf file (i.e. random access is allowed).
- A `pathlib.Path`: path to the pdf file (i.e. random access is allowed).
- A `dict` with the keys:
    - `path`: String with relative path of the pdf file in a dataset repository.
    - `bytes`: Bytes of the pdf file.
  This is useful for archived files with sequential access.

- A `pdfplumber.pdf.PDF`: pdfplumber pdf object.

Args:
    decode (`bool`, defaults to `True`):
        Whether to decode the pdf data. If `False`,
        returns the underlying dictionary in the format `{"path": pdf_path, "bytes": pdf_bytes}`.

Examples:

```py
>>> from datasets import Dataset, Pdf
>>> ds = Dataset.from_dict({"pdf": ["path/to/pdf/file.pdf"]}).cast_column("pdf", Pdf())
>>> ds.features["pdf"]
Pdf(decode=True, id=None)
>>> ds[0]["pdf"]
<pdfplumber.pdf.PDF object at 0x7f8a1c2d8f40>
>>> ds = ds.cast_column("pdf", Pdf(decode=False))
>>> ds[0]["pdf"]
{'bytes': None,
'path': 'path/to/pdf/file.pdf'}
```
TNF)ÚdefaultÚreprr   r   Úpath)r+   Úinitr,   c                ó   € V P                   # ©N)Úpa_type)Úselfs   &r   Ú__call__ÚPdf.__call__K   s   € Ø�|‰|Ðr    c                óF   <€ V ^8„  d   QhRS[ S[S[S[S[R3,          RS[/# )r   Úvaluer   r   )r   Ústrr   Ú	bytearrayÚdict)r   Ú__classdict__s   "€r   r   ÚPdf.__annotate__N   s-   ø€ ÷ !ñ !¡E©#©u±iÁÐG[Ð*[Õ$\ð !Ñaeñ !r    c                óà  € \         P                  '       d   ^ RIpMRp\        V\        4      '       d   RVRR/# \        V\
        4      '       d   R\	        VP                  4       4      RR/# \        V\        \        34      '       d   RRRV/# Ve1   \        WP                  P                  4      '       d   \        V4      # VP                  R4      eB   \        P                  P                  VR,          4      '       d   RRRVP                  R4      /# VP                  R4      f   VP                  R4      e%   RVP                  R4      RVP                  R4      /# \!        RV R24      h)zÌEncode example into a format for Arrow.

Args:
    value (`str`, `bytes`, `pdfplumber.pdf.PDF` or `dict`):
        Data passed as input to Pdf feature.

Returns:
    `dict` with "path" and "bytes" fields
Nr-   r   zRA pdf sample should have one of 'path' or 'bytes' but they are missing or None in Ú.)r   ÚPDFPLUMBER_AVAILABLEÚ
pdfplumberÚ
isinstancer7   r   Úabsoluter   r8   r   ÚPDFÚencode_pdfplumber_pdfÚgetÚosr-   ÚisfileÚ
ValueError)r2   r6   r?   s   && r   Úencode_exampleÚPdf.encode_exampleN   s9  € ô ×&×&Ð&ÜàˆJä�eœS×!Ò!Ø˜E 7¨DÐ1Ð1Ü˜œt×$Ò$ØœC §¡Ó 0Ó1°7¸DÐAÐAÜ˜¤¤yÐ1×2Ò2Ø˜D '¨5Ð1Ð1ØÒ#¬
°5¿.¹.×:LÑ:L×(MÒ(Mä(¨Ó/Ð/Ø�Y‰Y�vÓÒ*¬r¯w©w¯~©~¸eÀF½m×/LÒ/Là˜T 6¨5¯9©9°VÓ+<Ð=Ð=Ø�Y‰Y�wÓÒ+¨u¯y©y¸Ó/@Ò/Là˜UŸY™Y wÓ/°¸¿¹À6Ó9JÐKÐKäØdÐejÐdkÐklÐmóð r    c                ó$   <€ V ^8„  d   QhRS[ RR/# )r   r6   r   r   ©r9   )r   r:   s   "€r   r   r;   q   s   ø€ ÷ 8ñ 8¡Dð 8ÐEYñ 8r    c                ó6  € V P                   '       g   \        R4      h\        P                  '       d   ^ RIpM\        R4      hVf   / pVR,          VR,          rTVfæ   Vf   \        RV R24      h\        V4      '       d   VP                  ! V4      pV# VP                  R4      R,          pVP                  \        P                  4      '       d   \        P                  M\        P                  p \        Wx4      R	,          p	VP                  V	4      p
\!        V
R
7      p\#        VRVR7      pVP                  ! V4      # VP                  ! \%        V4      4      ;_uu_ 4       pTpRRR4       V#   \         d    Rp
 Lki ; i  + '       g   i     X# ; i)a  Decode example pdf file into pdf data.

Args:
    value (`str` or `dict`):
        A string with the absolute pdf file path, a dictionary with
        keys:

        - `path`: String with absolute or relative pdf file path.
        - `bytes`: The bytes of the pdf file.

    token_per_repo_id (`dict`, *optional*):
        To access and decode pdf files from private repositories on
        the Hub, you can pass a dictionary
        repo_id (`str`) -> token (`bool` or `str`).

Returns:
    `pdfplumber.pdf.PDF`
zKDecoding is disabled for this feature. Please use Pdf(decode=True) instead.Nz6To support decoding pdfs, please install 'pdfplumber'.r-   r   z@A pdf should have one of 'path' or 'bytes' but both are None in r=   ú::Úrepo_id©ÚtokenÚrb©Údownload_configéÿÿÿÿ)ÚdecodeÚRuntimeErrorr   r>   r?   ÚImportErrorrG   r   ÚopenÚsplitÚ
startswithÚHF_ENDPOINTÚHUB_DATASETS_URLÚHUB_DATASETS_HFFS_URLr   rD   r   r   r   )r2   r6   Útoken_per_repo_idr?   r-   Úbytes_r   Ú
source_urlÚpatternrN   rP   rS   ÚfÚps   &&&           r   Údecode_exampleÚPdf.decode_exampleq   sq  € ð& �{�{ˆ{ÜÐlÓmÐmä×&×&Ð&ÜäÐVÓWÐWàÒ$Ø "Ðà˜V•} e¨G¥nˆfØŠ>ØŠ|Ü Ð#cÐdiÐcjÐjkÐ!lÓmÐmä  ×&Ò&Ø$Ÿ/š/¨$Ó/�Cð( ˆ
ð% "&§¡¨DÓ!1°"Õ!5�Jð &×0Ñ0´×1CÑ1C×DÒDô ×/Ò/ä#×9Ñ9ð ð
%Ü"0°Ó"EÀiÕ"P˜Ø 1× 5Ñ 5°gÓ >˜ô '5¸5Ô&A�OÜ˜d D¸/ÔJ�AØ%Ÿ?š?¨1Ó-Ð-à—’¤¨£×1Ô1°QØ�÷ 2ð ˆ
øô &ô %Ø $šð%ú÷ 2Ö1ð ˆ
ús   Ã5#E4 Å'FÅ4FÆFÆF	c                óH   <€ V ^8„  d   QhRS[ RS[S[R3,          3,          /# )r   r   r   )r   r
   r7   )r   r:   s   "€r   r   r;   «   s(   ø€ ÷ 
ñ 
™˜}©d±3¸Ð3EÕ.FÐFÕGñ 
r    c                óZ   € ^RI Hp V P                  '       d   V # RV! R4      RV! R4      /# )zfIf in the decodable state, return the feature itself, otherwise flatten the feature into a dictionary.)ÚValuer   Úbinaryr-   Ústring)Úfeaturesrh   rU   )r2   rh   s   & r   ÚflattenÚPdf.flatten«   s8   € å#ð �{�{ˆ{ð ð	
ð ™˜x›Ø™˜h›ðð	
r    c                ó�   <€ V ^8„  d   QhRS[ S[P                  S[P                  S[P                  3,          RS[P                  /# )r   Ústorager   )r   ÚpaÚStringArrayÚStructArrayÚ	ListArray)r   r:   s   "€r   r   r;   ¸   s:   ø€ ÷ #1ñ #1¡E©"¯.©.¹"¿.¹.É"Ï,É,Ð*VÕ$Wð #1Ñ\^×\jÑ\jñ #1r    c                ó*  € \         P                  P                  VP                  4      '       dr   \         P                  ! R.\        V4      ,          \         P                  ! 4       R7      p\         P                  P                  W!.RR.VP                  4       R7      pEMß\         P                  P                  VP                  4      '       dr   \         P                  ! R.\        V4      ,          \         P                  ! 4       R7      p\         P                  P                  W.RR.VP                  4       R7      pEM?\         P                  P                  VP                  4      '       Ed   VP                  P                  R4      ^ 8¼  d   VP                  R4      pM<\         P                  ! R.\        V4      ,          \         P                  ! 4       R7      pVP                  P                  R4      ^ 8¼  d   VP                  R4      pM<\         P                  ! R.\        V4      ,          \         P                  ! 4       R7      p\         P                  P                  W#.RR.VP                  4       R7      p\        WP                   4      # )a¯  Cast an Arrow array to the Pdf arrow storage type.
The Arrow types that can be converted to the Pdf pyarrow storage type are:

- `pa.string()` - it must contain the "path" data
- `pa.binary()` - it must contain the image bytes
- `pa.struct({"bytes": pa.binary()})`
- `pa.struct({"path": pa.string()})`
- `pa.struct({"bytes": pa.binary(), "path": pa.string()})`  - order doesn't matter
- `pa.list(*)` - it must contain the pdf array data

Args:
    storage (`Union[pa.StringArray, pa.StructArray, pa.ListArray]`):
        PyArrow array to cast.

Returns:
    `pa.StructArray`: Array in the Pdf arrow storage type, that is
        `pa.struct({"bytes": pa.binary(), "path": pa.string()})`.
N©Útyper   r-   ©Úmask)rp   ÚtypesÚ	is_stringrv   ÚarrayÚlenri   rr   Úfrom_arraysÚis_nullÚ	is_binaryrj   Ú	is_structÚget_field_indexr   r   r1   )r2   ro   Úbytes_arrayÚ
path_arrays   &&  r   Úcast_storageÚPdf.cast_storage¸   s¶  € ô& �8‰8×Ñ˜gŸl™l×+Ò+ÜŸ(š( D 6¬C°«LÕ#8¼r¿yºy»{ÔKˆKÜ—n‘n×0Ñ0°+Ð1GÈ'ÐSYÐIZÐah×apÑapÓarÐ0ÓsŠGÜ�X‰X×Ñ §¡×-Ò-ÜŸš 4 &¬3¨w«<Õ"7¼b¿iºi»kÔJˆJÜ—n‘n×0Ñ0°'Ð1FÈÐRXÐHYÐ`g×`oÑ`oÓ`qÐ0ÓrŠGÜ�X‰X×Ñ §¡×-Ó-Ø�|‰|×+Ñ+¨GÓ4¸Ô9Ø%Ÿm™m¨GÓ4‘ä Ÿhšh¨ v´°G³Õ'<Ä2Ç9Â9Ã;ÔO�Ø�|‰|×+Ñ+¨FÓ3°qÔ8Ø$Ÿ]™]¨6Ó2‘
äŸXšX t f¬s°7«|Õ&;Ä"Ç)Â)Ã+ÔN�
Ü—n‘n×0Ñ0°+Ð1JÈWÐV\ÐL]Ðdk×dsÑdsÓduÐ0ÓvˆGÜ˜'§<¡<Ó0Ð0r    c                óZ   <€ V ^8„  d   QhRS[ P                  RS[RS[RS[ P                  /# )r   ro   Úlocal_filesÚremote_filesr   )rp   rr   Úbool)r   r:   s   "€r   r   r;   Ý   s;   ø€ ÷ C1ñ C1Ù—~‘~ðC1ÙLPðC1ÙgkðC1á	�‰ñC1r    c           	     ó�  a€ Sf   / o\         V3R l4       p\        P                  ! VP                  4        Uu. uFl  pVed   VR,          fP   V'       d   \	        VR,          4      '       g!   V'       d(   \        VR,          4      '       d   V! VR,          4      M
VR,          MRNKn  	  up\        P                  ! 4       R7      p\        P                  ! VP                  R4      P                  4        Uu. uF\  pVeT   V'       d   \	        V4      '       g   V'       d1   \        V4      '       d    \        P                  P                  V4      MTMRNK^  	  up\        P                  ! 4       R7      p	\        P                  P                  Wy.RR.VP                  4       R7      p\        WP                   4      # u upi u upi )a³  Embed PDF files into the Arrow array.

Args:
    storage (`pa.StructArray`):
        PyArrow array to embed.
    token_per_repo_id (`dict`, optional):
        Dictionary repo_id -> token to fetch the files bytes.
    local_files (`bool`, defaults to `True`)
        Whether to embed local files data in the array

        <Added version="4.8.5"/>
    remote_files (`bool`, defaults to `True`)
        Whether to embed remote files data in the array.
        E.g. files with paths that start with hf:// or https://

        <Added version="4.8.5"/>

Returns:
    `pa.StructArray`: Array in the PDF arrow storage type, that is
        `pa.struct({"bytes": pa.binary(), "path": pa.string()})`.
Nc                 ó²  <€ V P                  R 4      R,          pVP                  \        P                  4      '       d   \        P                  M\        P
                  p\        W4      pVe   SP                  VR,          4      MRp\        VR7      p\        V RVR7      ;_uu_ 4       pVP                  4       uuRRR4       #   + '       g   i     R# ; i)rM   NrN   rO   rQ   rR   rT   )rY   rZ   r   r[   r\   r]   r   rD   r   r   Úread)r-   r`   ra   Úsource_url_fieldsrP   rS   rb   r^   s   &      €r   Úpath_to_bytesÚ(Pdf.embed_storage.<locals>.path_to_bytesø   s£   ø€ àŸ™ DÓ)¨"Õ-ˆJà+5×+@Ñ+@Ä×ASÑAS×+TÒ+T”×'Ò'ÔZ`×ZvÑZvð ô !/¨zÓ CÐØK\ÒKhÐ%×)Ñ)Ð*;¸IÕ*FÔGÐnrˆEÜ,°5Ô9ˆOÜ�t˜T°?×CÕCÀqØ—v‘v“x÷ D×C×CÓCús   Â*CÃC	r   r-   ru   rw   )r   rp   r{   Ú	to_pylistr   r   ri   r   rE   r-   Úbasenamerj   rr   r}   r~   r   r1   )
r2   ro   r^   r‡   rˆ   rŽ   Úxr‚   r-   rƒ   s
   &&f&&     r   Úembed_storageÚPdf.embed_storageÝ   s”  ø€ ð0 Ò$Ø "Ðä	ô		 ó 
 ð		 ô —h’hð !×*Ñ*Ô,ó
ñ -�Að ’=ð	 ˜•zÒ)ß%¬-¸¸&½	×*BÒ*BÏÔYfÐghÐioÕgp×YqÒYqñ " ! F¥)Ô,ð ˜7žð òñ -ñ
ô —’“ô
ˆô —X’Xð $ŸM™M¨&Ó1×;Ñ;Ô=ó	ñ >�Dð Ò#÷ $¬°d×(;Ò(;ÇÔR_Ð`d×ReÒReô —G‘G×$Ñ$ TÔ*áð òñ >ñ	ô —’“ô
ˆ
ô —.‘.×,Ñ,¨kÐ-FÈÐRXÐHYÐ`g×`oÑ`oÓ`qÐ,ÓrˆÜ˜'§<¡<Ó0Ð0ùò7
ùò	s#   ¹F>ÁF>Á56F>Ã8GÄ	GÄ"8Gc                ó†   <€ V ^8„  d   Qh/ S[ ;R&   S[S[,          ;R&   S[S[,          ;R&   S[S[,          ;R&   S[;R&   # )r   rU   ÚidÚdtyper1   Ú_type)r‰   r   r7   r	   r   )r   r:   s   "€r   r   r;      s\   ø‡ ‚ ñJ ÑñK ñL 	‘�Ñ7ñM ñR ‘C�=Ñ/ñS ñT ‘c�]ÑSñU ñV Ñ=òW r    © r0   )NTT)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rU   r   r–   r—   rp   Ústructri   rj   r1   r˜   r3   rH   rd   rl   r„   r“   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__)r:   s   @r   r*   r*      sš   ø‡ € ñ!ðF €FÙ d°Ô7€Bð 0€EØŸYšY¨°·²³¸fÀbÇiÂiÃkÐ'RÓS€GÙ˜u¨5°uÔ=€Eò÷!ð !÷F8ò 8÷t
ð 
÷#1ð #1÷JC1ò C1÷ ƒ r    r*   c                ó(   € V ^8„  d   QhRRR\         /# r   rK   )r   s   "r   r   r   #  s   € ÷ :ñ :Ð3ð :¼ñ :r    c                óè   € \        V R4      '       dS   \        V P                  R4      '       d7   V P                  P                  '       d   RV P                  P                  RR/# RRR\        V 4      /# )a!  
Encode a pdfplumber.pdf.PDF object into a dictionary.

If the PDF has an associated file path, returns the path. Otherwise, serializes
the PDF content into bytes.

Args:
    pdf (pdfplumber.pdf.PDF): A pdfplumber PDF object.

Returns:
    dict: A dictionary with "path" or "bytes" field.
r$   Únamer-   r   N)Úhasattrr$   r¥   r(   )r   s   &r   rC   rC   #  sZ   € ô ˆs�H×Ò¤'¨#¯*©*°f×"=Ò"=À#Ç*Á*Ç/Ç/À/à˜Ÿ
™
Ÿ™¨°$Ð7Ð7ð ˜˜g¤|°CÓ'8Ð9Ð9r    )$rE   Údataclassesr   r   Úior   Úpathlibr   Útypingr   r   r	   r
   r   r   Úpyarrowrp   Ú r   Údownload.download_configr   Útabler   Úutils.file_utilsr   r   r   Úutils.py_utilsr   r   r?   rk   r   r(   r*   rC   r™   r    r   Ú<module>r±      s^   ðÛ 	ß (Ý Ý ß F× Fã å Ý 5Ý ß BÑ Bß C÷ Ûå%õ!ð ÷A1ð A1ó ðA1÷H:r    