o
    0j6                  &   @   sR  d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
mZ ddlmZ ed	d
Zedd
Zeeejdd
f ZeedB ejdd
f ZeedB ejdd
f Zejdddgd		d_dede	ddfddZejddgdddddddddddedeeejdd
f deeejdd
f d eeejd!d
f d"eeejd#d
f d$eeejd%d
f d&eeejd'd
f d(eeejd)d
f ded*eedB ejd+d
f de	d,eeejd-d
f d.eeejd/d
f d0eedB ejd1d
f d2eedB ejd3d
f d4eedB ejd5d
f ddf"d6dZejdd7gd				d`deeejdd
f ded eedB ejd8d
f dede	ddfd9d:Z	dade	ddfd;d<Zejdd=gde ejd>d?d@e ejedAdB ejdCgd		d_dedede	ddfdDdEZejdFgd														dbdededeedB ejdd
f d eedB ejd!d
f d"eedB ejd#d
f d$eedB ejd%d
f deedB ejdGd
f dHeedB ejdId
f d*eedB ejd+d
f d,eedB ejd-d
f d.eedB ejd/d
f d0eedB ejd1d
f d2eedB ejd3d
f d4eedB ejd5d
f de	ddf dJdKZejdLgd		M	dcdededNee ejdOdPd
f de	ddf
dQdRZ!ejdSgd		d_dedede	ddfdTdUZ"ejdVgd		M	dcdededWee ejdXdYd
f de	ddf
dZd[Z#ejd\gd		d_dedede	ddfd]d^Z$dS )dz2CLI commands for Hugging Face Inference Endpoints.    )	AnnotatedN)InferenceEndpointScalingMetric)HfHubHTTPError   )TokenOpt
get_hf_api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                 C   sl  t |d}z	|j| |d}W n ty+ } ztd|  tj|jjd|d}~ww g }|D ]|}|j	}|
di }|
di }	|
di }
|
d	i }||
d
dt|	tr_|	
ddndt|trk|
ddndt|	trw|	
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 q0tj|d
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	frameworkZinstanceTypevendorregion)r   r   r   r   r   instancer   r   )Zid_key)r   Zlist_inference_endpointsr   r	   errortyperExitresponsestatus_coderawgetappend
isinstancedicttable)r   r   apiZ	endpointsr   resultsendpointr$   r   r   r   r    r-   h/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/huggingface_hub/cli/inference_endpoints.pyls$   s6   

r/   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_thresholdr   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').r1   zVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.r2   zRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.r3   zFThe duration in minutes before an inactive endpoint is scaled to zero.r4   z!The metric reference for scaling.r5   zeThe scaling metric threshold used to trigger a scale up. Ignored when scaling metric is not provided.c                C   s   t |
d}|jdi d| d|d|d|d|d|d|d	|d
|d|	d|
d|d|d|d|d|}t|j dS )z3Deploy an Inference Endpoint from a Hub repository.r   r   r   r   r7   r8   r9   r   r   r   r   r   r1   r2   r4   r5   r3   Nr-   )r   Zcreate_inference_endpointr	   r(   r$   )r   r6   r   r7   r8   r9   r   r   r   r   r   r1   r2   r3   r4   r5   r*   r,   r-   r-   r.   r0   G   sF   
V
	
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              
   C   sn   t |d}z|j| ||||d}W n ty. } ztd|  tj|jjd|d}~ww t	|j
 dS )z4Deploy an Inference Endpoint from the Model Catalog.r   )Zrepo_idr   r7   r   r   zDeployment failed: r   N)r   Z&create_inference_endpoint_from_catalogr   r	   r   r    r!   r"   r#   r(   r$   )r6   r   r7   r   r   r*   r,   r   r-   r-   r.   deploy_from_catalog   s   

r:   c              
   C   sh   t | d}z|j| d}W n ty* } ztd|  tj|jjd|d}~ww t	d|i dS )zList available Catalog models.r   zCatalog fetch failed: r   Nmodels)
r   Zlist_inference_catalogr   r	   r   r    r!   r"   r#   r(   )r   r*   r;   r   r-   r-   r.   list_catalog   s   
r<   zhf endpoints catalog lszlist-catalogT)r   Zhiddencatalogr   z!hf endpoints describe my-endpointc              
   C   j   t |d}z
|j| ||d}W n ty, } ztd|  tj|jjd|d}~ww t	|j
 dS )z+Get information about an existing endpoint.r   r   r   r   zFetch failed: r   N)r   Zget_inference_endpointr   r	   r   r    r!   r"   r#   r(   r$   r   r   r   r*   r,   r   r-   r-   r.   describe      
rB   z/hf endpoints update my-endpoint --min-replica 2zBThe machine learning framework used for the model (e.g. 'custom').revisionzrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').c                 C   s   t |d}z|j| |||||||||	|
||||d}W n ty8 } ztd|  tj|jjd|d}~ww t	|j
 dS )zUpdate an existing endpoint.r   )r   r   r   r   rD   r   r7   r8   r9   r1   r2   r3   r4   r5   r   zUpdate failed: r   N)r   Zupdate_inference_endpointr   r	   r   r    r!   r"   r#   r(   r$   )r   r   r6   r7   r8   r9   r   rD   r   r1   r2   r3   r4   r5   r   r*   r,   r   r-   r-   r.   update   s2   
O
rE   zhf endpoints delete my-endpointFyesz--yeszSkip confirmation prompts.c              
   C   s   t jd|  d|d t|d}z
|j| ||d W n ty7 } zt d|  tj|jj	d|d}~ww t j
d	|  d
| d dS )z)Delete an Inference Endpoint permanently.zDelete endpoint 'z'?)rF   r   r@   zDelete failed: r   Nz	Deleted 'z'.r>   )r	   Zconfirmr   Zdelete_inference_endpointr   r   r    r!   r"   r#   result)r   r   rF   r   r*   r   r-   r-   r.   deleted  s   
rH   zhf endpoints pause my-endpointc              
   C   r?   )zPause an Inference Endpoint.r   r@   zPause failed: r   N)r   Zpause_inference_endpointr   r	   r   r    r!   r"   r#   r(   r$   rA   r-   r-   r.   pause{  rC   rI   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              
   C   sn   t |d}z|j| ||| d}W n ty. } ztd|  tj|jjd|d}~ww t	|j
 dS )zResume an Inference Endpoint.r   )r   r   r   Z
running_okzResume failed: r   N)r   Zresume_inference_endpointr   r	   r   r    r!   r"   r#   r(   r$   )r   r   rJ   r   r*   r,   r   r-   r-   r.   resume  s   

rK   z&hf endpoints scale-to-zero my-endpointc              
   C   r?   )z$Scale an Inference Endpoint to zero.r   r@   zScale To Zero failed: r   N)r   Z scale_to_zero_inference_endpointr   r	   r   r    r!   r"   r#   r(   r$   rA   r-   r-   r.   scale_to_zero  rC   rL   )NN)NNNN)N)NNNNNNNNNNNNNN)NFN)%__doc__typingr   r    Z$huggingface_hub._inference_endpointsr   Zhuggingface_hub.errorsr   Z
_cli_utilsr   r   r   _outputr	   Zie_cliZcatalog_appstrZArgumentZNameArgOptionZNameOptZNamespaceOptcommandr/   intfloatr0   r:   r<   Z	add_typerrB   rE   boolrH   rI   rK   rL   r-   r-   r-   r.   <module>   s   



". &-.45;AGMSk#
	!'-39?EKLg
