
    -:j*                     4	   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 ddlmZmZ  ee      Z ej$                  deD  ci c]  } | |  c} e	      Z ee      Z ej$                  d
eD ci c]  }|| c}e	      Z ed      Zej1                  dg d      	 	 	 	 	 dRdeedz   ej2                  d      f   deedz   ej2                  d      f   deedz   ej2                  d      f   de
deddfd       Zej1                  ddg      	 dSdee ej6                  d      f   deddfd       Zej1                  dg d       	 	 	 	 	 dTd!ee ej6                  d"      f   d#eedz   ej2                  d$      f   d%eedz   ej2                  d&      f   d'ee ej2                  d(      f   d)ee ej2                  d*      f   deddfd+       Zej1                  d,g d-      	 	 	 	 	 	 dUdee ej6                  d      f   d!eedz   ej2                  d.      f   d%eedz   ej2                  d/      f   d0eedz   ej2                  d1      f   d'eedz   ej2                  d2      f   d3eedz   ej2                  d4      f   deddfd5       Z ej1                  d6d7d8g      	 	 dVdee ej6                  d      f   d9ee ej2                  d:      f   deddfd;       Z!ej1                  d<g d=      	 	 	 dWdee ej6                  d      f   d>ee ej6                  d?      f   d@ee ej6                  dA      f   dBeedz   ej2                  dC      f   d)ee ej2                  dD      f   deddfdE       Z"ej1                  dFdGdHg      	 	 	 dXdee ej6                  d      f   dIee ej6                  dJ      f   dBeedz   ej2                  dK      f   d0eedz   ej2                  dL      f   deddfdM       Z#ej1                  dN      	 	 dVdee ej6                  d      f   dIee ej6                  dO      f   d9ee ej2                  dP      f   deddf
dQ       Z$yc c} w c c}w )Ya_  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
get_hf_apityper_factory)_dataclass_to_dictoutCollectionItemType)typeCollectionSortz%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}|j                  | |||      D cg c]  }t        |       }}t	        j
                  |       yc c}w )zList collections on the Hub.r   N)r   r   r   r   )r
   valuelist_collectionsr   r   table)	r   r   r   r   r   apisort_key
collectionresultss	            a/var/www/html/tokenscope/api/venv/lib/python3.12/site-packages/huggingface_hub/cli/collections.pycollections_lsr#   :   sn    6 5
!C!tzztH ..	 / 
 	:&G  IIgs   Ainfoz/hf collections info username/my-collection-slugcollection_slugz7The collection slug (e.g., 'username/collection-slug').c                 h    t        |      }|j                  |       }t        j                  |       y)z'Get info about a collection on the Hub.r   N)r
   get_collectionr   dict)r%   r   r   r    s       r"   collections_infor)   c   s*     5
!C##O4JHHZ    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        |      }|j                  | ||||      }t        j                  d|j                  |j
                         y)z#Create a new collection on the Hub.r   )r,   r-   r.   r/   r0   zCollection createdslugurlN)r
   create_collectionr   resultr3   r4   )r,   r-   r.   r/   r0   r   r   r    s           r"   collections_creater7   s   sM    : 5
!C&& ' J JJ#*//z~~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        |      }|j                  | |||||      }t        j                  d|j                  |j
                         y)z*Update a collection's metadata on the Hub.r   )r%   r,   r.   r9   r/   r:   zCollection updatedr2   N)r
   update_collection_metadatar   r6   r3   r4   )	r%   r,   r.   r9   r/   r:   r   r   r    s	            r"   collections_updater=      sQ    B 5
!C//' 0 J JJ#*//z~~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                 p    t        |      }|j                  | |       t        j                  d|        y)z!Delete a collection from the Hub.r   )r?   zCollection deletedr3   N)r
   delete_collectionr   r6   )r%   r?   r   r   s       r"   collections_deleterC      s0      5
!C/jAJJ#/: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                  | ||j                  ||      }t        j                  d| |j
                         y)zAdd an item to a collection.r   )r%   rD   rE   rF   r0   zItem added to collectionr2   N)r
   add_collection_itemr   r   r6   r4   )r%   rD   rE   rF   r0   r   r   r    s           r"   collections_add_itemrI      sM    8 5
!C(('// ) J JJ)Z^^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                  | |||       t        j                  d|        y)zUpdate an item in a collection.r   )r%   rJ   rF   r9   zItem updated in collectionrA   N)r
   update_collection_itemr   r6   )r%   rJ   rF   r9   r   r   s         r"   collections_update_itemrM     s>    0 5
!C'%	   JJ+/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                 r    t        |      }|j                  | ||       t        j                  d|        y)z!Delete an item from a collection.r   )r%   rJ   r?   zItem deleted from collectionrA   N)r
   delete_collection_itemr   r6   )r%   rJ   r?   r   r   s        r"   collections_delete_itemrP   &  s;      5
!C'%  
 JJ-ODr*   )NNN
   N)N)NNFFN)NNNNNN)FN)NFN)NNN)%__doc__enumtypingr   r   typerhuggingface_hub.hf_apir   r   
_cli_utilsr   r	   r
   r   _outputr   r   _COLLECTION_ITEM_TYPESEnumstrr   _COLLECTION_SORT_OPTIONSr   collections_clicommandOptionr#   Argumentr)   boolr7   intr=   rC   rI   rM   rP   )tss   00r"   <module>re      s  ,  &  I E E , ""67 TYY3DZ5[qad5[bef #$45 +<T-Uqad-U\_`  %LM    	 	 	!d
EF	H
 d
~	
	 PQ	S   !" 
#B 
9   sNENN8q$rrs 
    	 	 	 	%OS.%...LMMNOd
ij	lO d
=>	@O 89	;O ST	VO$ %O& 
'OO@    	 	 	 	 	-"OsNENN8q$rrs"Od
=>	@"O d
CD	F"O d
ST	V"O tEF	H"O$ d
WX	Z%"O, -"O. 
/"O"OJ 6C   	;sNENN8q$rrs;RS	U; ; 
;;   ( 	 	#UsNENN8q$rrsU^U^^!fggU
 ef	hU d
NO	QU [\	^U" #U$ 
%UU> `W    	 	CsNENN8q$rrsCrs	uC d
IJ	LC d
KL	NC C 
CC6 ' 	EsNENN8q$rrsE B	
	E LM	OE E 
E (Em 6\ .Vs   
R
4
R
