o
    0jC                     @   s  d Z ddlZddlmZmZ ddlZddlmZmZm	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mZmZmZmZmZ dd	lmZ dd
lmZ eeeZ eeZ!ej"ddd e!D e#dZ$ee#dB ej%dd&e  dee df Z'eddZ(e(j)dg ddddddddeddddddfdee#dB ej*ddf dedededee#dB ej%ddf d ee$dB ej%d!df d"ed#e'd$ee+ej%d%d&d'df d(ee+ej%d)d*df d+ee+ej%d,d-d.df d/ed0ed1dfd2d3Z,e(j)d4d5d6gd			dEd7ee#ej*d8df d/ed#e'd0ed1df
d9d:Z-e(j)d;g d<d			dFd7ee#ej*d8df d=ee+ej%d>d?df d@ee+ej%dAdBdf d0ed1df
dCdDZ.dS )Ga  Contains commands to interact with models on the Hugging Face Hub.

Usage:
    # list models on the Hub
    hf models ls

    # list models with a search query
    hf models ls --search "llama"

    # get info about a model
    hf models info Lightricks/LTX-2
    N)	Annotatedget_args)CLIErrorRepositoryNotFoundErrorRevisionNotFoundError)ExpandModelProperty_TModelSort_T)	ModelCard   )REPO_LIST_DEFAULT_LIMIT	AuthorOpt	FilterOptLimitOptRevisionOpt	SearchOptTokenOptapi_object_to_dict
get_hf_apimake_expand_properties_parsertyper_factory)list_repo_files_cmd)outModelSortEnumc                 C   s   i | ]}||qS  r   ).0sr   r   [/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/cli/models.py
<dictcomp>7   s    r   )typezComma-separated properties to return. When used, only the listed properties (and id) are returned. Example: '--expand=downloads,likes,tags'. Valid: z, .)helpcallbackz Interact with models on the Hub.)r    z	list | ls)z(hf models ls --sort downloads --limit 10z1hf models ls --search "llama" --author meta-llamaz:hf models ls --num-parameters min:6B,max:128B --sort likesz-hf models ls meta-llama/Llama-3.2-1B-Instructz0hf models ls meta-llama/Llama-3.2-1B-Instruct -Rz7hf models ls meta-llama/Llama-3.2-1B-Instruct --tree -h)ZexamplesFrepo_idzRModel ID (e.g. `username/repo-name`) to list files from. If omitted, lists models.searchauthorfilternum_parametersz2Filter by parameter count, e.g. 'min:6B,max:128B'.sortzSort results.limitexpandhuman_readablez--human-readablez-hz=Show sizes in human readable format (only for listing files).as_treez--treez3List files in tree format (only for listing files).	recursivez--recursivez-Rz0List files recursively (only for listing files).revisiontokenreturnc              
   C   s   | durN|durt d|durt d|durt d|dur(t d|dur1t d|tkr:t d|durCt dt| d	||	|
||d
S |	rUt d|
r\t d|rct d|durlt dt|d}|rv|jnd}dd |j|||||||dD }t| dS )zList models on the Hub, or files in a model repo.

    When called with no argument, lists models on the Hub.
    When called with a model ID, lists files in that model repo.
    Nz'Cannot use --search when listing files.z'Cannot use --author when listing files.z'Cannot use --filter when listing files.z/Cannot use --num-parameters when listing files.z%Cannot use --sort when listing files.z&Cannot use --limit when listing files.z'Cannot use --expand when listing files.model)r"   Z	repo_typer*   r+   r,   r-   r.   z&Cannot use --tree when listing models.z+Cannot use --recursive when listing models.z0Cannot use --human-readable when listing models.z*Cannot use --revision when listing models.r.   c                 S   s   g | ]}t |qS r   )r   )r   
model_infor   r   r   
<listcomp>   s    zmodels_ls.<locals>.<listcomp>)r%   r$   r#   r&   r'   r(   r)   )	typerZBadParameterr   r   r   valueZlist_modelsr   table)r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   apisort_keyresultsr   r   r   	models_lsF   s\   1












r:   infoz/hf models info meta-llama/Llama-3.2-1B-Instructz<hf models info Qwen/Qwen3.5-9B --expand downloads,likes,tagsmodel_idz)The model ID (e.g. `username/repo-name`).c              
   C   s   t |d}z
|j| ||d}W n, ty$ } z	td|  d|d}~w ty; } ztd| d|  d|d}~ww t| dS )	z"Get info about a model on the Hub.r1   )r"   r-   r)   zModel 'z' not found.Nz
Revision 'z' not found on 'z'.)r   r2   r   r   r   r   dict)r<   r-   r)   r.   r7   r;   er   r   r   models_info   s   
r?   card)z$hf models card google/gemma-4-31B-itz/hf models card google/gemma-4-31B-it --metadataz=hf models card google/gemma-4-31B-it --metadata --format jsonz+hf models card google/gemma-4-31B-it --textmetadataz
--metadataz'Output only the metadata from the card.textz--textz(Output only the text body (no metadata).c                 C   sl   |r|rt dtj| |d}|rt|j  dS |r%t|j dS t|j t	d|  d dS )z3Get the model card (README) for a model on the Hub.z---metadata and --text are mutually exclusive.r1   zUse `hf models card z/ --metadata` to extract only the card metadata.N)
r   r	   loadr   r=   datato_dictrB   contenthint)r<   rA   rB   r.   r@   r   r   r   models_card   s   rH   )NNN)FFN)/__doc__enumtypingr   r   r4   Zhuggingface_hub.errorsr   r   r   Zhuggingface_hub.hf_apir   r   Zhuggingface_hub.repocardr	   Z
_cli_utilsr   r   r   r   r   r   r   r   r   r   r   Z_file_listingr   _outputr   sortedZ_EXPAND_PROPERTIESZ_SORT_OPTIONSEnumstrr   OptionjoinZ	ExpandOptZ
models_clicommandZArgumentboolr:   r?   rH   r   r   r   r   <module>   s  4
	


 X	