o
    yqi                     @   s|   d dl mZmZ d dlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ G d
d deedZdS )    )ABCabstractmethod)AnyDictOptionalUnion   )logging)AutoRegisterABCMetaClass   )BasePredictor)	HPIConfig)PaddlePredictorOptionc                       s   e Zd ZdZdZ				ddedededee	e
eef ef  d	df
 fd
dZedd Zde
d	efddZde
fddZdd Zdd Z  ZS )BasePipelinezBase class for all pipelines.

    This class serves as a foundation for creating various pipelines.
    It includes common attributes and methods that are shared among all
    pipeline implementations.
    TNFdevice	pp_optionuse_hpip
hpi_configreturnc                    s&   t    || _|| _|| _|| _dS )ai  
        Initializes the class with specified parameters.

        Args:
            device (str, optional): The device to use for prediction. Defaults to None.
            pp_option (PaddlePredictorOption, optional): The options for PaddlePredictor. Defaults to None.
            use_hpip (bool, optional): Whether to use the high-performance
                inference plugin (HPIP) by default. Defaults to False.
            hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional):
                The default high-performance inference configuration dictionary.
                Defaults to None.
        N)super__init__r   r   r   r   )selfr   r   r   r   argskwargs	__class__ g/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddlex/inference/pipelines/base.pyr   #   s
   

zBasePipeline.__init__c                 K   s   t d)z
        Declaration of an abstract method. Subclasses are expected to
        provide a concrete implementation of predict.
        Args:
            input: The input data to predict.
            **kwargs: Additional keyword arguments.
        z2The method `predict` has not been implemented yet.)NotImplementedErrorr   inputr   r   r   r   predict>   s   	zBasePipeline.predictconfigc           
      K   s   d|v r
t |d |dd}|d| j}|dd}| jdur-|p%i }i | j|}|dd}ddlm} td	|d
 |f | jdurN| j	 }nd}|d|d
 || j
|dd||||d|}	|	S )a.  
        Create a model instance based on the given configuration.

        Args:
            config (Dict): A dictionary containing configuration settings.
            **kwargs: The model arguments that needed to be pass.

        Returns:
            BasePredictor: An instance of the model.
        Zmodel_config_error	model_dirNr   r   genai_configr   )create_predictorzCreating model: %s
model_name
batch_size   )r&   r#   r   r'   r   r   r   r$   r   )
ValueErrorgetr   r    r%   r	   infor   copyr   )
r   r"   r   r#   r   r   r$   r%   r   modelr   r   r   create_modelI   s6   


	zBasePipeline.create_modelc                 C   s   d|v r
t |d ddlm} |d| j}|dd}| jdur-|p%i }i | j|}||| j| jdur;| j n| j||d}|S )z
        Creates a pipeline based on the provided configuration.

        Args:
            config (Dict): A dictionary containing the pipeline configuration.

        Returns:
            BasePipeline: An instance of the created pipeline.
        Zpipeline_config_errorr(   )create_pipeliner   r   N)r"   r   r   r   r   )	r)   r+   r0   r*   r   r   r   r   r-   )r   r"   r0   r   r   Zpipeliner   r   r   r0   w   s    

	zBasePipeline.create_pipelinec                 C   s   d S )Nr   )r   r   r   r   close   s   zBasePipeline.closec                 K   s   | j |fi |S )a<  
        Calls the predict method with the given input and keyword arguments.

        Args:
            input: The input data to be predicted.
            **kwargs: Additional keyword arguments to be passed to the predict method.

        Returns:
            The prediction result from the predict method.
        )r!   r   r   r   r   __call__   s   zBasePipeline.__call__)NNFN)__name__
__module____qualname____doc__Z_BasePipeline__is_basestrr   boolr   r   r   r   r   r   r   r!   r   r/   r0   r1   r2   __classcell__r   r   r   r   r      s0    

. r   )	metaclassN)abcr   r   typingr   r   r   r   utilsr	   Zutils.subclass_registerr
   modelsr   Z	utils.hpir   Zutils.pp_optionr   r   r   r   r   r   <module>   s   