
    gjbD              ?          d Z ddlZddlmZ ddlZddlmZmZ ddlm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZ ddlmZ  ed	
          Z ed
          Zee ej        d
          f         Zeedz   ej        d
          f         Zeedz   ej        d
          f         Ze                     dddg          	 	 dkdededdfd            Z!e                     ddg          dddddddddd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dz   ej        d*
          f         ded+ee" ej        d,
          f         d-ee" ej        d.
          f         d/ee"dz   ej        d0
          f         d1eedz   ej        d2
          f         d3ee#dz   ej        d4
          f         d5ed6eedz   ej        d7d8
          f         d9eedz   ej        d:
          f         d;ee"dz   ej        d<
          f         d=eedz   ej        d>d?
          f         d@eedz   ej        dAdB
          f         dCedDedEedFedGeedz   ej        dH ee          dIJ          f         ddf8dK            Z$e                     ddLg          	 	 	 	 dldee ej        d
          f         dedeedz   ej        dM
          f         dededdfdN            Z%	 dmdeddfdOZ& e                     ddPg          e&            e                     dQdRS          e&           e'                    edTU           e                     dVg          	 	 dkdedededdfdW            Z(e                     dXg          	 	 	 	 	 	 	 	 	 	 	 	 	 	 dndededeedz   ej        d
          f         deedz   ej        d 
          f         d!eedz   ej        d"
          f         d#eedz   ej        d$
          f         deedz   ej        dY
          f         d5eedz   ej        dZ
          f         d)eedz   ej        d*
          f         d+ee"dz   ej        d,
          f         d-ee"dz   ej        d.
          f         d/ee"dz   ej        d0
          f         d1eedz   ej        d2
          f         d3ee#dz   ej        d4
          f         deddf d[            Z)e                     d\g          	 	 	 dodeded^ee* ej        d_d`
          f         deddf
da            Z+e                     dbg          	 	 dkdedededdfdc            Z,e                     ddg          	 	 	 dodededeee* ej        dfdg
          f         deddf
dh            Z-e                     dig          	 	 dkdedededdfdj            Z.dS )pz2CLI commands for Hugging Face Inference Endpoints.    N)	Annotated)InferenceEndpointScalingMetricInferenceEndpointType)CLIErrorHfHubHTTPError   )

EnvFileOptEnvOptRevisionOptSecretsFileOpt
SecretsOpt
SoftChoiceTokenOpt
get_hf_apiparse_env_maptyper_factory)outz(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.z	list | lszhf endpoints lsz"hf endpoints ls --namespace my-org)examples	namespacetokenreturnc                    t          |          }	 |                    | |          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wg }|D ]}|j	        }|
                    di           }|
                    di           }	|
                    di           }
|
                    d	i           }|                    |
                    d
d          t          |	t                    r|	
                    dd          ndt          |t                    r|
                    dd          ndt          |	t                    r|	
                    dd          ndt          |	t                    r|	
                    dd          ndt          |
t                    r|

                    dd          ndt          |t                    r|
                    dd          ndt          |t                    r|
                    dd          ndd           t          j        |d
           dS )z6Lists all Inference Endpoints for the given namespace.r   )r   r   zListing failed: codeNstatusmodelcomputeprovidername 
repositorystatetask	frameworkinstanceTypevendorregion)r!   r   r   r%   r&   instancer(   r)   )id_key)r   list_inference_endpointsr   r   errortyperExitresponsestatus_coderawgetappend
isinstancedicttable)r   r   api	endpointsr-   resultsendpointr2   r   r   r   r    s               k/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/huggingface_hub/cli/inference_endpoints.pylsr=   0   sP    5
!
!
!CE009E0RR		 E E E	,U,,---jen8999uDE G 
 
l2&&$$'')R((77:r**++8B5$8O8OW<444UW5?5M5MU&**Wb111SU1;E41H1HP		&"---b;EeT;R;RZUYY{B777XZ?I'SW?X?X`GKK;;;^`8B8T8R8RZ(,,x444XZ8B8T8R8RZ(,,x444XZ	 		
 	
 	
 	
 Igf%%%%%%s   * 
A07A++A0deployzChf endpoints deploy my-endpoint --repo gpt2 --framework pytorch ...)r!   r   )r   r%   r   min_replicamax_replicascale_to_zero_timeoutscaling_metricscaling_thresholdrevisioncustom_imagehealth_routeportcontainer_commandcontainer_argsenvenv_filesecretssecrets_fileendpoint_typer!   repozeThe name of the model repository associated with the Inference Endpoint (e.g. 'openai/gpt-oss-120b').r&   z@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').r)   zTThe cloud region in which the Inference Endpoint will be created (e.g. 'us-east-1').r(   zVThe cloud provider or vendor where the Inference Endpoint will be hosted (e.g. 'aws').r%   zCThe task on which to deploy the model (e.g. 'text-classification').r?   zVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.r@   zRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.rA   zFThe duration in minutes before an inactive endpoint is scaled to zero.rB   z!The metric reference for scaling.rC   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.rD   rE   z--custom-imagezfDocker image URL for a custom container (e.g. 'nexagi/sglang:v0.5.12'). Requires '--framework custom'.rF   z]Health check route exposed by the custom container (e.g. '/health'). Requires --custom-image.rG   zKPort the custom container listens on (e.g. 30000). Requires --custom-image.rH   z--container-commandzOverride the container entrypoint, as a quoted string split into tokens (e.g. "python -m sglang.launch_server"). Requires --custom-image.rI   z--container-argszArguments appended to the container entrypoint, as a quoted string split into tokens (e.g. "--tp 8 --reasoning-parser qwen3"). Requires --custom-image.rJ   rK   rL   rM   rN   z--typezTEndpoint access type. Defaults to 'authenticated' (token-gated, publicly reachable).)
click_typer   c                   ||||s|rt          d          d}|d|i}|||d<   |||d<   d t          ||                                          D             }d t          ||                                          D             }i }|||d<   |||d	<   |rt          j        |          |d
<   |rt          j        |          |d<   |r||d<   |r||d<   t          |
          } |j        d"i d| d|d|d|d|d|d|d|d|d|	d|
d|d|d|d|d|d||} t          j        | j	                   t          j
        d |  d!           dS )#z3Deploy an Inference Endpoint from a Hub repository.NzX--health-route, --port, --container-command and --container-args require --custom-image.urlhealthRouterG   c                     i | ]
\  }}||pd S r"    .0keyvalues      r<   
<dictcomp>zdeploy.<locals>.<dictcomp>   s"    WWWJCsEKRWWW    c                     i | ]
\  }}||pd S rX   rY   rZ   s      r<   r^   zdeploy.<locals>.<dictcomp>   s"    ccc
U3cccr_   typerE   rH   rI   rJ   rL   r   r!   r#   r&   rP   rQ   rR   r)   r(   r   r%   r   r?   r@   rB   rC   rA   rD   zUse 'hf endpoints describe z!' to check the deployment status.rY   )r   r   itemsshlexsplitr   create_inference_endpointr   r6   r2   hint)!r!   rO   r&   rP   rQ   rR   r)   r(   r   r%   r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   custom_image_dictenv_mapsecrets_mapparamsr8   r;   s!                                    r<   r>   r>   S   sq   V !9T=MQb=Mft=Mqrrr%)"L1#/;m,(,f%WW-X2N2N2T2T2V2VWWWGccmG\6Z6Z6`6`6b6bcccK F &v$!2~ E&+k2C&D&D"# ?#(;~#>#>   u ('y
5
!
!
!C,s,   T4 )  K	
 $m $m v v ) T e  K  K &~ ,+  43!" 
% H( HX\HR4RRRSSSSSr_   zChf endpoints catalog deploy --repo meta-llama/Llama-3.2-1B-InstructzPThe hardware accelerator to be used for inference (e.g. 'cpu', 'gpu', 'neuron').c                 "   t          |          }	 |                    | ||||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j	        |j
                   dS )z4Deploy an Inference Endpoint from the Model Catalog.r   )repo_idr!   rP   r   r   zDeployment failed: r   N)r   &create_inference_endpoint_from_catalogr   r   r-   r.   r/   r0   r1   r6   r2   )rO   r!   rP   r   r   r8   r;   r-   s           r<   deploy_from_catalogrn     s    & 5
!
!
!C
E==# > 
 
  E E E	///000jen8999uDE HX\   - 
A37A..A3c                    t          |           }	 |                    |           }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j	        d|i           dS )zList available Catalog models.r   zCatalog fetch failed: r   Nmodels)
r   list_inference_catalogr   r   r-   r.   r/   r0   r1   r6   )r   r8   rq   r-   s       r<   list_catalogrs   6  s     5
!
!
!CE++%+88 E E E	2522333jen8999uDE Hh     s   ) 
A/7A**A/zhf endpoints catalog lszlist-catalogT)r!   hiddencatalogr!   z!hf endpoints describe my-endpointc                    t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j	        |j
                   dS )z+Get information about an existing endpoint.r   r!   r   r   zFetch failed: r   N)r   get_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   r!   r   r   r8   r;   r-   s         r<   describer{   K  s     5
!
!
!CE--49TY-ZZ E E E	*5**+++jen8999uDE HX\   + 
A17A,,A1z/hf endpoints update my-endpoint --min-replica 2zBThe machine learning framework used for the model (e.g. 'custom').zrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').c                 6   t          |          }	 |                    | |||||||||	|
||||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j	        |j
                   dS )zUpdate an existing endpoint.r   )r!   r   r#   r&   rD   r%   rP   rQ   rR   r?   r@   rA   rB   rC   r   zUpdate failed: r   N)r   update_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   )r!   r   rO   rP   rQ   rR   r&   rD   r%   r?   r@   rA   rB   rC   r   r8   r;   r-   s                     r<   updater   \  s    ^ 5
!
!
!CE00#''##"7)/ 1 
 
"  E E E	+E++,,,jen8999uDE HX\s   $7 
A=7A88A=zhf endpoints delete my-endpointFyesz--yeszSkip confirmation prompts.c                 T   t          j        d|  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'?)r   r   rx   zDelete failed: r   Nz	Deleted 'z'.rv   )r   confirmr   delete_inference_endpointr   r-   r.   r/   r0   r1   result)r!   r   r   r   r8   r-   s         r<   deleter     s     K,D,,,#6666
5
!
!
!CE%%49E%RRRR E E E	+E++,,,jen8999uDE J#4###$//////s   A 
B7BBzhf endpoints pause my-endpointc                    t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j	        |j
                   dS )zPause an Inference Endpoint.r   rx   zPause failed: r   N)r   pause_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   rz   s         r<   pauser     s     5
!
!
!CE//TYV[/\\ E E E	*5**+++jen8999uDE HX\r|   zhf endpoints resume my-endpoint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          j	        |j
                   dS )zResume an Inference Endpoint.r   )r!   r   r   
running_okzResume failed: r   N)r   resume_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   )r!   r   r   r   r8   r;   r-   s          r<   resumer     s     5
!
!
!C	E0022	 1 
 
  E E E	+E++,,,jen8999uDE HX\ro   z&hf endpoints scale-to-zero my-endpointc                    t          |          }	 |                    | ||          }nI# t          $ r<}t          j        d|            t          j        |j        j                  |d}~ww xY wt          j	        |j
                   dS )z$Scale an Inference Endpoint to zero.r   rx   zScale To Zero failed: r   N)r    scale_to_zero_inference_endpointr   r   r-   r.   r/   r0   r1   r6   r2   rz   s         r<   scale_to_zeror     s     5
!
!
!CE77TY^c7dd E E E	2522333jen8999uDE HX\r|   )NN)NNNN)N)NNNNNNNNNNNNNN)NFN)/__doc__rc   typingr   r.   $huggingface_hub._inference_endpointsr   r   huggingface_hub.errorsr   r   
_cli_utilsr	   r
   r   r   r   r   r   r   r   r   _outputr   ie_clicatalog_appstrArgumentNameArgOptionNameOptNamespaceOptcommandr=   intfloatr>   rn   rs   	add_typerr{   r   boolr   r   r   r   rY   r_   r<   <module>r      s>   8 8         f f f f f f f f ; ; ; ; ; ; ; ;                              
F	G	G	Gm!QRRR EN()))+ $JEL&''')
 $JELn   '8:^&_``"& &&& 
& & & a`&D X)n(opp\ # 	 	
 	
 	 	 	  	 	 	 	 	#' 	M|T |T |T
|T
x	
 	
 	
	|T S	
 	
 	
	|T R	
 	
 	
	|T( a	
 	
 	
	)|T4 l	
 	
 	
	5|T@ g	
 	
 	
	A|TL i	
 	
 	
	M|TZ [|T\ d
V	
 	
 	
	]|Th i|Tj i	
 	
 	
	k|Tv e	
 	
 	
	w|TB %d
Y	
 	
 	
	C|TN &-4	
 	
 	
	O|TZ !x	
 	
 	
	[|Tf g|Th d
y	
 	
 	
	i|Tv d
p	
 	
 	
	w|TB d
^	
 	
 	
	C|TN !d
!T	
 	
 	
		O|Tb d
U	
 	
 	
		c|Tv 
w|Tx y|Tz {|T| !}|T~ d
!z"788g	
 	
 	
	|TN 
O|T |T |T qp|T~ (.s-tuu  	" 
x	
 	
 	
	  d
c	
 	
 	
	    
!   vuF ! !!	! ! ! ! L  0I/J  K KL Y Y Y 0N4 0 0 > > >   9  - - - =>?? # 
  
	   @?  KLMM # 	 	 	 	 	 	 	 	 	 	 	 	Wd d
dd d
x	
 	
 	
	d d
R	
 	
 	
	d d
a	
 	
 	
	d* d
l	
 	
 	
	+d6 d
U	
 	
 	
	7dB d
 F	
 	
 	
	CdN d
V	
 	
 	
	OdZ d
i	
 	
 	
	[df d
e	
 	
 	
	gdr %d
Y	
 	
 	
	sd~ &-4	
 	
 	
	dJ !x	
 	
 	
	KdV WdX 
Yd d d NMdN ;<== # 	0 0
00 
W#?@@@	B
0 0 
0 0 0 >=0, :;<< # 
  
	   =<  ;<== # 	 
 ''j	
 	
 	
	  
   >=6 BCDD # 
  
	   ED  r_   