
    U[i?]              &          d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZ ddlZddlmZmZ ddlmZ ddlmZ dd	lmZ d
dlmZmZmZ  ej6                  e      ZeD  cg c]  } | j<                  dk7  s| j<                    c} Ze	e  ejB                  d      f   Z"e	ee     ejF                  d      f   Z$e	ee    ejF                  ddjK                  e       d      f   Z&e	ee'e        ejF                  ddd      f   Z(e	ee'e        ejF                  ddd      f   Z)e	ee     ejF                  dd      f   Z*e	ee     ejF                  d      f   Z+e	ee     ejF                  d      f   Z,e	e- ejF                  ddd      f   Z.e	ee     ejF                  d       f   Z/e	ee'e        ejF                  d!d"      f   Z0e	ee     ejF                  d#d$d%      f   Z1e	ee-    ejF                  d&      f   Z2e	ee-    ejF                  d'      f   Z3e	e  ejB                  d(      f   Z4e	e  ejB                  d)      f   Z5e	ee'e        ejB                  d*      f   Z6e	e'e     ejB                  d+      f   Z7e	e  ejB                  d,      f   Z8e	e  ejB                  d-      f   Z9e	ee     ejF                  d.      f   Z: ed/      Z;e;jy                  d0d1      	 	 	 	 	 	 	 	 	 dd2e"d3e7d4e(d5e)d6e*d7e+d8e&d9e,d:e.d;e/d<ed=dfd>       Z=e;jy                  d?d@      	 	 ddAe8d;e/d<ed=dfdB       Z>dCe?e e f   dDe?e e f   d=e-fdEZ@dFe'e'ee eAf         dGe'e    dHee    d=dfdIZBe;jy                  dJdK      	 	 	 	 	 ddLe	e- ejF                  dMdNdO      f   d;e/d<edPe	ee'e        ejF                  dQdRdS      f   dTe	ee     ejF                  dU      f   d=dfdV       ZCe;jy                  dWdX      	 	 ddYe	e'e     ejB                  dZ      f   d;e/d<ed=dfd[       ZDe;jy                  d\d]      	 	 ddAe8d;e/d<ed=dfd^       ZE ed_      ZFe;j                  eFd`a       eFjy                  d0db      	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddce5dde6d2e$dee:d8e&d4e(d5e)d6e*d7e+d9e,d:e.d;e/d<edfe0dge1d=df dh       ZH edi      ZIe;j                  eIdja       eIjy                  d0dk      	 	 	 	 	 	 	 	 	 	 ddle4d2e"d3e7dme2dne3d4e(d5e)d6e*d7e+d8e&d9e,d;e/d<ed=dfdo       ZJeIjy                  dJdp      	 	 	 	 	 ddLe	e- ejF                  dMdNdq      f   d;e/d<edPe	ee'e        ejF                  dQdRdS      f   dTe	ee     ejF                  drdU      f   d=dfds       ZKeIjy                  dWdt      	 	 ddue	e'e     ejB                  dv      f   d;e/d<ed=dfdw       ZLeIjy                  dxdy      	 	 ddze9d;e/d<ed=dfd{       ZMeIjy                  dmd|      	 	 ddze9d;e/d<ed=dfd}       ZNeIjy                  d~d      	 	 ddze9d;e/d<ed=dfd       ZO ed      ZPeIj                  ePd`a       ePjy                  d0db      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddle4dce5dde6dme2dne3d2e$dee:d8e&d4e(d5e)d6e*d7e+d9e,d;e/d<edfe0dge1d=df$d       ZQdFe'e'ee eAf         dGe'e    d=e fdZRd=e
e e f   fdZSyc c} w )a  Contains commands to interact with jobs on the Hugging Face Hub.

