o
    !i                     @   sl   d dl 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
 dZG dd	 d	e jd
ZG dd deZdS )    N)create_predictor)DependencyError   )CLISubcommandExecutor)add_common_cli_optsparse_common_argsprepare_common_init_argsFc                       sp   e Zd Zddd fdd
Zeejdd Zdd Zd	d
 Z	dd Z
eejdd Zdd Zdd Z  ZS )PaddleXPredictorWrapperN
model_name	model_dirc                   s@   t    |d ur|n| j| _|| _t|td| _|  | _	d S )N)default_enable_hpi)
super__init__default_model_name_model_name
_model_dirr   _DEFAULT_ENABLE_HPI_common_args_create_paddlex_predictorpaddlex_predictor)selfr   r   Zcommon_args	__class__ b/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/paddleocr/_models/base.pyr      s   
z PaddleXPredictorWrapper.__init__c                 C      t NNotImplementedErrorr   r   r   r   r   0      z*PaddleXPredictorWrapper.default_model_namec                 O   s   | j j|i |S r   )r   predict)r   argskwargsr   r   r   predict_iter5   s   z$PaddleXPredictorWrapper.predict_iterc                 O   s   t | j|i |}|S r   )listr%   )r   r#   r$   resultr   r   r   r"   8   s   zPaddleXPredictorWrapper.predictc                 C   s   | j   d S r   )r   closer    r   r   r   r(   <   s   zPaddleXPredictorWrapper.closec                 C   r   r   r   )clsr   r   r   get_cli_subcommand_executor?   r!   z3PaddleXPredictorWrapper.get_cli_subcommand_executorc                 C   s   i S r   r   r    r   r   r   &_get_extra_paddlex_predictor_init_argsD   s   z>PaddleXPredictorWrapper._get_extra_paddlex_predictor_init_argsc              
   C   s\   t | j| j}i |  |}ztd| j| jd|W S  ty- } ztd|d }~ww )Nr
   zA dependency error occurred during predictor creation. Please refer to the installation documentation to ensure all required dependencies are installed.r   )r   r   r   r+   r   r   r   RuntimeError)r   r$   er   r   r   r   G   s    z1PaddleXPredictorWrapper._create_paddlex_predictor)__name__
__module____qualname__r   propertyabcabstractmethodr   r%   r"   r(   classmethodr*   r+   r   __classcell__r   r   r   r   r	      s    r	   )	metaclassc                   @   s4   e Zd Zeejdd Zdd Zejdd ZdS )PredictorCLISubcommandExecutorc                 C   r   r   r   r    r   r   r   subparser_nameV   r!   z-PredictorCLISubcommandExecutor.subparser_namec                 C   sJ   |j | jd}| | |jdtdd |jdtdd t|tdd |S )	N)namez--model_namezName of the model.)typehelpz--model_dirz$Directory where the model is stored.F)r   Zallow_multiple_devices)
add_parserr8   _update_subparseradd_argumentstrr   r   )r   Z
subparsers	subparserr   r   r   add_subparser[   s   
z,PredictorCLISubcommandExecutor.add_subparserc                 C   r   r   r   )r   r@   r   r   r   r=   i   s   z0PredictorCLISubcommandExecutor._update_subparserN)	r.   r/   r0   r1   r2   r3   r8   rA   r=   r   r   r   r   r7   U   s    r7   )r2   Zpaddlexr   Zpaddlex.utils.depsr   Z	_abstractr   r   r   r   r   r   ABCMetar	   r7   r   r   r   r   <module>   s   7