
    "j,                     J
   d 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
mZmZmZmZmZ ddlmZmZ  ee          Z ej        dd	 eD             e
          Z ee          Z ej        dd eD             e
          Z ed          Ze                    dg d          dddd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                    ddg          ej        dfd ee ej        d!          f         de
deddfd"            Ze                    d#g d$          ddd%d%ej        dfd&ee 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  ej        d-          f         d.ee  ej        d/          f         de
deddfd0            Z!e                    d1g d2          dddddej        dfd ee ej        d!          f         d&eedz   ej        d3          f         d*eedz   ej        d4          f         d5ee"dz   ej        d6          f         d,ee dz   ej        d7          f         d8eedz   ej        d9          f         de
deddfd:            Z#e                    d;d<d=g          d%ej        dfd ee ej        d!          f         d>ee  ej        d?          f         de
deddf
d@            Z$e                    dAg dB          dd%ej        dfd ee ej        d!          f         dCee ej        dD          f         dEee ej        dF          f         dGeedz   ej        dH          f         d.ee  ej        dI          f         de
deddfdJ            Z%e                    dKdLdMg          ddej        dfd ee ej        d!          f         dNee ej        dO          f         dGeedz   ej        dP          f         d5ee"dz   ej        dQ          f         de
deddfdR            Z&e                    dS          d%ej        dfd ee ej        d!          f         dNee ej        dT          f         d>ee  ej        dU          f         de
deddfdV            Z'dS )Wa_  Contains commands to interact with collections on the Hugging Face Hub.

Usage:
    # list collections on the Hub
    hf collections ls

    # list collections for a specific user
    hf collections ls --owner username

    # get info about a collection
    hf collections info username/collection-slug

    # create a new collection
    hf collections create "My Collection" --description "A collection of models"

    # add an item to a collection
    hf collections add-item username/collection-slug username/model-name model

    # delete a collection
    hf collections delete username/collection-slug
    N)	Annotatedget_args)CollectionItemType_TCollectionSort_T   )FormatWithAutoOptLimitOptTokenOptapi_object_to_dict
get_hf_apityper_factory)OutputFormatWithAutooutCollectionItemTypec                     i | ]}||S  r   ).0ts     i/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/huggingface_hub/cli/collections.py
<dictcomp>r   1   s    5[5[5[qa5[5[5[    )typeCollectionSortc                     i | ]}||S r   r   )r   ss     r   r   r   4   s    -U-U-Uqa-U-U-Ur   z%Interact with collections on the Hub.)helpz	list | ls)zhf collections lsz hf collections ls --owner nvidiazLhf collections ls --item models/teknium/OpenHermes-2.5-Mistral-7B --limit 10)examples
   ownerz)Filter by owner username or organization.itemzkFilter collections containing a specific item (e.g., "models/gpt2", "datasets/squad", "papers/2311.12983").sortz4Sort results by last modified, trending, or upvotes.limitformattokenreturnc                     t          |          }|r|j        nd}d |                    | |||          D             }t          j        |           dS )zList collections on the Hub.r$   Nc                 ,    g | ]}t          |          S r   )r   )r   
collections     r   
<listcomp>z"collections_ls.<locals>.<listcomp>X   s0        	:&&  r   )r   r    r!   r"   )r   valuelist_collectionsr   table)	r   r    r!   r"   r#   r$   apisort_keyresultss	            r   collections_lsr1   :   s{    8 5
!
!
!C!+tzztH ..	 / 
 
  G Igr   infoz/hf collections info username/my-collection-slugcollection_slugz7The collection slug (e.g., 'username/collection-slug').c                 x    t          |          }|                    |           }t          j        |           dS )z'Get info about a collection on the Hub.r'   N)r   get_collectionr   dict)r3   r#   r$   r.   r)   s        r   collections_infor7   d   s=     5
!
!
!C##O44JHZr   create)z!hf collections create "My Models"z^hf collections create "My Models" --description "A collection of my favorite models" --privatez9hf collections create "Org Collection" --namespace my-orgFtitlezThe title of the collection.	namespacezMThe namespace (username or organization). Defaults to the authenticated user.descriptionz!A description for the collection.privatezCreate a private collection.	exists_okz7Do not raise an error if the collection already exists.c                     t          |          }|                    | ||||          }t          j        d|j        |j                   dS )z#Create a new collection on the Hub.r'   )r9   r:   r;   r<   r=   zCollection createdslugurlN)r   create_collectionr   resultr@   rA   )	r9   r:   r;   r<   r=   r#   r$   r.   r)   s	            r   collections_createrD   u   sa    < 5
!
!
!C&& '  J J#*/z~NNNNNNr   update)z@hf collections update username/my-collection --title "New Title"zPhf collections update username/my-collection --description "Updated description"zDhf collections update username/my-collection --private --theme greenz!The new title for the collection.z'The new description for the collection.positionz7The new position of the collection in the owner's list.z)Whether the collection should be private.themez;The theme color for the collection (e.g., 'green', 'blue').c                     t          |          }|                    | |||||          }	t          j        d|	j        |	j                   dS )z*Update a collection's metadata on the Hub.r'   )r3   r9   r;   rF   r<   rG   zCollection updatedr?   N)r   update_collection_metadatar   rC   r@   rA   )
r3   r9   r;   rF   r<   rG   r#   r$   r.   r)   s
             r   collections_updaterJ      se    D 5
