
    qiw+                     d	   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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j9                  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j9                  ddg      	 dUdee ej@                  d       f   deddfd!       Z!ej9                  d"g d#      	 	 	 	 	 dVd$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d.       Z#ej9                  d/g d0      	 	 	 	 	 	 dWdee ej@                  d       f   d$eee    ej<                  d1      f   d(eee    ej<                  d2      f   d3eee$    ej<                  d4      f   d*eee"    ej<                  d5      f   d6eee    ej<                  d7      f   deddfd8       Z%ej9                  d9d:d;g      	 	 dXdee ej@                  d       f   d<ee" ej<                  d=      f   deddfd>       Z&ej9                  d?g d@      	 	 	 dYdee ej@                  d       f   dAee ej@                  dB      f   dCee ej@                  dD      f   dEeee    ej<                  dF      f   d,ee" ej<                  dG      f   deddfdH       Z'ej9                  dIdJdKg      	 	 	 dZdee ej@                  d       f   dLee ej@                  dM      f   dEeee    ej<                  dN      f   d3eee$    ej<                  dO      f   deddfdP       Z(ej9                  dQ      	 	 dXdee ej@                  d       f   dLee ej@                  dR      f   d<ee" ej<                  dS      f   deddf
dT       Z)yc c} w c c}w )[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CollectionItemType)typeCollectionSortz%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}|j                  | |||      D 	cg c]  }	t        |	       }
}	t	        |
||       yc c}	w )zList collections on the Hub.r   N)r   r   r   r   )r   r   )r   valuelist_collectionsr   r   )r   r   r   r   r   r   r   apisort_key
collectionresultss              Q/opt/pipecat/venv/lib/python3.12/site-packages/huggingface_hub/cli/collections.pycollections_lsr*   D   sn    : 5
!C!tzztH ..	 / 
 	:&G  gfE:s   Ainfoz/hf collections info username/my-collection-slugcollection_slugz7The collection slug (e.g., 'username/collection-slug').c                     t        |      }|j                  |       }t        t        j                  t        |      d             y)z'Get info about a collection on the Hub.r"      indentN)r   get_collectionprintjsondumpsr   )r,   r   r%   r'   s       r)   collections_infor5   o   s7     5
!C##O4J	$**'
3A
>?    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        d|j                          t        t	        j
                  t        |      d             y)z#Create a new collection on the Hub.r"   )r8   r9   r:   r;   r<   zCollection created: r.   r/   N)r   create_collectionr2   urlr3   r4   r   )r8   r9   r:   r;   r<   r   r%   r'   s           r)   collections_creater@      sb    : 5
!C&& ' J 
  0
12	$**'
3A
>?r6   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        d|j                          t        t	        j
                  t        |      d             y)z*Update a collection's metadata on the Hub.r"   )r,   r8   r:   rB   r;   rC   zCollection updated: r.   r/   N)r   update_collection_metadatar2   r?   r3   r4   r   )	r,   r8   r:   rB   r;   rC   r   r%   r'   s	            r)   collections_updaterF      sf    B 5
!C//' 0 J 
  0
12	$**'
3A
>?r6   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        |      }|j                  | |       t        d|         y)z!Delete a collection from the Hub.r"   )rH   zCollection deleted: N)r   delete_collectionr2   )r,   rH   r   r%   s       r)   collections_deleterK      s2      5
!C/jA	  1
23r6   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                  | ||j                  ||      }t        d|         t        t	        j
                  t        |      d             y)zAdd an item to a collection.r"   )r,   rL   rM   rN   r<   zItem added to collection: r.   r/   N)r   add_collection_itemr#   r2   r3   r4   r   )r,   rL   rM   rN   r<   r   r%   r'   s           r)   collections_add_itemrQ      sb    8 5
!C(('// ) J 
&&7
89	$**'
3A
>?r6   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                 b    t        |      }|j                  | |||       t        d|         y)zUpdate an item in a collection.r"   )r,   rR   rN   rB   zItem updated in collection: N)r   update_collection_itemr2   )r,   rR   rN   rB   r   r%   s         r)   collections_update_itemrU     s@    0 5
!C'%	   
((9
:;r6   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        |      }|j                  | ||       t        d|         y)z!Delete an item from a collection.r"   )r,   rR   rH   zItem deleted from collection: N)r   delete_collection_itemr2   )r,   rR   rH   r   r%   s        r)   collections_delete_itemrX   5  s=      5
!C'%  
 
*?*;
<=r6   )N)NNFFN)NNNNNN)FN)NFN)NNN)*__doc__enumr3   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Optionr*   Argumentr5   boolr@   intrF   rK   rQ   rU   rX   )tss   00r)   <module>rl      s  ,   0 0  I
 
 
 ""67 TYY3DZ5[qad5[bef #$45 +<T-Uqad-U\_`  %LM    	 	 	$**% ;EF	H ;
 ~	
	 ;  PQ	S ;  ;  ! ;" # ;$ % ;& 
' ; ;F 
9   @sNENN8q$rrs@@ 
@@    	 	 	 	%@S.%...LMMN@ij	l@ =>	@@ 89	;@ ST	V@$ %@& 
'@@B    	 	 	 	 	-#@sNENN8q$rrs#@=>	@#@ CD	F#@ ST	V#@ EF	H#@$ WX	Z%#@, -#@. 
/#@#@L 6C   	4sNENN8q$rrs4RS	U4 4 
44   ( 	 	#@sNENN8q$rrs@^U^^!fgg@
 ]^	`@ NO	Q@ [\	^@" #@$ 
%@@@ `W    	 	<sNENN8q$rrs<rs	u< IJ	L< KL	N< < 
<<6 ' 	>sNENN8q$rrs> B	
	> LM	O> > 
> (>w 6\ .Vs   
R(
<
R-
