
    -i'2              &       X   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
 ddlmZmZmZ  ed	          Z ed
	          Zee ej        d	          f         Zeee          ej        d	          f         Zeee          ej        d	          f         ZdeddfdZe                                	 	 dJdededdfd            Ze                    d          ddddddddddedee ej        d	          f         dee ej        d	          f         dee ej        d	          f         dee ej        d	          f         dee ej        d 	          f         d!ee ej        d"	          f         d#ee ej        d$	          f         ded%eee          ej        d&	          f         ded'ee ej        d(	          f         d)ee ej        d*	          f         d+eee          ej        d,	          f         d-eee          ej        d.	          f         d/eee          ej        d0	          f         ddf"d1            Ze                    d          	 	 	 dKdee ej        d	          f         dedededdf
d2            Z	 dLdeddfd3Z e                    d4          e            e                    d5d6d78          e           e                    ed9           e                                	 	 dJdedededdfd:            Z e                                	 	 	 	 	 	 	 	 	 	 	 	 	 	 dMdededeee          ej        d	          f         deee          ej        d	          f         deee          ej        d	          f         deee          ej        d 	          f         deee          ej        d;	          f         d<eee          ej        d=	          f         d%eee          ej        d&	          f         d'eee          ej        d(	          f         d)eee          ej        d*	          f         d+eee          ej        d,	          f         d-eee          ej        d.	          f         d/eee          ej        d0	          f         deddf d>            Z!e                                	 	 	 dNdeded@ee" ej        dAdB	          f         deddf
dC            Z#e                                	 	 dJdedededdfdD            Z$e                                	 	 	 dNdededEee" ej        dFdG	          f         deddf
dH            Z%e                                	 	 dJdedededdfdI            Z&dS )Oz2CLI commands for Hugging Face Inference Endpoints.    N)	AnnotatedOptional)InferenceEndpointInferenceEndpointScalingMetric)HfHubHTTPError   )TokenOpt
get_hf_apityper_factoryz(Manage Hugging Face Inference Endpoints.)helpz.Interact with the Inference Endpoints catalog.zEndpoint name.z_The namespace associated with the Inference Endpoint. Defaults to the current user's namespace.endpointreturnc                 b    t          j        t          j        | j        dd                     d S )N   Tindent	sort_keys)typerechojsondumpsraw)r   s    e/var/www/html/speakWrite/venv/lib/python3.11/site-packages/huggingface_hub/cli/inference_endpoints.py_print_endpointr   #   s+    	Jtz(,qDAAABBBBB    	namespacetokenc                 T   t          |          }	 |                    | |          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j        t          j	        dd |D             idd	
                     dS )z6Lists all Inference Endpoints for the given namespace.r   )r   r   zListing failed: codeNitemsc                     g | ]	}|j         
S  )r   ).0r   s     r   
<listcomp>zls.<locals>.<listcomp>6   s    >>>x|>>>r   r   Tr   )
r
   list_inference_endpointsr   r   r   Exitresponsestatus_coder   r   )r   r   api	endpointserrors        r   lsr.   '   s     5
!
!
!CE009E0RR		 E E E
-e--...jen8999uDE 
J
>>I>>>?	
 	
 	
    s   * 
A07A++A0deploy)name)r   taskr   min_replicamax_replicascale_to_zero_timeoutscaling_metricscaling_thresholdr0   repozeThe name of the model repository associated with the Inference Endpoint (e.g. 'openai/gpt-oss-120b').	frameworkz@The machine learning framework used for the model (e.g. 'vllm').acceleratorz?The hardware accelerator to be used for inference (e.g. 'cpu').instance_sizezNThe size or type of the instance to be used for hosting the model (e.g. 'x4').instance_typezYThe cloud instance type where the Inference Endpoint will be deployed (e.g. 'intel-icl').regionzTThe cloud region in which the Inference Endpoint will be created (e.g. 'us-east-1').vendorzVThe cloud provider or vendor where the Inference Endpoint will be hosted (e.g. 'aws').r1   zCThe task on which to deploy the model (e.g. 'text-classification').r2   zVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.r3   zRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.r4   zFThe duration in minutes before an inactive endpoint is scaled to zero.r5   z!The metric reference for scaling.r6   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.c                    t          |
          }|                    | |||||||||	|
|||||          }t          |           dS )z3Deploy an Inference Endpoint from a Hub repository.r   )r0   
repositoryr8   r9   r:   r;   r<   r=   r   r1   r   r2   r3   r5   r6   r4   N)r
   create_inference_endpointr   )r0   r7   r8   r9   r:   r;   r<   r=   r   r1   r   r2   r3   r4   r5   r6   r+   r   s                     r   r/   r/   =   su    l 5
!
!
!C,,##%+3! -  H& Hr   c                    t          |          }	 |                    | |||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )z4Deploy an Inference Endpoint from the Model Catalog.r   )repo_idr0   r   r   zDeployment failed: r    N)	r
   &create_inference_endpoint_from_catalogr   r   r   r(   r)   r*   r   )r7   r0   r   r   r+   r   r-   s          r   deploy_from_catalogrD      s     5
!
!
!C	E==	 > 
 
  E E E
000111jen8999uDE Hs   , 
A27A--A2c                 >   t          |           }	 |                    |           }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j        t          j	        d|idd                     dS )	List available Catalog models.r   zCatalog fetch failed: r    Nmodelsr   Tr   )
r
   list_inference_catalogr   r   r   r(   r)   r*   r   r   )r   r+   rG   r-   s       r   list_catalogrI      s     5
