
    qi?                        d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZmZmZmZ ddlZddlmZ ddlmZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZm Z  dd
l!m"Z" ddl#m$Z$m%Z%m&Z& ddl'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: dZ; e< ee$            Z= ee&      Z> ej~                  de>D  ci c]  } | |  c} e@      ZAeee@    ej                  ddj                  e=       d e8e=            f   ZD e:d      ZEeEj                  dddg      dddddde1j                  ddf	de4de-d e.d!eeeA    ej                  d"      f   d#e0d$eDd%e/d&e2d'e5d(dfd)       ZHeEj                  d*d+d,g      	 	 	 dKd-ee@ ej                  d.      f   d/e3d$eDd'e5d(df
d0       ZJeEj                  d1d2g      	 	 dLd-ee@ ej                  d.      f   d3eeK ej                  d4      f   d'e5fd5       ZLeEj                  d6g d7      	 	 	 	 	 dMd-ee@ ej                  d.      f   d8eee@    ej                  d9      f   d:eee@    ej                  d;d<d=      f   d>eeK ej                  d?      f   d@eeK ej                  dA      f   d'e5d(dfdB       ZMdCe%d-e@dDe@dEee@   d'ee@   d(dfdFZNdGZOej                  d(ee@   fdH       ZQdEe@d(eeRedI   f   fdJZSyc c} w )Na  Contains commands to interact with spaces on the Hugging Face Hub.

Usage:
    # list spaces on the Hub
    hf spaces ls

    # list spaces with a search query
    hf spaces ls --search "chatbot"

    # get info about a space
    hf spaces info enzostvs/deepsite
    N)	AnnotatedLiteralOptionalUnionget_args)version)assert_never)multi_replica_reload_events)ApiGetReloadEventSourceDataReloadRegion)
SpaceStage)CLIErrorRepositoryNotFoundErrorRevisionNotFoundError)hf_hub_download)ExpandSpaceProperty_THfApiSpaceSort_T)
StatusLineare_progress_bars_disableddisable_progress_barsenable_progress_bars   )	AuthorOpt	FilterOpt	FormatOptLimitOptOutputFormatQuietOptRevisionOpt	SearchOptTokenOptapi_object_to_dict
get_hf_apimake_expand_properties_parserprint_list_outputtyper_factoryz6.1.0SpaceSortEnum)typezMComma-separated properties to expand. Example: '--expand=likes,tags'. Valid: , .)helpcallbackz Interact with spaces on the Hub.)r,   lszhf spaces ls --limit 10z4hf spaces ls --search "chatbot" --author huggingface)examples
   FsearchauthorfiltersortzSort results.limitexpandformatquiettokenreturnc	                     t        |      }	|r|j                  nd}
|	j                  ||| |
||      D cg c]  }t        |       }}t	        |||       yc c}w )zList spaces on the Hub.r9   N)r3   r2   r1   r4   r5   r6   )r7   r8   )r$   valuelist_spacesr#   r&   )r1   r2   r3   r4   r5   r6   r7   r8   r9   apisort_key
space_inforesultss                L/opt/pipecat/venv/lib/python3.12/site-packages/huggingface_hub/cli/spaces.py	spaces_lsrD   X   sr    , 5
!C!tzztH // * 

 	:&
G 
 gfE:
s   Ainfoz hf spaces info enzostvs/deepsitez>hf spaces info gradio/theme_builder --expand sdk,runtime,likesspace_idz)The space ID (e.g. `username/repo-name`).revisionc                    t        |      }	 |j                  | ||      }t        t        j                  t        |      d	
             y# t        $ r}t        d|  d      |d}~wt        $ r}t        d| d|  d      |d}~ww xY w)z"Get info about a space on the Hub.r<   )repo_idrG   r6   zSpace 'z' not found.Nz
Revision 'z' not found on 'z'.   )indent)	r$   rA   r   r   r   printjsondumpsr#   )rF   rG   r6   r9   r?   rE   es          rC   spaces_inforP   ~   s     5
!CS~~h&~Q
 