Usage:
    # run a job
    hf jobs run <image> <command>

    # List running or completed jobs
    hf jobs ps [-a] [-f key=value] [--format TEMPLATE]

    # Stream logs from a job
    hf jobs logs <job-id>

    # Inspect detailed information about a job
    hf jobs inspect <job-id>

    # Cancel a running job
    hf jobs cancel <job-id>

    # Run a UV script
    hf jobs uv run <script>

    # Schedule a job
    hf jobs scheduled run <schedule> <image> <command>

    # List scheduled jobs
    hf jobs scheduled ps [-a] [-f key=value] [--format TEMPLATE]

    # Inspect a scheduled job
    hf jobs scheduled inspect <scheduled_job_id>

    # Suspend a scheduled job
    hf jobs scheduled suspend <scheduled_job_id>

    # Resume a scheduled job
    hf jobs scheduled resume <scheduled_job_id>

    # Delete a scheduled job
    hf jobs scheduled delete <scheduled_job_id>

    N)asdict)Path)	AnnotatedDictOptionalUnion)SpaceHardware	get_token)HfHubHTTPError)logging)load_dotenv   )TokenOpt
get_hf_apityper_factoryz	zero-a10gzThe Docker image to use.)helpz.Use a custom Docker image with `uv` installed.zTFlavor for the hardware, as in HF Spaces. Defaults to `cpu-basic`. Possible values: , .z-ez--envz/Set environment variables. E.g. --env ENV=valuez-sz	--secretszvSet secret environment variables. E.g. --secrets SECRET=value or `--secrets HF_TOKEN` to pass your Hugging Face token.z
--env-filez(Read in a file of environment variables.z/Read in a file of secret environment variables.zVMax duration: int/float with s (seconds, default), m (minutes), h (hours) or d (days).z-dz--detachz3Run the Job in the background and print the Job ID.zVThe namespace where the job will be running. Defaults to the current user's namespace.z--withz%Run with the given packages installedz-pz--pythonz5The Python interpreter to use for the run environmentz!Suspend (pause) the scheduled Jobz8Allow multiple instances of this Job to run concurrentlyzWOne of annually, yearly, monthly, weekly, daily, hourly, or a CRON schedule expression.z$UV script to run (local file or URL)zArguments for the scriptzThe command to run.zJob IDzScheduled Job IDzCRepository name for the script (creates ephemeral if not specified)zRun and manage Jobs on the Hub.runz	Run a Jobimagecommandenvsecretsenv_filesecrets_fileflavortimeoutdetach	namespacetokenreturnc           	         i }|rO|j                  t        t        |      j                         t        j
                  j                                      |xs g D ]:  }|j                  t        |t        j
                  j                                      < i }t               }|r3|j                  t        t        |      j                         |             |xs g D ]  }|j                  t        ||               t        |
      }|j                  | ||||||	      }t        d|j                          t        d|j                          |ry |j                  |j                        D ]  }t        |        y )Nenvironr    )r   r   r   r   r   r   r   Job started with ID: 	View at: job_id)updater   r   	read_textosr$   copy_get_extended_environr   run_jobprintidurlfetch_job_logs)r   r   r   r   r   r   r   r   r   r   r    env_map	env_valuesecrets_mapextended_environsecretapijoblogs                      f/var/www/html/chatbot/Makanify-Chatbot-3/venv/lib/python3.12/site-packages/huggingface_hub/cli/jobs.pyjobs_runr=      sW    )+G{4>#;#;#=rzzGXYZYB J	{9bjjoo6GHIJ -/K,.;tL'9'C'C'EO_`a-R J;v7GHIJ 5
!C
++  C 
!#&&
*+	IcggY
 !!!0 c
    logszFetch the logs of a Jobr)   c                 b    t        |      }|j                  | |      D ]  }t        |        y Nr%   r)   r   )r   r3   r0   )r)   r   r    r9   r;   s        r<   	jobs_logsrC     s4     5