!
!
!C//' 0  J J#*/z~NNNNNNr   deletez,hf collections delete username/my-collectionz9hf collections delete username/my-collection --missing-ok
missing_okz6Do not raise an error if the collection doesn't exist.c                     t          |          }|                    | |           t          j        d|            dS )z!Delete a collection from the Hub.r'   )rL   zCollection deletedr@   N)r   delete_collectionr   rC   )r3   rL   r#   r$   r.   s        r   collections_deleterP      sI    " 5
!
!
!C/jAAAJ#/::::::r   zadd-item)zGhf collections add-item username/my-collection moonshotai/kimi-k2 modelz`hf collections add-item username/my-collection Qwen/DeepPlanning dataset --note "Useful dataset"zGhf collections add-item username/my-collection Tongyi-MAI/Z-Image spaceitem_idzCThe ID of the item to add (repo_id for repos, paper ID for papers).	item_typezGThe type of item (model, dataset, space, paper, collection, or bucket).notez2A note to attach to the item (max 500 characters).z?Do not raise an error if the item is already in the collection.c                     t          |          }|                    | ||j        ||          }t          j        d| |j                   dS )zAdd an item to a collection.r'   )r3   rQ   rR   rS   r=   zItem added to collectionr?   N)r   add_collection_itemr+   r   rC   rA   )	r3   rQ   rR   rS   r=   r#   r$   r.   r)   s	            r   collections_add_itemrV      sa    : 5
!
!
!C(('/ )  J J)Z^TTTTTTr   zupdate-itemzVhf collections update-item username/my-collection ITEM_OBJECT_ID --note "Updated note"zMhf collections update-item username/my-collection ITEM_OBJECT_ID --position 0item_object_idzTThe ID of the item in the collection (from 'item_object_id' field, not the repo_id).z-A new note for the item (max 500 characters).z/The new position of the item in the collection.c                     t          |          }|                    | |||           t          j        d|            dS )zUpdate an item in a collection.r'   )r3   rW   rS   rF   zItem updated in collectionrN   N)r   update_collection_itemr   rC   )r3   rW   rS   rF   r#   r$   r.   s          r   collections_update_itemrZ   
  s[    2 5
!
!
!C'%	     J+/BBBBBBr   zdelete-itemznThe ID of the item in the collection (retrieved from `item_object_id` field returned by 'hf collections info'.z0Do not raise an error if the item doesn't exist.c                     t          |          }|                    | ||           t          j        d|            dS )z!Delete an item from a collection.r'   )r3   rW   rL   zItem deleted from collectionrN   N)r   delete_collection_itemr   rC   )r3   rW   rL   r#   r$   r.   s         r   collections_delete_itemr]   -  sX    " 5
!
!
!C'%    
 J-ODDDDDDr   )(__doc__enumtypingr   r   typerhuggingface_hub.hf_apir   r   
_cli_utilsr   r	   r
   r   r   r   _outputr   r   _COLLECTION_ITEM_TYPESEnumstrr   _COLLECTION_SORT_OPTIONSr   collections_clicommandautoOptionr1   Argumentr7   boolrD   intrJ   rP   rV   rZ   r]   r   r   r   <module>rp      s4
   ,  & & & & & & & &  I I I I I I I I l l l l l l l l l l l l l l l l . . . . . . . . ""677 TY35[5[DZ5[5[5[befff #8$455 +-U-U<T-U-U-U\_```  -%LMMM       	 	 	 4 9# d
EFFF	H
 d
~	
 	
 	
	 PQQQ	S   !" #$ 
%   D 
9    !5 9 sNEN8q$r$r$rrs  
	          	 	 	 	 4 9'O OS.%..LMMMMNOd
ijjj	lO d
=>>>	@O 8999	;O STTT	VO$ %O& 'O( 
)O O O OB       	 	 	 	 	 4 9/#O #OsNEN8q$r$r$rrs#Od
=>>>	@#O d
CDDD	F#O d
STTT	V#O tEFFF	H#O$ d
WXXX	Z%#O, -#O. /#O0 
1#O #O #O #OL 6C    	 4 9; ;sNEN8q$r$r$rrs;RSSS	U; ; ; 
; ; ; ;      ( 	 	 4 9%U UsNEN8q$r$r$rrsU^U^!fggggU
 efff	hU d
NOOO	QU [\\\	^U" #U$ %U& 
'U U U U@ `W     	 	 4 9C CsNEN8q$r$r$rrsCrsss	uC d
IJJJ	LC d
KLLL	NC C C  
!C C C C8 '' 	 4 9E EsNEN8q$r$r$rrsE B	
 	
 	
	E LMMM	OE E E 
E E E ('E E Er   