$**'-a
89	 # @
,78a?  SH:-=hZrJKQRRSs#   A 	B	A%%B	1BB	zdev-modez(hf spaces dev-mode my-user-name/deepsitestopzStop dev mode.c                 (   t        |      }|r!|j                  |        t        d|  d       y|j                  |        |j	                  |       }t        |j                  d|j                  dk(  rdnd      }|rd	| nd}t        d
|j                          t        j                  dt        j                  dt        j                  dt        j                  di}t               }	 |j	                  |       }|j                  t        d       y|j                  j                   |vrn>|j#                  ||j                  j                             t%        j&                  d       |j                  j                   t        j(                  k7  r*|j+                  d|j                  j                    d       y|j+                  d       t        d       t        d       t        d       d|j                   d}	|r|	d| z  }	|j,                   d}
t        d|	        t        d       t        d       t        d       t        d|
 d       t        d       t        d|
 |        t        d|
 |        t        d       t        d        y)!ax  
    Enable or disable dev mode on a Space.

    Spaces Dev Mode eases the debugging of your application and makes iterating on Spaces faster by allowing you to
    restart your application without stopping the Space container itself. This feature is available as part of a PRO
    or Team & Enterprise plan.

    See docs: https://huggingface.co/docs/hub/spaces-dev-mode
    r<   zDev mode disabled for ''Nzdev-mode-folderdocker z/home/user/appzfolder=zWDev mode is currently building, track the progress here: https://huggingface.co/spaces/zbuilding...zapp starting...z Runtime of the space unavailabler   zDev mode is not ready (stage='z')zDev mode ready!zConnect to dev environment:zWeb:zhttps://huggingface.co/spaces/z/dev-mode/vscode-web?z@ssh.hf.spacez  * VSCode: zLocal:z;1. Add your SSH key to https://huggingface.co/settings/keysz2. SSH with `ssh -i <your_key> `z
   Or openz.  * VSCode: vscode://vscode-remote/ssh-remote+z.  * Cursor: cursor://vscode-remote/ssh-remote+zXPS: Dev mode stops after 48h of inactivity, don't forget to save your changes regularly.)r$   disable_space_dev_moderL   enable_space_dev_moderA   getattr	card_datasdkidr   BUILDINGRUNNING_BUILDINGAPP_STARTINGRUNNING_APP_STARTINGr   runtimestageupdatetimesleepRUNNINGdone	subdomain)rF   rQ   r9   r?   rE   folderfolder_query_param"intermediate_statuses_and_messagesstatusvscode_web_urlssh_hosts              rC   dev_moderp      sW   ( 5
!C""8,'z34h'>>(#DT^^%6dhh(>RXhiF/576(+2	cdhdkdkcl
mn]##]!2''):	*& \F
~~h'<<45<<%GG89K9KLM

1  ||Z///4T\\5G5G4HKL
KK!"	
'(	"I	&M5dggY>RSNA0122..!/H	L(
)*	"I	(O	
GH	+H:Q
78	,	:8*VH
MN	:8*VH
MN	"I	
de    z
hot-reload)zshf spaces hot-reload username/repo-name app.py               # Open an interactive editor to the remote app.py filezhf spaces hot-reload username/repo-name -f app.py            # Take local version from ./app.py and patch app.py in remote repozhf spaces hot-reload username/repo-name app.py -f src/app.py # Take local version from ./src/app.py and patch app.py in remote repofilenamez~Path to the Python file in the Space repository. Can be omitted when --local-file is specified and path in repository matches.
local_filez--local-filez-fz<Path of local file. Interactive editor mode if not specifiedskip_checksz%Skip hot-reload compatibility checks.skip_summaryz2Skip summary display after hot-reload is triggeredc                    t        j                  dt         j                  j                         t	        |      }|s|j                  |       }|j                  dk7  rt        d|j                   d      |j                  x}t        d|        |j                  x}	t        d	|  d
      t        j                  |	      t        j                  t              k  rt        dt         d|	 d      |r	|}