!C!!9!E c
r>   job_propertiesfiltersc                 <   |j                         D ]  \  }}|| vr yd|v sd|v rQ|j                  dd      j                  dd      }t        j                  d| d| |   t        j                        rc y|j                         | |   j                         vs y y)	z5Check if scheduled job matches all specified filters.F*?z.*r   ^$T)itemsreplaceresearch
IGNORECASElower)rD   rE   keypatternregex_patterns        r<   _matches_filtersrT   )  s     Wn$'>SG^#OOC6>>sCHM99qq1>#3FV]]_N3$7$=$=$?? r>   rowsheadersfmtc           	          |rU|}| D ]M  }|}t        g d      D ].  \  }}d| d}||v s|j                  |t        ||               }0 t        |       O yt        t	        | |             y)z,Print output according to the chosen format.)r1   r   r   createdstatusz{{.z}})rV   N)	enumeraterL   strr0   	_tabulate)	rU   rV   rW   templaterowlineifieldplaceholders	            r<   _print_outputrd   ;  s    
 	CD%&UV B5 %eWD1$&<<SQ[ADB $K	 	ig./r>   psz	List Jobsallz-az--allz*Show all Jobs (default shows just running)filterz-fz--filterz>Filter output based on conditions provided (format: key=value)formatz%Format output using a custom templatec           
      R   	 t        |      }|j                  |      }g d}g }i }	|xs g D ]>  }
d|
v r)|
j                  dd      \  }}||	|j                         <   0t	        d|
 d       @ |D ]  }|j
                  r|j
                  j                  nd}| s|d	vr.|j                  }|j                  xs d
}|j                  xs g }|rdj                  |      nd
}|j                  r|j                  j                  d      nd
}|||j                         |d}t        ||	      s|j                  |||||g        |sM|	r:ddj                  |	j                         D cg c]  \  }}| d|  c}}       nd}t	        d|        y t!        |||       y c c}}w # t"        $ r}t	        d|        Y d }~y d }~wt$        t&        t(        f$ r}t	        d|        Y d }~y d }~wt*        $ r.}t	        dt-        |      j.                   d|        Y d }~y d }~ww xY w)Nr%   r   )zJOB IDIMAGE/SPACECOMMANDCREATEDSTATUS=r   )Warning: Ignoring invalid filter format ''. Use key=value format.UNKNOWN)RUNNINGUPDATINGN/A %Y-%m-%d %H:%M:%S)r1   r   rZ   r    matching filters: r    zNo jobs foundzError fetching jobs data: zError processing jobs data: Unexpected error - : )r   	list_jobssplitrP   r0   rZ   stager1   docker_imager   join
created_atstrftimerT   appendrK   rd   r   KeyError
ValueError	TypeError	Exceptiontype__name__)rf   r   r    rg   rh   r9   jobstable_headersrU   rE   frQ   valuer:   rZ   r)   image_or_spacecmdcommand_strr   propskvfilters_msges                            r<   jobs_psr   L  s3   6:=u%}}y}1Q,."$2 	_AaxWWS!_
U',		$A!D\]^	_  	SC),SZZ%%F6)@@VVF !--6N ++#C+.#((3-EK JM001DE]bJ "NfllnalmE#E73 KKj&QR3	S8 _f%dii0X1A3as0X&Y%Z[ln  M+/0dM62 1Y  0*1#.//j), 2,QC011 =#DG$4$4#5Rs;<<=sH   E$F& &F 7F& F&  F& &	H&/GH&G,,H&8$H!!H&inspectz0Display detailed information on one or more Jobsjob_idszThe jobs to inspectc           
          t        |      }| D cg c]  }|j                  ||       }}t        t        j                  |D cg c]  }t        |       c}dt                     y c c}w c c}w )Nr%   rB      indentdefault)r   inspect_jobr0   jsondumpsr   r\   )r   r   r    r9   r)   r   r:   s          r<   jobs_inspectr     s[     5
!CNUVFCOO6YO?VDV	$**T2cfSk21c
JK W2   A*A/cancelzCancel a Jobc                 B    t        |      }|j                  | |       y rA   )r   
cancel_job)r)   r   r    r9   s       r<   jobs_cancelr     s     5
!CNN&IN6r>   zERun UV scripts (Python with inline dependencies) on HF infrastructureuv)namez8Run a UV script (local file or URL) on HF infrastructurescriptscript_argsrepowith_pythonc                    i }|rO|j                  t        t        |      j                         t        j
                  j                                      |xs g D ]:  }|j                  t        |t        j
                  j                                      < i }t               }|r3|j                  t        t        |      j                         |             |xs g D ]  }|j                  t        ||               t        |      }|j                  | |xs g |||||||	||      }t        d|j                          t        d|j                          |