!
!
!CE++%+88 E E E
3E33444jen8999uDE 
Jtz8V,Q$GGGHHHHHs   ) 
A/7A**A/r.   zlist-catalogrF   T)r0   r   hiddencatalogc                 
   t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )z+Get information about an existing endpoint.r   r0   r   r   zFetch failed: r    N)	r
   get_inference_endpointr   r   r   r(   r)   r*   r   r0   r   r   r+   r   r-   s         r   describerP      s     5
!
!
!CE--49TY-ZZ E E E
+E++,,,jen8999uDE H   + 
A17A,,A1zBThe machine learning framework used for the model (e.g. 'custom').revisionzrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').c                 "   t          |          }	 |                    | |||||||||	|
||||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )zUpdate an existing endpoint.r   )r0   r   r?   r8   rR   r1   r9   r:   r;   r2   r3   r4   r5   r6   r   zUpdate failed: r    N)	r
   update_inference_endpointr   r   r   r(   r)   r*   r   )r0   r   r7   r9   r:   r;   r8   rR   r1   r2   r3   r4   r5   r6   r   r+   r   r-   s                     r   updaterU      s    ^ 5
!
!
!CE00#''##"7)/ 1 
 
"  E E E
,U,,---jen8999uDE Hs   $7 
A=7A88A=Fyesz--yeszSkip confirmation prompts.c                    |sGt          j        d|  d          }|| k    r)t          j        d           t          j        d          t	          |          }	 |                    | ||           nI# t          $ r<}t          j        d|            t          j        |j        j                  |d	}~ww xY wt          j        d
|  d           d	S )z)Delete an Inference Endpoint permanently.zDelete endpoint 'z'? Type the name to confirm.zAborted.r   r    r   rM   zDelete failed: Nz	Deleted 'z'.)	r   promptr   r(   r
   delete_inference_endpointr   r)   r*   )r0   r   rV   r   confirmationr+   r-   s          r   deleter[   T  s     %|$Z$Z$Z$Z[[4Jz"""*!$$$$
5
!
!
!CE%%49E%RRRR E E E
,U,,---jen8999uDE 
J#4###$$$$$s   A4 4
B:>7B55B:c                 
   t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )zPause an Inference Endpoint.r   rM   zPause failed: r    N)	r
   pause_inference_endpointr   r   r   r(   r)   r*   r   rO   s         r   pauser^   o  s     5
!
!
!CE//TYV[/\\ E E E
+E++,,,jen8999uDE HrQ   fail_if_already_runningz--fail-if-already-runningzWIf `True`, the method will raise an error if the Inference Endpoint is already running.c                    t          |          }	 |                    | |||           }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )zResume an Inference Endpoint.r   )r0   r   r   
running_okzResume failed: r    N)	r
   resume_inference_endpointr   r   r   r(   r)   r*   r   )r0   r   r_   r   r+   r   r-   s          r   resumerc     s     5
!
!
!C	E0022	 1 
 
  E E E
,U,,---jen8999uDE Hs   - 
A37A..A3c                 
   t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          |           dS )z$Scale an Inference Endpoint to zero.r   rM   zScale To Zero failed: r    N)	r
    scale_to_zero_inference_endpointr   r   r   r(   r)   r*   r   rO   s         r   scale_to_zerorf     s     5
!
!
!CE77TY^c7dd E E E
3E33444jen8999uDE HrQ   )NN)NNN)N)NNNNNNNNNNNNNN)NFN)'__doc__r   typingr   r   r   $huggingface_hub._inference_endpointsr   r   huggingface_hub.errorsr   
_cli_utilsr	   r
   r   ie_clicatalog_appstrArgumentNameArgOptionNameOptNamespaceOptr   commandr.   intfloatr/   rD   rI   	add_typerrP   rU   boolr[   r^   rc   rf   r$   r   r   <module>ry      sz   8 8  & & & & & & & &  b b b b b b b b 1 1 1 1 1 1 ; ; ; ; ; ; ; ; ; ; 
F	G	G	Gm!QRRR
EN()))+ SMEL&''')
 SMELn  C/ CD C C C C "  
   * X\ # 	 	
 	
 	 	 	ei i i
i
x	
 	
 	
	i S	
 	
 	
	i R	
 	
 	
	i( a	
 	
 	
	)i4 l	
 	
 	
	5i@ g	
 	
 	
	AiL i	
 	
 	
	MiZ [i\ V	
 	
 	
	]ih iij i	
 	
 	
	kiv e	
 	
 	
	wiB %Y	
 	
 	
	CiN /04	
 	
 	
	OiZ !x	
 	
 	
	[if 
gi i i iX (## " 
x	
 	
 	
	    
   $#8 I II	I I I I      | , , , WN)IRV W WXd e e e   9  - - -  # 
  
	      # 	 	 	 	 	 	 	 	 	 	 	 	Wd d
dd x	
 	
 	
	d R	
 	
 	
	d a	
 	
 	
	d* l	
 	
 	
	+d6 U	
 	
 	
	7dB  F	
 	
 	
	CdN V	
 	
 	
	OdZ i	
 	
 	
	[df e	
 	
 	
	gdr %Y	
 	
 	
	sd~ /04	
 	
 	
	dJ !x	
 	
 	
	KdV WdX 
Yd d d dN  # 	% %
%% 
W#?@@@	B
% % 
% % % %4  # 
  
	      # 	 
 ''j	
 	
 	
	  
   6  # 
  
	     r   