wL iz),dZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z m Z dd lmZmZmZdd lmZdd lmZej,eZGd d eZGddZGddZGddeZGddeZGddeZy)a Contains commands to interact with repositories on the Hugging Face Hub. Usage: # create a new dataset repo on the Hub hf repo create my-cool-dataset --repo-type=dataset # create a private model repo on the Hub hf repo create my-cool-model --private N)_SubParsersAction)Optional) HTTPError)BaseHuggingfaceCLICommand)ANSI) REPO_TYPESSPACES_SDK_TYPES)HfHubHTTPErrorRepositoryNotFoundErrorRevisionNotFoundError)HfApi)loggingc"eZdZedefdZy) RepoCommandsparserc|jddjd}jfd|jdd}|jd td |jd td |jdtdt |jddd|jdtd |jddd|jdtd |jd|jdd}|jddd !}|jdd"}|jd td# |jdtd$ |jd%d&td' |jd(td) |jdtd* |jd gd+d,d-.|jd/|jd0d1}|jd td2 |jdtd* |jd gd+d,d-.|jd3|jd4d5}|jd td6 |jdtd7 |jd8d9dd:|jdtd* |jd gd+d,d-.|jd;y)z2RepoCommands.register_subcommand..0s;3I3I3K)funccreatez#Create a new repo on huggingface.corepo_idzThe ID of the repo to create to (e.g. `username/repo-name`). The username is optional and will be set to your username if not provided.)typerz --repo-typezWOptional: set to "dataset" or "space" if creating a dataset or space, default is model.z --space_sdkzOOptional: Hugging Face Spaces SDK type. Required when --type is set to "space".)r rchoicesz --private store_truezhWhether to create a private repository. Defaults to public unless the organization's default is private.)actionrz--tokenzLHugging Face token. Will default to the locally saved token if not provided.z --exist-okz-Do not raise an error if repo already exists.z--resource-group-idzoResource group in which to create the repo. Resource groups is only available for Enterprise Hub organizations.ct|Sr)RepoCreateCommandrs rrz2RepoCommands.register_subcommand..Xs :KD:Qrtagz"Manage tags for a repo on the Hub.z Tag actions tag_actionT)rdestrequiredzCreate a tag for a repo.z6The ID of the repo to tag (e.g. `username/repo-name`).zThe name of the tag to create.z-mz --messagez%The description of the tag to create.z --revisionzThe git revision to tag.zJA User Access Token generated from https://huggingface.co/settings/tokens.)modeldatasetspacer+z6Set the type of repository (model, dataset, or space).)r!defaultrct|Sr)RepoTagCreateCommandr&s rrz2RepoCommands.register_subcommand..o 9Md9SrlistzList tags for a repo.z@The ID of the repo to list tags for (e.g. `username/repo-name`).ct|Sr)RepoTagListCommandr&s rrz2RepoCommands.register_subcommand..s 7I$7OrdeletezDelete a tag from a repo.zFThe ID of the repo to delete the tag from (e.g. `username/repo-name`).zThe name of the tag to delete.z-yz--yesz$Answer Yes to prompts automatically.ct|Sr)RepoTagDeleteCommandr&s rrz2RepoCommands.register_subcommand..r1r) add_parseradd_subparsers set_defaults add_argumentstrr ) rrepo_subparsersrepo_create_parserrepo_tag_parsertag_subparserstag_create_parsertag_list_parsertag_delete_parserrs @rregister_subcommandz RepoCommands.register_subcommand*s{''5O'P %44:a4b   &K L-77Gl7m'' [ ( '' j ( '' b$ ( '' { ( '' _ ( '' @ ( '' !C ( ''-Q'R*44UAe4f(77]Q]hl7m+55hE_5`&& C&^ '  &&u3=]&^&&t[sIp&q&&|#D^&_&& C&r '  && 1I ' &&,S&T)33FAX3Y$$ C&h %  $$ C&r %  $$ 1I % $$*O$P+55hE`5a&& C&n '  &&u3=]&^&&tW\Pv&w&& C&r '  && 1I ' &&,S&TrN)__name__ __module__ __qualname__ staticmethodrrDrrrr)s"fU$5fUfUrrc2eZdZdejfdZdZy)r%rc|j|_|j|_|j|_|j|_|j|_|j |_|j |_t|_yr) r repo_type space_sdkprivatetokenexist_okresource_group_idr _apiselfrs r__init__zRepoCreateCommand.__init__s[ LL (,(,!\\ $(JJ "mm 040F0FG rc n|jj|j|j|j|j |j |j|j}tdtj|jdtdtj|y)N)rrLrNrOrPrQrMzSuccessfully created z on the Hub.zYour repo is now available at ) rR create_reporrLrNrOrPrQrMprintrbold)rTrepo_urls rrunzRepoCreateCommand.runs99((LLnnLL**]]"44nn)  %dii0@0@&A%B,OP .tyy/B.CDErN)rErFrGargparse NamespacerUr[rIrrr%r%sX// Frr%ceZdZdZy)RepoTagCommandc||_tt|dd|_|j|_t|dd|_|j t vrtdtdyy)NrO)rOrLr+zInvalid repo --repo-type) rr getattrapirrLrrXexitrSs rrUzRepoTagCommand.__init__sZ wtWd;<||  {G< >> + , - G ,rN)rErFrGrUrIrrr_r_srr_ceZdZdZy)r0c tdtjt|jj d|j dtj|j |jj|j|jj t|jddt|jdd|j td tjt|jj d tj|jy#t$rTt|j jdtj|jdtdYt$rOtd tjtt|jdddtdYt$r}|j j"d k(ritd tjt|jj d tj|jtd|d}~wwxYw)NzYou are about to create tag  on  messagerevision)rr' tag_messagerjrL not found.raz Revision iTag z already exists on z created on )rXrrYr<rr'rLrrc create_tagrbr capitalizerdr r response status_code)rTes rr[zRepoTagCreateCommand.runs *499S5G+H*IdnnM]]^_c_h_himiuiu_v^w x   HH   IIMM#DIIy$? J=..  $ TYYs499==123< $,,@W?XYZ'  T^^..01499T\\3J2K;W X G$  IdiiGDIIz4,P(QRSS^_ ` G zz%%,TYYs499=='9:;;NtyyY]YeYeOfNghiQG  s(-A2D>>AJAJ0J8BI<<JNrErFrGr[rIrrr0r0s[rr0ceZdZdZy)r4c |jj|j|j}tjdk(rt dtdt d|jdtj|jd|jD]}t |j y#t$rTt |jj dtj|jdtdYt$rS}t |t tj|jjtdYd}~@d}~wwxYw) N)rrLrhrlrarz No tags foundz Tags for :)rclist_repo_refsrrLr rXrorrYrdrredrptextlentagsname)rTrefsrrr's rr[zRepoTagListCommand.runs 88** ..+D tyy>Q  / " G $..)499T\\+B*C1EF99 C #((O '  T^^..01499T\\3J2K;W X G  !H $((1::??+ , GG s1CAE8E8%AE33E8NrsrIrrr4r4srr4ceZdZdZy)r7c (tdtj|jjd|j dtj|j t|jdds2tdj}|dvrtdt |jj|j |jj|j td tj|jjdtj|j y#t$rTt|j jdtj|j d td Yt$rdtd tj|jjd tj|j td YwxYw)NzYou are about to delete tag rgrhyesFzProceed? [Y/n] )yrAbort)rr'rLrlrarmz not found on z deleted on )rXrrYrr'rLrrbinputlowerrdrc delete_tagr ror )rTchoices rr[zRepoTagDeleteCommand.runsx ,TYYtyy}}-E,Fd4>>JZZ[\`\e\efjfrfr\s[tuvtyy%/,-335F--g  HH   $))--SWSaSa  b TYYtyy}}-.l499T\\;R:STU '  T^^..01499T\\3J2K;W X G$  D499==12.4<rs&)>4Baa()   H %hU,hUVFF2[>[6,V>Vr