ry |j                  |j                        D ]  }t        |        y )Nr#   r%   )r   r   dependenciesr   r   r   r   r   r   r   _repor&   r'   r(   )r*   r   r   r+   r,   r$   r-   r.   r   
run_uv_jobr0   r1   r2   r3   )r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r4   r5   r6   r7   r8   r9   r:   r;   s                          r<   jobs_uv_runr     sf   $ )+G{4>#;#;#=rzzGXYZYB J	{9bjjoo6GHIJ,.K,.;tL'9'C'C'EO_`a-R J;v7GHIJ 5
!C
..%2  C 
!#&&
*+	IcggY
 !!!0 c
r>   z,Create and manage scheduled Jobs on the Hub.	scheduledzSchedule a Jobschedulesuspendconcurrencyc                 ~   i }|rO|j                  t        t        |      j                         t        j
                  j                                      |xs g D ]:  }|j                  t        |t        j
                  j                                      < i }t               }|r3|j                  t        t        |      j                         |             |xs g D ]  }|j                  t        ||               t        |      }|j                  ||| |||||	|
|
      }t        d|j                          y )Nr#   r%   )
r   r   r   r   r   r   r   r   r   r   Scheduled Job created with ID: )r*   r   r   r+   r,   r$   r-   r.   r   create_scheduled_jobr0   r1   )r   r   r   r   r   r   r   r   r   r   r   r   r    r4   r5   r6   r7   r8   r9   scheduled_jobs                       r<   scheduled_runr     s"     )+G{4>#;#;#=rzzGXYZYB J	{9bjjoo6GHIJ,.K,.;tL'9'C'C'EO_`a-R J;v7GHIJ 5
!C,, - M 
+M,<,<+=
>?r>   zList scheduled Jobsz1Show all scheduled Jobs (default hides suspended)z--formatc           
      $   	 t        |      }|j                  |      }g d}g }i }	|xs g D ]>  }
d|
v r)|
j                  dd      \  }}||	|j                         <   0t	        d|
 d       @ |D ]7  }|j
                  xs d}| s|r|j                  }|j                  xs d	}|j                  j                  xs d	}|j                  j                  xs g }|rd
j                  |      nd	}|j                  j                  r/|j                  j                  j                  j                  d      nd	}|j                  j                   r%|j                  j                   j                  d      nd	}||t#        |      |d}t%        ||	      s |j'                  |||||||g       : |sM|	r:ddj                  |	j)                         D cg c]  \  }}| d|  c}}       nd}t	        d|        y t+        |||       y c c}}w # t,        $ r}t	        d|        Y d }~y d }~wt.        t0        t2        f$ r}t	        d|        Y d }~y d }~wt4        $ r.}t	        dt7        |      j8                   d|        Y d }~y d }~ww xY w)Nr%   rj   )IDSCHEDULErk   rl   zLAST RUNzNEXT RUNSUSPENDro   r   rp   rq   Fru   rv   rw   )r1   r   r   r   rx   r   ry   zNo scheduled jobs foundz$Error fetching scheduled jobs data: z&Error processing scheduled jobs data: rz   r{   )r   list_scheduled_jobsr}   rP   r0   r   r1   r   job_specr   r   r   rZ   last_jobatr   next_job_run_atr\   rT   r   rK   rd   r   r   r   r   r   r   r   )rf   r   r    rg   rh   r9   scheduled_jobsr   rU   rE   r   rQ   r   r   r   sj_idr   r   r   r   last_job_atr   r   r   r   r   r   s                              r<   scheduled_psr   (  s   82=u%0090Eg,."$2 	_AaxWWS!_
U',		$A!D\]^	_ , 	oM#++4uG7!$$E$--6H*33@@IEN((006BC+.#((3-EK !''00 $$--0099:MN  !''77 $$44==>QR 
 !>c'l_jkE#E73KK.+{Tcelmn-	o0 _f%dii0X1A3as0X&Y%Z[ln  +K=9:dM62	 1Y  :4QC899j), <6qc:;; =#DG$4$4#5Rs;<<=sH   GH H	 H ;H 	H 	JH++JIJ!$J

