
    9iv$                        S SK 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  SSKJr  S	S
KJr  S	SKJrJr  S	SKJr  S	SKJrJrJr  S	SKJr  S	SKJr  S	SKJr  S	SK J!r!  S	SK"J#r#  S	SK$J%r%  S	SK&J'r'  S	SK(J)r)  S	SK*J+r+  S	SK,J-r-  S	SK.J/r/  S	SK0J1r1  S	SK2J3r3  S	SK4J5r5  S	SK6J7r7  S	SK8J9r9  S	SK:J;r;J<r<  S	SK=J>r>  S	S K?J@r@  S	S!KAJBrB  S	S"KCJDrD  S	S#KEJFrF  S	S$KGJHrH  S	S%KIJJrJJKrK  S	S&KLJMrM  S	S'KNJOrO  S	S(KPJQrQ  S	S)KRJSrS  S	S*KTJUrU  S+\VS,\V4S- jrWS.\VS,\\V\4   4S/ jrX      S<S.\\V   S1\\\V\4      S2\\V   S3\\   S4\\Y   S5\\\\V\4   \4      S6\S7\S,\4S8 jjrZS1\S,\4S9 jr[S1\S,\4S: jr\S1\S,\4S; jr]g0)=    )Path)AnyDictOptionalUnion   )logging)parse_config   )	HPIConfig)PaddlePredictorOption   )AnomalyDetectionPipeline)PedestrianAttributeRecPipelineVehicleAttributeRecPipeline)BasePipeline)BaseChatBaseGeneratePromptBaseRetriever)DocPreprocessorPipeline)DocUnderstandingPipeline)FaceRecPipeline)FormulaRecognitionPipeline)ImageClassificationPipeline)%ImageMultiLabelClassificationPipeline)InstanceSegmentationPipeline)KeypointDetectionPipeline)LayoutParsingPipeline)BEVDet3DPipeline)%MultilingualSpeechRecognitionPipeline)ObjectDetectionPipeline)OCRPipeline)OpenVocabularyDetectionPipeline)"OpenVocabularySegmentationPipeline)PaddleOCRVLPipeline)PP_ChatOCRv3_PipelinePP_ChatOCRv4_Pipeline)PP_DocTranslation_Pipeline)ShiTuV2Pipeline)RotatedObjectDetectionPipeline)SealRecognitionPipeline)SemanticSegmentationPipeline)SmallObjectDetectionPipeline)TableRecognitionPipelineTableRecognitionPipelineV2)TSAnomalyDetPipeline)TSClsPipeline)TSFcPipeline)VideoClassificationPipeline)VideoDetectionPipelinepipeline_namereturnc                     [        [        5      R                  R                  R                  S-  U  S3-  R                  5       n[        U5      R	                  5       (       d  gU$ )z
Get the full path of the pipeline configuration file based on the provided pipeline name.

Args:
    pipeline_name (str): The name of the pipeline.

Returns:
    str: The full path to the pipeline configuration file or None if not found.
zconfigs/pipelines.yamlN)r   __file__parentresolveexists)r5   pipeline_paths     d/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/paddlex/inference/pipelines/__init__.pyget_pipeline_pathr?   <   sa     	X$$++
	O5
