o
    0j*                     @   s  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	d
 eD edZeeZejddd
 eD edZeddZejdg dd					d_deedB ejddf deedB ejddf deedB ejddf de
deddfddZejdd gd	d`d!eeejd"df deddfd#d$Zejd%g d&d			'	'	dad(eeejd)df d*eedB ejd+df d,eedB ejd-df d.eeejd/df d0eeejd1df deddfd2d3Zejd4g d5d						dbd!eeejd"df d(eedB ejd6df d,eedB ejd7df d8eedB ejd9df d.eedB ejd:df d;eedB ejd<df deddfd=d>Z ejd?d@dAgd	'	dcd!eeejd"df dBeeejdCdf deddfdDdEZ!ejdFg dGd		'	ddd!eeejd"df dHeeejdIdf dJeeejdKdf dLeedB ejdMdf d0eeejdNdf deddfdOdPZ"ejdQdRdSgd			ded!eeejd"df dTeeejdUdf dLeedB ejdVdf d8eedB ejdWdf deddfdXdYZ#edZ	'	dcd!eeejd"df dTeeejd[df dBeeejd\df deddf
d]d^Z$dS )fa_  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                 C      i | ]}||qS  r   ).0tr   r   `/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/cli/collections.py
<dictcomp>1       r   )typeCollectionSortc                 C   r   r   r   )r   sr   r   r   r   4   r   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)Z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                 C   sB   t |d}|r
|jnd}dd |j| |||dD }t| dS )zList collections on the Hub.r   Nc                 S   s   g | ]}t |qS r   )r	   )r   
collectionr   r   r   
<listcomp>W   s    z"collections_ls.<locals>.<listcomp>)r   r   r   r   )r
   valueZlist_collectionsr   table)r   r   r   r   r   apisort_keyresultsr   r   r   collections_ls:   s   
	r(   infoz/hf collections info username/my-collection-slugcollection_slugz7The collection slug (e.g., 'username/collection-slug').c                 C   s"   t |d}|| }t| dS )z'Get info about a collection on the Hub.r    N)r
   Zget_collectionr   dict)r*   r   r%   r!   r   r   r   collections_infoc   s   

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                 C   s6   t |d}|j| ||||d}tjd|j|jd dS )z#Create a new collection on the Hub.r    )r.   r/   r0   r1   r2   zCollection createdslugurlN)r
   Zcreate_collectionr   resultr4   r5   )r.   r/   r0   r1   r2   r   r%   r!   r   r   r   collections_creates   s   
r7   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           	      C   s8   t |d}|j| |||||d}tjd|j|jd dS )z*Update a collection's metadata on the Hub.r    )r*   r.   r0   r9   r1   r:   zCollection updatedr3   N)r
   Zupdate_collection_metadatar   r6   r4   r5   )	r*   r.   r0   r9   r1   r:   r   r%   r!   r   r   r   collections_update   s   
!r;   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                 C   s*   t |d}|j| |d tjd| d dS )z!Delete a collection from the Hub.r    )r=   zCollection deletedr4   N)r
   Zdelete_collectionr   r6   )r*   r=   r   r%   r   r   r   collections_delete   s   
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                 C   s6   t |d}|j| ||j||d}tjd| |jd dS )zAdd an item to a collection.r    )r*   r@   rA   rB   r2   zItem added to collectionr3   N)r
   Zadd_collection_itemr#   r   r6   r5   )r*   r@   rA   rB   r2   r   r%   r!   r   r   r   collections_add_item   s   
rC   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                 C   s.   t |d}|j| |||d tjd| d dS )zUpdate an item in a collection.r    )r*   rD   rB   r9   zItem updated in collectionr>   N)r
   Zupdate_collection_itemr   r6   )r*   rD   rB   r9   r   r%   r   r   r   collections_update_item  s   
rE   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                 C   s,   t |d}|j| ||d tjd| d dS )z!Delete an item from a collection.r    )r*   rD   r=   zItem deleted from collectionr>   N)r
   Zdelete_collection_itemr   r6   )r*   rD   r=   r   r%   r   r   r   collections_delete_item&  s   
rF   )NNNr   N)N)NNFFN)NNNNNN)FN)NFN)NNN)%__doc__enumtypingr   r   ZtyperZhuggingface_hub.hf_apir   r   Z
_cli_utilsr   r   r	   r
   r   _outputr   Z_COLLECTION_ITEM_TYPESEnumstrr   Z_COLLECTION_SORT_OPTIONSr   Zcollections_clicommandOptionr(   ZArgumentr,   boolr7   intr;   r?   rC   rE   rF   r   r   r   r   <module>   s  


!





 





%

	