Jz:Display detailed information on one or more scheduled Jobsscheduled_job_idszThe scheduled jobs to inspectc           
          t        |      }| D cg c]  }|j                  ||       }}t        t        j                  |D cg c]  }t        |       c}dt                     y c c}w c c}w )Nr%   scheduled_job_idr   r   r   )r   inspect_scheduled_jobr0   r   r   r   r\   )r   r   r    r9   r   r   r   s          r<   scheduled_inspectr   y  sr     5
!C !2 	!!3Cy!YN  
$**Pf]+PYZdg
hi	 Qr   deletezDelete a scheduled Jobr   c                 B    t        |      }|j                  | |       y Nr%   r   )r   delete_scheduled_jobr   r   r    r9   s       r<   scheduled_deleter     "     5
!C.>)Tr>   zSuspend (pause) a scheduled Jobc                 B    t        |      }|j                  | |       y r   )r   suspend_scheduled_jobr   s       r<   scheduled_suspendr     s"     5
!C/?9Ur>   resumez Resume (unpause) a scheduled Jobc                 B    t        |      }|j                  | |       y r   )r   resume_scheduled_jobr   s       r<   scheduled_resumer     r   r>   z(Schedule UV scripts on HF infrastructurec                    i }|
rO|j                  t        t        |
      j                         t        j
                  j                                      |xs g D ]:  }|j                  t        |t        j
                  j                                      < i }t               }|r3|j                  t        t        |      j                         |             |	xs g D ]  }|j                  t        ||               t        |      }|j                  ||xs g | |||||||||||      }t        d|j                          y )Nr#   r%   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r*   r   r   r+   r,   r$   r-   r.   r   create_scheduled_uv_jobr0   r1   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r4   r5   r6   r7   r8   r9   r:   s                           r<   scheduled_uv_runr     s0   ( )+G{4>#;#;#=rzzGXYZYB J	{9bjjoo6GHIJ,.K,.;tL'9'C'C'EO_`a-R J;v7GHIJ 5
!C

%
%%2 & C  
+CFF8
45r>   c           
         t        g | | D cg c]  }t        d |D               }}t        t        j                         j                  t        |      dz        }t        |      t        |      z   |kD  r|j                  t        |            }||xx   dz  cc<   t        |      t        |      z   |k  r#|t        |      z
  t        |      z
  ||   z   ||<   t        |      t        |      z   |kD  r dt        |      z  j                  | }g }|j                   |j                  |        |j                   |j                  |D cg c]  }d|z  	 c}        | D ]r  }	t        |	|      D 
cg c];  \  }
}t        t        |
            |kD  rt        |
      d|dz
   dz   n
