
    =pj                        S SK Jr  S SKJrJr  S SKJrJrJrJ	r	  SSK
Jr  SSKJr  SSKJrJrJr  SS	KJr   " S
 S\\S9rg)    )annotations)ABCabstractmethod)AnyDictOptionalUnion   )logging)AutoRegisterABCMetaClass   )BasePredictor	HPIConfigPaddlePredictorOption)uses_server_backendc                     ^  \ rS rSrSrSrSSSSSSS.             SU 4S jjjr\S 5       r\	        SS	 j5       r
SS
 jrSS jrS rS rSrU =r$ )BasePipeline   zBase 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engineengine_config	pp_optionuse_hpip
hpi_configc               j   > [         TU ]  5         Xl        X l        X0l        X@l        XPl        X`l        g)av  
Initializes the class with specified parameters.

Args:
    device (Optional[str], optional): The device to use for prediction. Defaults to `None`.
    engine (Optional[str], optional): Inference engine. Defaults to `None`.
    engine_config (Optional[Dict[str, Any]], optional): Engine-specific config. Defaults to `None`.
    pp_option (Optional[PaddlePredictorOption], optional): Paddle predictor options.
        Defaults to `None`.
    use_hpip (bool, optional): Whether to use HPIP. Defaults to `False`.
    hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional): HPIP configuration.
        Defaults to `None`.
N)super__init__r   r   r   r   r   r   )	selfr   r   r   r   r   r   kwargs	__class__s	           \/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/paddlex/inference/pipelines/base.pyr   BasePipeline.__init__$   s/    0 	*" $    c                    [        S5      e)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   s      r!   predictBasePipeline.predictD   s     ""VWWr#   c                   SU ;   a  U R                  SS5      nX3SL 4$ SU ;   nU(       a"  [        U R                  SS5      5      (       a  SnU(       a  gUS4$ )a  Resolve the effective child engine.

Returns a tuple of `(engine, suppress_inherited_engine_defaults)`.

Same-level `engine` has the highest priority. If a child omits `engine`
but specifies another engine selector such as `use_hpip`, or a
`genai_config` that targets a remote server backend, that selector
should beat the inherited parent `engine` and fall back to local
auto-resolution instead of reusing the parent engine defaults.
r   Nr   genai_configT)NTF)getr   )configinherited_engineallow_genaichild_enginehas_local_engine_selectors        r!   _resolve_child_engine"BasePipeline._resolve_child_engineO   se     v!::h5L!555$.&$8!.vzz.$/OPP(,%$&&r#   c                   SU;   a  [        US   5      eUR                  SS5      nU R                  XR                  SS9u  pEUR                  SS5      nU R                  b6  U(       d/  [        U R                  5      nU(       a  UR                  U5        UnUR                  SU R                  5      nUR                  SS5      n	U R                  br  U	=(       d    0 n	[        U R                  S	5      (       a  U R                  R                  SS
9O,[        U R                  [
        5      (       a  U R                  O0 n
0 U
EU	En	SSKJn  [        R                  " SUS   X445        U R                   b  U R                   R#                  5       OSnU" SUS   UU R$                  UUUR                  SS5      UUU	UR                  SS5      S.
UD6$ )z;
Create a model instance based on the given configuration.
model_config_error	model_dirNTr/   r   r   r   
model_dumpexclude_noner   )create_predictorzCreating model: %s
model_name
batch_size   r+   )
r<   r6   r   r   r   r=   r   r   r   r+    )
ValueErrorr,   r2   r   r   dictupdater   r   hasattrr8   
isinstancemodelsr;   r   infor   copyr   )r   r-   r   r6   model_engine"suppress_inherited_engine_defaultsmodel_engine_configmergedr   r   baser;   r   s                r!   create_modelBasePipeline.create_modelj   s     6)V$89::JJ{D1	;?;U;UKKT <V <
8 %jj$?)2T$,,-F"12"(::j$--8ZZd3
??&#)rJ 4??L99 ***=)3DOOT)J)JdooPR 
 0D/J/J- 6,#7"Q	
 .2^^-GDNN'')T	 
l+;;-zz,2!ND9
 
 	
r#   c                p   SU;   a  [        US   5      eSSKJn  U R                  XR                  SS9u  pEUR                  SU R                  5      nUR                  SS5      nU R                  br  U=(       d    0 n[        U R                  S	5      (       a  U R                  R                  S
S9O,[        U R                  [        5      (       a  U R                  O0 n0 UEUEnU" SUU R                  UU(       a  SOU R                  U R                  b  U R                  R                  5       OSUUS.UD6$ )z9
Creates a pipeline based on the provided configuration.
pipeline_config_errorr>   )create_pipelineFr7   r   r   Nr8   Tr9   )r-   r   r   r   r   r   r   r?   )r@    rQ   r2   r   r,   r   r   rC   r8   rD   rA   r   r   r   rG   )	r   r-   r   rQ   pipeline_enginerI   r   r   rL   s	            r!   rQ   BasePipeline.create_pipeline   s,    #f,V$;<==% &&v{{&N 	< ::j$--8ZZd3
??&#)rJ 4??L99 ***=)3DOOT)J)JdooPR 
 0D/J/J 
;;":@R@R040Jt~~**,PT!
 
 	
r#   c                    g )Nr?   )r   s    r!   closeBasePipeline.close   s    r#   c                (    U R                   " U40 UD6$ )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&   s      r!   __call__BasePipeline.__call__   s     ||E,V,,r#   )r   r   r   r   r   r   )r   Optional[str]r   r[   r   zOptional[Dict[str, Any]]r   zOptional[PaddlePredictorOption]r   boolr   z*Optional[Union[Dict[str, Any], HPIConfig]]returnNone)r-   zDict[str, Any]r.   r[   r/   r\   r]   ztuple[Optional[str], bool])r-   r   r]   r   )r-   r   r]   z'BasePipeline')__name__
__module____qualname____firstlineno____doc___BasePipeline__is_baser   r   r(   staticmethodr2   rM   rQ   rV   rY   __static_attributes____classcell__)r    s   @r!   r   r      s     I
 !% $2659AE% % 	%
 0% 3% % ?% 
% %@ X X ''2?'QU'	#' '41
f#
J- -r#   r   )	metaclassN)
__future__r   abcr   r   typingr   r   r   r	   utilsr   utils.subclass_registerr   rE   r   r   r   models.common.genair   r   r?   r#   r!   <module>ro      s3    # # - -  ? D D 5v-3": v-r#   