
    ^j^'                        d Z ddlZddlmZm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 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      	 	 	 	 	 dSdeedz   ed      f   deedz   ed      f   deedz   ed      f   de	de
ddfd       Zej5                  ddg      	 dTdee ed      f   de
ddfd       Zej5                  d g d!      	 	 	 	 	 dUd"ee ed#      f   d$eedz   ed%      f   d&eedz   ed'      f   d(ee ed)      f   d*ee ed+      f   de
ddfd,       Zej5                  d-g d.      	 	 	 	 	 	 dVdee ed      f   d"eedz   ed/      f   d&eedz   ed0      f   d1eedz   ed2      f   d(eedz   ed3      f   d4eedz   ed5      f   de
ddfd6       Z ej5                  d7d8d9g      	 	 dWdee ed      f   d:ee ed;      f   de
ddfd<       Z!ej5                  d=g d>      	 	 	 dXdee ed      f   d?ee ed@      f   dAee edB      f   dCeedz   edD      f   d*ee edE      f   de
ddfdF       Z"ej5                  dGdHdIg      	 	 	 dYdee ed      f   dJee edK      f   dCeedz   edL      f   d1eedz   edM      f   de
ddfdN       Z#ej5                  dO      	 	 dWdee ed      f   dJee edP      f   d:ee edQ      f   de
ddf
dR       Z$yc c} w c c}w )ZzGContains commands to interact with collections on the Hugging Face Hub.    N)	Annotatedget_args)CollectionItemType_TCollectionSort_T   )LimitOptTokenOpt
get_hf_apityper_factory)ArgumentOption)_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	            j/var/www/ramen.bs-engineer-server.com/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+   N   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/   r0   r1   r2   zCollection createdslugurlN)r
   create_collectionr   resultr5   r6   )r.   r/   r0   r1   r2   r   r    r"   s           r$   collections_creater9   ^   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.   r0   r;   r1   r<   zCollection updatedr4   N)r
   update_collection_metadatar   r8   r5   r6   )	r'   r.   r0   r;   r1   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   )rA   zCollection deletedr5   N)r
   delete_collectionr   r8   )r'   rA   r   r    s       r$   collections_deleterE      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'   rF   rG   rH   r2   zItem added to collectionr4   N)r
   add_collection_itemr   r   r8   r6   )r'   rF   rG   rH   r2   r   r    r"   s           r$   collections_add_itemrK      sM    4 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'   rL   rH   r;   zItem updated in collectionrC   N)r
   update_collection_itemr   r8   )r'   rL   rH   r;   r   r    s         r$   collections_update_itemrO      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'   rL   rA   zItem deleted from collectionrC   N)r
   delete_collection_itemr   r8   )r'   rL   rA   r   r    s        r$   collections_delete_itemrR     s;      5
!C'%  
 JJ-ODr,   )NNN
   N)N)NNFFN)NNNNNN)FN)NFN)NNN)%__doc__enumtypingr   r   huggingface_hub.hf_apir   r   
_cli_utilsr   r	   r
   r   
_frameworkr   r   _outputr   r   _COLLECTION_ITEM_TYPESEnumstrr   _COLLECTION_SORT_OPTIONSr   collections_clicommandr%   r+   boolr9   intr?   rE   rK   rO   rR   )tss   00r$   <module>re      s   N  & I E E ( , ""67 TYY3DZ5[qad5[bef #$45 +<T-Uqad-U\_`  %LM    	 	 	!d
?@	B
 d
~	
	 JK	M   !" 
#B 
9   sH2k$llm 
    	 	 	 	%OS((FGGHOd
cd	fO d
78	:O 23	5O MN	PO$ %O& 
'OO@    	 	 	 	 	-"OsH2k$llm"Od
78	:"O d
=>	@"O d
MN	P"O t?@	B"O$ d
QR	T%"O, -"O. 
/"O"OJ 6C   	;sH2k$llm;LM	O; ; 
;;   $ 	 	UsH2k$llmUsH*oppqU _`	bU d
HI	KU UV	XU U  
!UU: `W    	 	CsH2k$llmClm	oC d
CD	FC d
EF	HC C 
CC6 ' 	EsH2k$llmE B	
	E FG	IE E 
E (Ei 6\ .Vs   
M2
8
M7