t        |
      = }}
}|j                   |j                  |        t d	j                  |      S c c}w c c}w c c}}
w )
z
    Inspired by:

    - stackoverflow.com/a/8356620/593036
    - stackoverflow.com/questions/9535954/printing-lists-as-tabular-data
    c              3   D   K   | ]  }t        t        |              y w)N)lenr\   ).0xs     r<   	<genexpr>z_tabulate.<locals>.<genexpr>  s     /ac#a&k/s          z{{:{}}} -N   z...
)zipmaxr,   get_terminal_sizecolumnsr   sumindexrh   r   r\   r   )rU   rV   col
col_widthsterminal_widthcol_to_minimize
row_formatlineswr_   r   	col_widthrow_format_argss                r<   r]   r]     s    <?;N;Ng;NOC#/3//OJO--/77W9JKN
g,Z
(>
9$**3z?;?#)#w<#j/)^;*83z?*JSQX\*Y\fgv\w*wJ'	 g,Z
(>
9
 4*s7|+33Z@JE	LL"""G,-	LL"""j$AS1W$ABC : !$C 4
9 033q6{Y/FCF?Y]#e+CPQFR
 
 	&Z&&89: 99U# P %B
s   G*G/6A G4c                  d    t         j                  j                         } t               x}|| d<   | S )NHF_TOKEN)r,   r$   r-   r
   )r7   r    s     r<   r.   r.      s1    zz()',$r>   )	NNNNNNFNN)NN)FNNNN)NNNNNNNNNFNNNN)
NNNNNNNNNN)NNNNNNNNNNNNNNN)T__doc__r   r,   rM   dataclassesr   pathlibr   typingr   r   r   r   typerhuggingface_hubr	   r
   huggingface_hub.errorsr   huggingface_hub.utilsr   huggingface_hub.utils._dotenvr   
_cli_utilsr   r   r   
get_loggerr   loggerr   SUGGESTED_FLAVORSr\   ArgumentImageArgOptionImageOptr   	FlavorOptlistEnvOpt
SecretsOpt
EnvFileOptSecretsFileOpt
TimeoutOptbool	DetachOptNamespaceOptWithOpt	PythonOpt
SuspendOptConcurrencyOptScheduleArg	ScriptArgScriptArgsArg
CommandArgJobIdArgScheduledJobIdArgRepoOptjobs_clir   r=   rC   dictrT   intrd   r   r   r   uv_app	add_typerr   scheduled_appr   r   r   r   r   r   scheduled_uv_appr   r]   r.   )items   0r<   <module>r*     s9  'R  	 	   3 3  4 1 ) 5 ; ; 
		H	%,9WDTZZ;=VTZZW  ENN' SMELL= ]ELLcdhdmdmn  eA  dB  BC  D	 
T#YELL>
 T#YELL F
 SMELL7
 SMELL> SMELLe
 ELLB	 SMELLe T#YELL4 SMELLD	 TNELL0
 TNELLG ENNf ENN3	 T#YENN' IENN"
 ENN ENN  SMELLR ?@ 
%k* #'",,, 
, 	,
 , !, , , , , , 
, +,^ 
&89 #  
	 :T#s(^ d38n QU $0T%S/23 0d3i 0hWZm 0`d 0" 
$[) 	" 	 	1T=	=	
	
T= T= T= cQ	
	T=& 8	
	'T=2 
3T= *T=n 
)"TU #LS	&	
	L L L 
L VL 
(0 #777 7 
	7 17 
c	d   6  % VW "&#'"222 2 	2
 2 
2 2 2 !2 2 2 2 2 2 2  
!2 X2j #QR   ={  3 u#34
 "&#'"(@(@(@ (@ 	(@
  (@ 
(@ (@ (@ !(@ (@ (@ (@ (@ 
(@ 5(@V t"78 	" 	 	3M=	D	
	
M= M= M= cQ	
	M=& 8	
	'M=4 
5M= 9M=` y'cd #j S	0	
	j j j 
j ej$ x&>? #U'UU U 
	U @U y'HI #V'VV V 
	V JV x&HI #U'UU U 
	U JU !&PQ    (t  4 %&`a "&"&#'"#060606 06 	06
  06 06 06 06 
06 06 06 !06 06 06 06  !06" #06$ 
%06 b06lDeCHo./ $s)  6tCH~ m Xs   %[:[