
    Ziw+                     6
   d Z ddlZddlZddlmZ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mZ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dfdeee          ej        d          f         deee          ej        d          f         deee          ej        d          f         dededededdfd            Ze                    dd g          	 dWd!ee ej         d"          f         deddfd#            Z!e                    d$g d%          	 	 	 	 	 dXd&ee ej         d'          f         d(eee          ej        d)          f         d*eee          ej        d+          f         d,ee" ej        d-          f         d.ee" ej        d/          f         deddfd0            Z#e                    d1g d2          	 	 	 	 	 	 dYd!ee ej         d"          f         d&eee          ej        d3          f         d*eee          ej        d4          f         d5eee$          ej        d6          f         d,eee"          ej        d7          f         d8eee          ej        d9          f         deddfd:            Z%e                    d;d<d=g          	 	 dZd!ee ej         d"          f         d>ee" ej        d?          f         deddfd@            Z&e                    dAg dB          	 	 	 d[d!ee ej         d"          f         dCee ej         dD          f         dEee ej         dF          f         dGeee          ej        dH          f         d.ee" ej        dI          f         deddfdJ            Z'e                    dKdLdMg          	 	 	 d\d!ee ej         d"          f         dNee ej         dO          f         dGeee          ej        dP          f         d5eee$          ej        dQ          f         deddfdR            Z(e                    dS          	 	 dZd!ee ej         d"          f         dNee ej         dT          f         d>ee" ej        dU          f         deddf
dV            Z)dS )]a_  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Optionalget_args)CollectionItemType_TCollectionSort_T   )		FormatOptLimitOptOutputFormatQuietOptTokenOptapi_object_to_dict
get_hf_apiprint_list_outputtyper_factoryCollectionItemTypec                     i | ]}||S  r   ).0ts     Z/root/projects/butler/venv/lib/python3.11/site-packages/huggingface_hub/cli/collections.py
<dictcomp>r   ;   s    5[5[5[qa5[5[5[    )typeCollectionSortc                     i | ]}||S r   r   )r   ss     r   r   r   >   s    -U-U-Uqa-U-U-Ur   z%Interact with collections on the Hub.)helpls)zhf collections lsz hf collections ls --owner nvidiazLhf collections ls --item models/teknium/OpenHermes-2.5-Mistral-7B --limit 10)examples
   F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quiettokenreturnc                     t          |          }|r|j        nd}d |                    | |||          D             }	t          |	||           dS )zList collections on the Hub.r(   Nc                 ,    g | ]}t          |          S r   )r   )r   
collections     r   
<listcomp>z"collections_ls.<locals>.<listcomp>c   s0        	:&&  r   )r"   r#   r$   r%   )r&   r'   )r   valuelist_collectionsr   )
r"   r#   r$   r%   r&   r'   r(   apisort_keyresultss
             r   collections_lsr4   D   s    : 5
!
!
!C!+tzztH ..	 / 
 
  G gfE::::::r   infoz/hf collections info username/my-collection-slugcollection_slugz7The collection slug (e.g., 'username/collection-slug').c                     t          |          }|                    |           }t          t          j        t          |          d                     dS )z'Get info about a collection on the Hub.r+      indentN)r   get_collectionprintjsondumpsr   )r6   r(   r1   r-   s       r   collections_infor?   o   sS     5
!
!
!C##O44J	$*'
33A
>
>
>?????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-org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          d|j                    t          t	          j        t          |          d                     dS )z#Create a new collection on the Hub.r+   )rA   rB   rC   rD   rE   zCollection created: r8   r9   N)r   create_collectionr<   urlr=   r>   r   )rA   rB   rC   rD   rE   r(   r1   r-   s           r   collections_createrI      s    : 5
!
!
!C&& '  J 

1
1
1222	$*'
33A
>
>
>?????r   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          d|j                    t          t	          j        t          |          d                     dS )z*Update a collection's metadata on the Hub.r+   )r6   rA   rC   rK   rD   rL   zCollection updated: r8   r9   N)r   update_collection_metadatar<   rH   r=   r>   r   )	r6   rA   rC   rK   rD   rL   r(   r1   r-   s	            r   collections_updaterO      s    B 5
!
!
!C//' 0  J 

1
1
1222	$*'
33A
>
>
>?????r   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                 x    t          |          }|                    | |           t          d|             dS )z!Delete a collection from the Hub.r+   )rQ   zCollection deleted: N)r   delete_collectionr<   )r6   rQ   r(   r1   s       r   collections_deleterT      sJ      5
!
!
!C/jAAA	
2
2
233333r   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_typez?The type of item (model, dataset, space, paper, or collection).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          d|             t          t	          j        t          |          d                     dS )zAdd an item to a collection.r+   )r6   rU   rV   rW   rE   zItem added to collection: r8   r9   N)r   add_collection_itemr/   r<   r=   r>   r   )r6   rU   rV   rW   rE   r(   r1   r-   s           r   collections_add_itemrZ      s    8 5
!
!
!C(('/ )  J 

8
8
8999	$*'
33A
>
>
>?????r   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          d|             dS )zUpdate an item in a collection.r+   )r6   r[   rW   rK   zItem updated in collection: N)r   update_collection_itemr<   )r6   r[   rW   rK   r(   r1   s         r   collections_update_itemr^     s\    0 5
!
!
!C'%	     

:
:
:;;;;;r   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                 z    t          |          }|                    | ||           t          d|             dS )z!Delete an item from a collection.r+   )r6   r[   rQ   zItem deleted from collection: N)r   delete_collection_itemr<   )r6   r[   rQ   r(   r1   s        r   collections_delete_itemra   5  sY      5
!
!
!C'%    
 

<?
<
<=====r   )N)NNFFN)NNNNNN)FN)NFN)NNN)*__doc__enumr=   typingr   r   r   typerhuggingface_hub.hf_apir   r   
_cli_utilsr	   r
   r   r   r   r   r   r   r   _COLLECTION_ITEM_TYPESEnumstrr   _COLLECTION_SORT_OPTIONSr   collections_clicommandtableOptionr4   Argumentr?   boolrI   intrO   rT   rZ   r^   ra   r   r   r   <module>rs      s	   ,   0 0 0 0 0 0 0 0 0 0  I I I I I I I I
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ""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       	 	 	$*% ;  ;EFFF	H ;
 ~	
 	
 	
	 ;  PQQQ	S ;  ;  ! ;" # ;$ % ;& 
' ;  ;  ;  ;F 
9    @ @sNEN8q$r$r$rrs@@ 
@ @ @ @       	 	 	 	%@ @S.%..LMMMMN@ijjj	l@ =>>>	@@ 8999	;@ STTT	V@$ %@& 
'@ @ @ @B       	 	 	 	 	-#@ #@sNEN8q$r$r$rrs#@=>>>	@#@ CDDD	F#@ STTT	V#@ EFFF	H#@$ WXXX	Z%#@, -#@. 
/#@ #@ #@ #@L 6C    	4 4sNEN8q$r$r$rrs4RSSS	U4 4 
4 4 4 4      ( 	 	#@ @sNEN8q$r$r$rrs@^U^!fgggg@
 ]^^^	`@ NOOO	Q@ [\\\	^@" #@$ 
%@ @ @ @@ `W     	 	< <sNEN8q$r$r$rrs<rsss	u< IJJJ	L< KLLL	N< < 
< < < <6 '' 	> >sNEN8q$r$r$rrs> B	
 	
 	
	> LMMM	O> > 
> > > ('> > >r   