
    i,                     
   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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j5                  dg d      ddddej6                  dfdeedz   ej8                  d      f   deedz   ej8                  d      f   deedz   ej8                  d      f   dede
deddfd       Zej5                  ddg      ej6                  dfdee ej<                  d      f   de
deddfd        Zej5                  d!g d"      ddd#d#ej6                  dfd$ee ej<                  d%      f   d&eedz   ej8                  d'      f   d(eedz   ej8                  d)      f   d*ee  ej8                  d+      f   d,ee  ej8                  d-      f   de
deddfd.       Z!ej5                  d/g d0      dddddej6                  dfdee ej<                  d      f   d$eedz   ej8                  d1      f   d(eedz   ej8                  d2      f   d3ee"dz   ej8                  d4      f   d*ee dz   ej8                  d5      f   d6eedz   ej8                  d7      f   de
deddfd8       Z#ej5                  d9d:d;g      d#ej6                  dfdee ej<                  d      f   d<ee  ej8                  d=      f   de
deddf
d>       Z$ej5                  d?g d@      dd#ej6                  dfdee ej<                  d      f   dAee ej<                  dB      f   dCee ej<                  dD      f   dEeedz   ej8                  dF      f   d,ee  ej8                  dG      f   de
deddfdH       Z%ej5                  dIdJdKg      ddej6                  dfdee ej<                  d      f   dLee ej<                  dM      f   dEeedz   ej8                  dN      f   d3ee"dz   ej8                  dO      f   de
deddfdP       Z&ej5                  dQ      d#ej6                  dfdee ej<                  d      f   dLee ej<                  dR      f   d<ee  ej8                  dS      f   de
deddfdT       Z'yc c} w c c}w )Ua_  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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format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   r   apisort_key
collectionresultss
             p/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/huggingface_hub/cli/collections.pycollections_lsr'   :   sn    8 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"   r$   s        r&   collections_infor-   d   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-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        |      }|j                  | ||||      }t        j                  d|j                  |j
                         y)z#Create a new collection on the Hub.r   )r0   r1   r2   r3   r4   zCollection createdslugurlN)r   create_collectionr   resultr7   r8   )	r0   r1   r2   r3   r4   r   r   r"   r$   s	            r&   collections_creater;   u   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)   r0   r2   r=   r3   r>   zCollection updatedr6   N)r   update_collection_metadatar   r:   r7   r8   )
r)   r0   r2   r=   r3   r>   r   r   r"   r$   s
             r&   collections_updaterA      sQ    D 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   )rC   zCollection deletedr7   N)r   delete_collectionr   r:   )r)   rC   r   r   r"   s        r&   collections_deleterG      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)   rH   rI   rJ   r4   zItem added to collectionr6   N)r   add_collection_itemr   r   r:   r8   )	r)   rH   rI   rJ   r4   r   r   r"   r$   s	            r&   collections_add_itemrM      sM    : 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)   rN   rJ   r=   zItem updated in collectionrE   N)r   update_collection_itemr   r:   )r)   rN   rJ   r=   r   r   r"   s          r&   collections_update_itemrQ   
  s>    2 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)   rN   rC   zItem deleted from collectionrE   N)r   delete_collection_itemr   r:   )r)   rN   rC   r   r   r"   s         r&   collections_delete_itemrT   -  s;    " 5
!C'%  
 JJ-O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Optionr'   Argumentr-   boolr;   intrA   rG   rM   rQ   rT   )tss   00r&   <module>ri      sB  ,  &  I l l . ""67 TYY3DZ5[qad5[bef #$45 +<T-Uqad-U\_`  %LM    	 	 	 4 9 9#d
EF	H
 d
~	
	 PQ	S   !" #$ 
%D 
9   !5 9 9sNENN8q$rrs  
	    	 	 	 	 4 9 9'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B    	 	 	 	 	 4 9 9/#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0 
1#O#OL 6C   	 4 9 9;sNENN8q$rrs;RS	U; ; ; 
;;   ( 	 	 4 9 9%UsNENN8q$rrsU^U^^!fggU
 ef	hU d
NO	QU [\	^U" #U$ %U& 
'UU@ `W    	 	 4 9 9CsNENN8q$rrsCrs	uC d
IJ	LC d
KL	NC C C  
!CC8 ' 	 4 9 9EsNENN8q$rrsE B	
	E LM	OE E E 
E (E{ 6\ .Vs   
S<
8
T
