
    iQ                        d Z ddlZddlZddlmZmZ ddlZddlmZm	Z	 ddl
mZ ddlmZmZmZmZmZmZ ddlmZmZ  ee      Z ej.                  d	eD  ci c]  } | |  c} e
      Zdedz  dedz  fdZ ed      Zej9                  dg d      ddddddej:                  dfdeedz   ej<                  de      f   deedz   ej<                  d      f   deedz   ej<                  d      f   deedz   ej<                  d      f   deedz   ej<                  d      f   ded ed!eddfd"       Zej9                  d#g d$      d%ej:                  dfd&ee ej@                  d'      f   ded ed!eddf
d(       Z!ej9                  d)d*g      ej:                  dfd+ee ej@                  d,      f   d ed!eddfd-       Z"ej9                  d.d/g      	 d1d+ee ej@                  d,      f   d!eddfd0       Z#yc c} w )2a  Contains commands to interact with papers on the Hugging Face Hub.

Usage:
    # list daily papers (most recently submitted)
    hf papers ls

    # list trending papers
    hf papers ls --sort=trending

    # list papers from a specific date, ordered by upvotes
    hf papers ls --date=2025-01-23

    # list today's papers, ordered by upvotes
    hf papers ls --date=today

    # list papers from a specific week
    hf papers ls --week=2025-W09

    # list papers by a specific submitter
    hf papers ls --submitter=someuser

    # search papers
    hf papers search "vision language"

    # get info about a paper
    hf papers info 2502.08025

    # read a paper as markdown
    hf papers read 2502.08025
    N)	Annotatedget_args)CLIErrorHfHubHTTPError)DailyPapersSort_T   )FormatWithAutoOptLimitOptTokenOptapi_object_to_dict
get_hf_apityper_factory)OutputFormatWithAutooutPaperSortEnum)typevaluereturnc                     | y| j                         dk(  r,t        j                  j                         j	                         S | S )z6Parse date option, converting 'today' to current date.Ntoday)lowerdatetimedater   	isoformat)r   s    k/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/huggingface_hub/cli/papers.py_parse_dater   E   s9    }{{}}}""$..00L    z Interact with papers on the Hub.)helpz	list | ls)zhf papers lszhf papers ls --sort trendingzhf papers ls --date 2025-01-23zhf papers ls --week 2025-W09z hf papers ls --submitter akhaliqzhf papers ls --format json)examples2   r   z+Date in ISO format (YYYY-MM-DD) or 'today'.)r   callbackweekz'ISO week to filter by, e.g. '2025-W09'.monthz;Month to filter by in ISO format (YYYY-MM), e.g. '2025-02'.	submitterz$Filter by username of the submitter.sortzSort results.limitformattokenc                 j   t        |      }|r|j                  nd}	g }
|j                  | ||||	|      D ]^  }t        |      }|j	                  d      xs i }|j	                  d      xs |j	                  d      xs d|d<   |
j                  |       ` t        j                  |
g d	d
d
d       y)zList daily papers on the Hub.r(   N)r   r"   r#   r$   r%   r&   submitted_byfullnameusername submitted_by_name)idtitleupvotescommentspublished_atr/   right)r2   r3   headers
alignments)r   r   list_daily_papersr   getappendr   table)r   r"   r#   r$   r%   r&   r'   r(   apisort_keyresults
paper_infoitemr+   s                 r   	papers_lsrB   Q   s    P 5
!C!tzztHG++ ,  
 "*-xx/52$0$4$4Z$@$fLDTDTU_D`$fdf !t II[&G<r   search)z"hf papers search "vision language"z1hf papers search "attention mechanism" --limit 10z*hf papers search "diffusion" --format json   queryzSearch query string.c                     t        |      }|j                  | |      D cg c]  }t        |       }}t        j                  |g dddi       yc c}w )zSearch papers on the Hub.r*   )rE   r&   )r0   r1   summaryr2   r4   r2   r5   r6   N)r   list_papersr   r   r<   )rE   r&   r'   r(   r=   r@   r?   s          r   papers_searchrI      sT     5
!C@CV[ch@ij*!*-jGjIIgTbkmtauv ks   Ainfozhf papers info 2601.15621paper_idz'The arXiv paper ID (e.g. '2502.08025').c                     t        |      }	 |j                  |       }t        j                  |       y# t        $ r/}|j                  j                  dk(  rt        d|  d      | d}~ww xY w)z"Get info about a paper on the Hub.r*   r0     Paper '' not found on the Hub.N)r   r@   r   responsestatus_coder   r   dict)rK   r'   r(   r=   rJ   es         r   papers_inforU      sn     5
!C~~~*
 HHTN	  ::!!S(WXJ.EFGQN   6 	A.*A))A.readzhf papers read 2601.15621c                     t        |      }	 |j                  |       }t        j                  |       y# t        $ r/}|j                  j                  dk(  rt        d|  d      | d}~ww xY w)zRead a paper as markdown.r*   rM   rN   rO   rP   N)r   
read_paperr   rQ   rR   r   r   text)rK   r(   r=   contentrT   s        r   papers_readr\      so     5
!C..H.-
 HHW	  ::!!S(WXJ.EFGQNrV   )N)$__doc__r   enumtypingr   r   typerhuggingface_hub.errorsr   r   huggingface_hub.hf_apir   
_cli_utilsr	   r
   r   r   r   r   _outputr   r   _SORT_OPTIONSEnumstrr   r   
papers_clicommandautoOptionrB   ArgumentrI   rU   r\   )ss   0r   <module>rn      sD  >   &  ; 4  / *+		/-+HQAqD+HsSsTz cDj   BC
   
$ 	 	 	 	 	 4 9 950
d
> 	
	0 d
CD	F0 d
WX	Z0  d
@A	C!0( /*	,)00 102 304 506 
70
0f     4 9 9		wS.%...DEEF	w	w 	w 		w
 
	w	w 
#   !5 9 9^U^^1Z[[\  
	  
#   ^U^^1Z[[\ 
{ ,Is   
H	