||n|}n|r|s	 |j                  d| d       t!        j"                         }t$        j&                  j)                  |j*                  |      }
t-               x}s
t/                	 t1        d| ||j*                         |st3                	 t5        |
      }|dk(  rt        d      |dk(  rt        d      |dk7  rt        d|
       t        d      |j7                  d| |
|d      }|s<t9        || |j:                  |r|
nt$        j&                  j=                  |
      |       yy# t        $ r}t        d|  d      |d}~ww xY w# |st3                w w xY w)u  
    Hot-reload any Python file of a Space without a full rebuild + restart.

    ⚠ This feature is experimental ⚠

    Only works with Gradio SDK (6.1+)
    Opens an interactive editor unless --local-file/-f is specified.

    This command patches the live Python process using https://github.com/breuleux/jurigged
    (AST-based diffing, in-place function updates, etc.), integrated with Gradio's native hot-reload support
    (meaning that Gradio demo object changes are reflected in the UI)
    z2This feature is experimental and subject to change)fgr<   gradioz5Hot-reloading is only available on Gradio SDK. Found z SDKNz"Unable to read cardData for Space z Unable to read sdk_version from z	 cardDataz!Hot-reloading requires Gradio >= z (found )spaceT)	repo_typerI   writezWrite access check to z8 repository failed. Make sure that you are authenticated)r{   rI   rr   	local_dirno-ttyzICannot open an editor (no TTY). Use -f flag to hot-reload from local path	no-editorzONo editor found in local environment. Use -f flag to hot-reload from local pathr   z>Editor returned a non-zero exit code while attempting to edit z4Either filename or --local-file/-f must be specified)r{   rI   path_or_fileobjpath_in_repo_hot_reload)r?   rF   
commit_sha
local_pathr9   )typersechocolorsBRIGHT_BLACKr$   rA   r\   r   r[   sdk_versionr   parseVersionHOT_RELOADING_MIN_GRADIO
auth_checkr   tempfileTemporaryDirectoryospathjoinnamer   r   r   r   _editor_openupload_file_spaces_hot_reload_summaryoidbasename)rF   rr   rs   rt   ru   r9   r?   rA   r[   r   r   rO   temp_dirpbar_disabled
editor_rescommit_infos                   rC   spaces_hot_reloadr      s{   \ 
KKDIbIbc
5
!C^^H-
>>X%RS]SaSaRbbfghh#---I6?zJKK$000K9=hZyQRR==%8P(QQ>?W>XX`al`mmnopp
!)!1:x		%$   ..0WW\\(--:
!;!===!#		'! !"--	 !$&!*-
!fgg$lmm?[\f[ghiiMNN//" " K ""%/zRWW5E5Ej5Q	
 I + ,XJ6no  !$& !s$   H2 .I 2	I;III"r?   r   r   c                    | j                  |      }|j                  x}t        d| d      |j                  x}t        d| d      |j                  dk7  r#t        j                  d|j                         y |j                  x}t        d      |j                  x}	t        d      d	t        d
t        ffddt        d
d ffd}
t        |||	|j                  D cg c]  \  }}|	 c}}|      D ]d  }|d   dk(  r |
|d          |d   dk(  rt        j                  d|d    d       <|d   dk(  rt        j                  d       Zt        |       f y c c}}w )Nz!Unable to read SpaceRuntime from z infoszSpace z2 current running version has not been hot-reloadedcreatedzDFailed creating hot-reloaded commit. hot_reloading.replica_statuses=z)Unexpected None host on hotReloaded Spacez.Unexpected None subdomain on hotReloaded Spaceregionr:   c                 ~    d}| dz  }| d   | d   k(  r|d| d   dz
   z  }|S |d| d   dz
   d| d    z  }|S )	NrU   r*   	startLineendLinezline r   zlines - )r   resr   s     rC   render_regionz1_spaces_hot_reload_summary.<locals>.render_regionf  s    !j\$$C+&"33U6+.2344C 
 VF;/!34AfY6G5HIIC
