o
    yqi+                     @   sJ  d Z ddlZddlmZ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 edd	Zed
d	Zeeejdd	f Zeee ejdd	f ZdeddfddZe 		dOdededdfddZej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e ejd(d	f deddfd)dZejdd		dOdedeeejdd	f dededdf
d*d+Z	dPdeddfd,d-Zejdde ejd.d/d0d1e ejed2d e 		dOdedededdfd3d4Ze 												dQdededeee ejdd	f deee ejdd	f deee ejd d	f d!eee ejd"d	f deee ejd5d	f d6eee ejd7d	f d'eee ejd(d	f d8eee ejd9d	f d:eee ejd;d	f d<eee ejd=d	f deddfd>d?Ze 		@	dRdededAeeejdBdCd	f deddf
dDdEZ e 		dOdedededdfdFdGZ!e 		@	dRdededHeeejdIdJd	f deddf
dKdLZ"e 		dOdedededdfdMdNZ#dS )Sz2CLI commands for Hugging Face Inference Endpoints.    N)	AnnotatedOptional)InferenceEndpoint)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                 C   s   t tj| jddd d S )N   Tindent	sort_keys)typerechojsondumpsraw)r    r   n/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/huggingface_hub/cli/inference_endpoints.py_print_endpoint   s   r   	namespacetokenc              
   C   s   t |d}z	|j| |d}W n ty+ } ztd|  tj|jjd|d}~ww ttj	ddd |D id	d
d dS )z6Lists all Inference Endpoints for the given namespace.r   )r   r   zListing failed: codeNitemsc                 S   s   g | ]}|j qS r   )r   ).0r   r   r   r   
<listcomp>2   s    zls.<locals>.<listcomp>r   Tr   )
r   Zlist_inference_endpointsr   r   r   Exitresponsestatus_coder   r   )r   r   apiZ	endpointserrorr   r   r   ls#   s   
r&   deploy)name)r   taskr   r(   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').r)   zCThe task on which to deploy the model (e.g. 'text-classification').c                C   s6   t |
d}|j| |||||||||	|
d}t| dS )z3Deploy an Inference Endpoint from a Hub repository.r   )r(   
repositoryr+   r,   r-   r.   r/   r0   r   r)   r   N)r   Zcreate_inference_endpointr   )r(   r*   r+   r,   r-   r.   r/   r0   r   r)   r   r$   r   r   r   r   r'   9   s   
8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S )z4Deploy an Inference Endpoint from the Model Catalog.r   )Zrepo_idr(   r   r   zDeployment failed: r   N)	r   Z&create_inference_endpoint_from_catalogr   r   r   r!   r"   r#   r   )r(   r*   r   r   r$   r   r%   r   r   r   deploy_from_catalog   s   

r2   c              
   C   st   t | d}z|j| d}W n ty* } ztd|  tj|jjd|d}~ww ttj	d|iddd dS )	List available Catalog models.r   zCatalog fetch failed: r   Nmodelsr   Tr   )
r   Zlist_inference_catalogr   r   r   r!   r"   r#   r   r   )r   r$   r4   r%   r   r   r   list_catalog   s   
r5   zlist-catalogr3   T)r(   r
   Zhiddencatalogc              
   C   f   t |d}z
|j| ||d}W n ty, } ztd|  tj|jjd|d}~ww t| 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   describe      
r:   zBThe machine learning framework used for the model (e.g. 'custom').revisionzrThe specific model revision to deploy on the Inference Endpoint (e.g. '6c0e6080953db56375760c0471a8c5f2929baf11').min_replicazVThe minimum number of replicas (instances) to keep running for the Inference Endpoint.max_replicazRThe maximum number of replicas (instances) to scale to for the Inference Endpoint.scale_to_zero_timeoutzFThe duration in minutes before an inactive endpoint is scaled to zero.c                 C   sz   t |d}z|j| |||||||||	|
||d}W n ty6 } ztd|  tj|jjd|d}~ww t| dS )zUpdate an existing endpoint.r   )r(   r   r1   r+   r<   r)   r,   r-   r.   r=   r>   r?   r   zUpdate failed: r   N)	r   Zupdate_inference_endpointr   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   update   s.   
C
r@   Fyesz--yeszSkip confirmation prompts.c              
   C   s   |st d|  d}|| krt d t jddt|d}z
|j| ||d W n tyF } zt d|  t j|jjd|d	}~ww t d
|  d d	S )z)Delete an Inference Endpoint permanently.zDelete endpoint 'z'? Type the name to confirm.zAborted.r   r   r   r8   zDelete failed: Nz	Deleted 'z'.)	r   promptr   r!   r   Zdelete_inference_endpointr   r"   r#   )r(   r   rA   r   Zconfirmationr$   r%   r   r   r   delete  s   

rC   c              
   C   r7   )zPause an Inference Endpoint.r   r8   zPause failed: r   N)	r   Zpause_inference_endpointr   r   r   r!   r"   r#   r   r9   r   r   r   pause:  r;   rD   fail_if_already_runningz--fail-if-already-runningzWIf `True`, the method will raise an error if the Inference Endpoint is already running.c              
   C   sj   t |d}z|j| ||| d}W n ty. } ztd|  tj|jjd|d}~ww t| 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   rE   r   r$   r   r%   r   r   r   resumeK  s   

rF   c              
   C   r7   )z$Scale an Inference Endpoint to zero.r   r8   zScale To Zero failed: r   N)	r   Z scale_to_zero_inference_endpointr   r   r   r!   r"   r#   r   r9   r   r   r   scale_to_zerog  r;   rG   )NN)N)NNNNNNNNNNNN)NFN)$__doc__r   typingr   r   r   Z$huggingface_hub._inference_endpointsr   Zhuggingface_hub.errorsr   Z
_cli_utilsr   r   r	   Zie_cliZcatalog_appstrZArgumentZNameArgOptionZNamespaceOptr   commandr&   r'   r2   r5   Z	add_typerr:   intr@   boolrC   rD   rF   rG   r   r   r   r   <module>   sz   



. &-.45
I		

	!'-39?@Y
