
    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 ddl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          	 	 	 	 	 dVd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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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dfd/            Ze                    d0g d1          	 	 	 	 	 	 dYdee ej        d           f         d%eedz   ej        d2          f         d)eedz   ej        d3          f         d4eedz   ej        d5          f         d+eedz   ej        d6          f         d7eedz   ej        d8          f         deddfd9            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                    d@g dA          	 	 	 d[dee ej        d           f         dBee ej        dC          f         dDee ej        dE          f         dFeedz   ej        dG          f         d-ee ej        dH          f         deddfdI            Z"e                    dJdKdLg          	 	 	 d\dee ej        d           f         dMee ej        dN          f         dFeedz   ej        dO          f         d4eedz   ej        dP          f         deddfdQ            Z#e                    dR          	 	 dZdee ej        d           f         dMee ej        dS          f         d=ee ej        dT          f         deddf
dU            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get_args)CollectionItemType_TCollectionSort_T   )LimitOptTokenOptapi_object_to_dict
get_hf_apityper_factory)outCollectionItemTypec                     i | ]}||S  r   ).0ts     b/var/www/html/Carbon-Document/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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>W   s0        	:&&  r   )r   r   r   r    )r   valuelist_collectionsr   table)r   r   r   r    r!   apisort_keyresultss           r   collections_lsr.   :   s{    6 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)r0   r!   r+   r&   s       r   collections_infor4   c   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$   )r6   r7   r8   r9   r:   zCollection createdslugurlN)r   create_collectionr   resultr=   r>   )r6   r7   r8   r9   r:   r!   r+   r&   s           r   collections_createrA   s   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$   )r0   r6   r8   rC   r9   rD   zCollection updatedr<   N)r   update_collection_metadatar   r@   r=   r>   )	r0   r6   r8   rC   r9   rD   r!   r+   r&   s	            r   collections_updaterG      se    B 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$   )rI   zCollection deletedr=   N)r   delete_collectionr   r@   )r0   rI   r!   r+   s       r   collections_deleterM      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$   )r0   rN   rO   rP   r:   zItem added to collectionr<   N)r   add_collection_itemr(   r   r@   r>   )r0   rN   rO   rP   r:   r!   r+   r&   s           r   collections_add_itemrS      sa    8 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$   )r0   rT   rP   rC   zItem updated in collectionrK   N)r   update_collection_itemr   r@   )r0   rT   rP   rC   r!   r+   s         r   collections_update_itemrW     s[    0 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$   )r0   rT   rI   zItem deleted from collectionrK   N)r   delete_collection_itemr   r@   )r0   rT   rI   r!   r+   s        r   collections_delete_itemrZ   &  sX      5
!
!
!C'%    
 J-ODDDDDDr   )NNNr   N)N)NNFFN)NNNNNN)FN)NFN)NNN)%__doc__enumtypingr   r   typerhuggingface_hub.hf_apir   r   
_cli_utilsr   r	   r
   r   r   _outputr   _COLLECTION_ITEM_TYPESEnumstrr   _COLLECTION_SORT_OPTIONSr   collections_clicommandOptionr.   Argumentr4   boolrA   intrG   rM   rS   rW   rZ   r   r   r   <module>rl      s	   ,  & & & & & & & &  I I I I I I I I Y Y Y Y Y Y Y Y Y Y Y Y Y Y       ""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       	 	 	! d
EFFF	H
 d
~	
 	
 	
	 PQQQ	S   !" 
#   B 
9     sNEN8q$r$r$rrs 
          	 	 	 	%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 "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 "O "O "OJ 6C    	; ;sNEN8q$r$r$rrs;RSSS	U; ; 
; ; ; ;      ( 	 	#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> `W     	 	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6 '' 	E EsNEN8q$r$r$rrsE B	
 	
 	
	E LMMM	OE E 
E E E ('E E Er   