!	" gi	 
 %%''    pipelinec                     U R                  S5      (       d4  U R                  S5      (       d  [        U 5      nUc  [        SU  S35      eOU n[        U5      nU$ )z
Load the pipeline configuration.

Args:
    pipeline (str): The name of the pipeline or the path to the config file.

Returns:
    Dict[str, Any]: The parsed pipeline configuration.

Raises:
    Exception: If the config file of pipeline does not exist.
z.ymlr8   zThe pipeline (zC) does not exist! Please use a pipeline name or a config file path!)endswithr?   	Exceptionr
   )rA   r=   configs      r>   load_pipeline_configrF   P   sj     f%%):):7)C)C)(3  
*mn  !
 !-(FMr@   NrE   device	pp_optionuse_hpip
hpi_configargskwargsc           	         U c  Uc  [        S5      eUc  [        U 5      nO;U b(  US   U :w  a  [        R                  " SUS   U US   5        UR	                  5       nUS   nUc  UR                  SS5      nOUR                  SS5        Uc  UR                  SS5      nOUR                  SS5        [        R                  " U5      " UUUUUUS.UD6n U $ )	a  
Create a pipeline instance based on the provided parameters.

If the input parameter config is not provided, it is obtained from the
default config corresponding to the pipeline name.

Args:
    pipeline (Optional[str], optional): The name of the pipeline to
        create, or the path to the config file. Defaults to None.
    config (Optional[Dict[str, Any]], optional): The pipeline configuration.
        Defaults to None.
    device (Optional[str], optional): The device to run the pipeline on.
        Defaults to None.
    pp_option (Optional[PaddlePredictorOption], optional): The options for
        the PaddlePredictor. Defaults to None.
    use_hpip (Optional[bool], optional): Whether to use the high-performance
        inference plugin (HPIP). If set to None, the setting from the
        configuration file or `config` will be used. Defaults to None.
    hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional): The
        high-performance inference configuration dictionary.
        Defaults to None.
    *args: Additional positional arguments.
    **kwargs: Additional keyword arguments.

Returns:
    BasePipeline: The created pipeline instance.
Nz=Both `pipeline` and `config` cannot be None at the same time.r5   ziThe pipeline name in the config (%r) is different from the specified pipeline name (%r). %r will be used.rI   FrJ   )rE   rG   rH   rI   rJ   )
ValueErrorrF   r	   warningcopypopr   get)	rA   rE   rG   rH   rI   rJ   rK   rL   r5   s	            r>   create_pipelinerS   i   s    J FNK
 	
 ~%h/F?$;x$GOO{''	 ?+M::j%0

:t$ZZd3


<&. 
  H Or@   c                 p    SU ;   a  [        U S   5      eU S   n[        R                  " U5      " U 5      nU$ )a  Creates an instance of a chat bot based on the provided configuration.

Args:
    config (Dict): Configuration settings, expected to be a dictionary with at least a 'model_name' key.
    *args: Additional positional arguments. Not used in this function but allowed for future compatibility.
    **kwargs: Additional keyword arguments. Not used in this function but allowed for future compatibility.

Returns:
    BaseChat: An instance of the chat bot class corresponding to the 'model_name' in the config.
chat_bot_config_errorapi_type)rN   r   rR   )rE   rK   rL   rV   chat_bots        r>   create_chat_botrX      s?     &( 7899j!H||H%f-HOr@   c                 p    SU ;   a  [        U S   5      eU S   n[        R                  " U5      " U 5      nU$ )a  
Creates a retriever instance based on the provided configuration.

Args:
    config (Dict): Configuration settings, expected to be a dictionary with at least a 'model_name' key.
    *args: Additional positional arguments. Not used in this function but allowed for future compatibility.
    **kwargs: Additional keyword arguments. Not used in this function but allowed for future compatibility.

Returns:
    BaseRetriever: An instance of a retriever class corresponding to the 'model_name' in the config.
retriever_config_errorrV   )rN   r   rR   )rE   rK   rL   rV   	retrievers        r>   create_retrieverr\      sB       6) 89::j!H!!(+F3Ir@   c                 p    SU ;   a  [        U S   5      eU S   n[        R                  " U5      " U 5      nU$ )a  
Creates a prompt engineering instance based on the provided configuration.

Args:
    config (Dict): Configuration settings, expected to be a dictionary with at least a 'task_type' key.
    *args: Variable length argument list for additional positional arguments.
    **kwargs: Arbitrary keyword arguments.

Returns:
    BaseGeneratePrompt: An instance of a prompt engineering class corresponding to the 'task_type' in the config.
pe_config_error	task_type)rN   r   rR   )rE   rK   rL   r_   pes        r>   create_prompt_engineeringra      sA      F" 1233{#I					*6	2BIr@   )NNNNNN)^pathlibr   typingr   r   r   r   utilsr	   utils.configr
   	utils.hpir   utils.pp_optionr   anomaly_detectionr   attribute_recognitionr   r   baser   
componentsr   r   r   doc_preprocessorr   doc_understandingr   face_recognitionr   formula_recognitionr   image_classificationr   image_multilabel_classificationr   instance_segmentationr   keypoint_detectionr   layout_parsingr   m_3d_bev_detectionr   multilingual_speech_recognitionr    object_detectionr!   ocrr"   open_vocabulary_detectionr#   open_vocabulary_segmentationr$   paddleocr_vlr%   
pp_chatocrr&   r'   pp_doctranslationr(   pp_shitu_v2r)   rotated_object_detectionr*   seal_recognitionr+   semantic_segmentationr,   small_object_detectionr-   table_recognitionr.   r/   ts_anomaly_detectionr0   ts_classificationr1   ts_forecastingr2   video_classificationr3   video_detectionr4   strr?   rF   boolrS   rX   r\   ra    r@   r>   <module>r      s    - -  ( ! 3 7  C C 5 7 - ; = R ? 9 1 0 R 5  F L - D 9 ( D 5 ? @ S 6 , ( = 3S S (3 4S> 4 #'+ 15#=AGsmGT#s(^$G SMG -.	G
 tnG tCH~y89:G G G GTD h & 	. 	r@   