rq   eventc                    | d   d   dk(  r5t        j                  dd       t        j                  | d   d   d       y | d   d   d	k(  rDt        j                  d
 | d   d          d       t        j                  | d   d   d       y | d   d   dk(  r*t        j                  d| d   d    d| d   d    d       y | d   d   dk(  r*t        j                  d| d   d    d| d   d    d       y | d   d   dk(  r*t        j                  d| d   d    d| d   d    d       y | d   d   dk(  rDt        j                  d | d   d          d       t        j                  | d   d   d       y | d   d   dk(  r8| d   d   rt        j                  dd       y t        j                  dd       y t        | d   d          y )Ndatakinderroru"   ✘ Unexpected hot-reloading errorT)bold	traceback)italic	exceptionu   ✘ Exception at r   addu   ✔︎ Created 
objectName 
objectTypedeleteu   ∅ Deleted rd   u   ✔︎ Updated runu   ▶ Run 	codeLinesuiupdatedu   ⟳ UI updatedu   ∅ UI untouched)r   r   r	   )r   r   s    rC   display_eventz1_spaces_hot_reload_summary.<locals>.display_eventp  s   = G+KK<4HKKfk24@6]6"k1KK+M%-:Q,R+ST[_`KKfk24@6]6"e+KK/%-*E)FafVbHcGdelpq6]6"h.KK,uV}\'B&C1U6]S_E`Dabimn6]6"h.KK/%-*E)FafVbHcGdelpq6]6"e+KK(=vx1H#I"JKRVWKKfk24@6]6"d*V}Y',48.T:vv./rq   )r   hostri   replica_hashesr9   r   replicaHashz---- Replica hashz ----	fullMatchu   ✔︎ Same as first replica)rA   rb   r   hot_reloadingrm   r   echoreplica_statusesr   ri   r   strr   r
   r   r	   )r?   rF   r   r   r9   rA   rb   r   
space_hostspace_subdomainr   r   _replica_stream_eventr   s      `          @rC   r   r   Q  s    )J%%%.:8*FKLL ...7z)[\]]y(

Z=;Y;Y:[\] oo%
.BCC%///8GHHl s 08 0T 00 !<!,9,J,JKqK! /  '72.w78!&)]:KK-(<V(D'EUKL!&)[8JJ56-./ Ls   )E'))codezcode --wait)nvimr   )nanor   )vimr   )vir   c                      dD ],  } t        j                  | d      j                         x}s*|c S  t        D ]  \  }}t	        j
                  |      |c S  y )N)	HF_EDITORVISUALEDITORrU   )r   getenvstripPREFERRED_EDITORSshutilwhich)envcommandbinary_patheditor_commands       rC   _get_editor_commandr     se    0 iiR(..0070N (9 "#^<<$0!!" rq   )r~   r   c                    t         j                  j                         rt         j                  j                         syt	               x}yg t        j                  |      | }t        j                  |d      }|j                  S )Nr~   r   T)start_new_session)
sysstdinisattystdoutr   shlexsplit
subprocessr   
returncode)r   r   r   r   s       rC   r   r     sg    II3::#4#4#6-//88N+8Z8G
..D
9C>>rq   )NNN)FN)NNFFN)T__doc__enum	functoolsrM   r   r   r   r   r   r   re   typingr   r   r   r   r   r   	packagingr   typing_extensionsr	   "huggingface_hub._hot_reload.clientr
   !huggingface_hub._hot_reload.typesr   r   huggingface_hub._space_apir   huggingface_hub.errorsr   r   r   huggingface_hub.file_downloadr   huggingface_hub.hf_apir   r   r   huggingface_hub.utilsr   r   r   r   
_cli_utilsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r   sorted_EXPAND_PROPERTIES_SORT_OPTIONSEnumr   r(   Optionr   	ExpandOpt
spaces_clir   tablerD   ArgumentrP   boolrp   r   r   r   cacher   intr   )ss   0rC   <module>r      s      	    
   @ @   * J W 1 [ [ 9 L L u u   $ #  H%:;< %		/-+HQAqD+HsS SMELL\]a]f]fgy]z\{{|}./AB	  BC
 !>    	$**;;; ; /*	,	; ; ; ; ; ; 
;;> 
*H   !	:^U^^1\]]^:: : 	:
 
::" 2   BG<f^U^^1\]]^<f
D,%,,,<==
><f <f<f~   ( 	 	_dmr/k
<	
	k
  R	
	k
 O	
	k
* 43Z![[\+k
, D,%,,4h"iij-k
. /k
0 
1k
k
\E/	E/E/ E/ 	E/
 C=E/ 
E/P  Xc]  S U38M0N+N%O G ,Is   
K1
