
    {-j9%                     D   d dl 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mZ dd	lmZ dd
lmZmZ ddlmZ ddl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" 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, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z? dd l@mAZA dd!lBmCZC dd"lDmEZE dd#lFmGZG dd$lHmIZImJZJ dd%lKmLZL dd&lMmNZN dd'lOmPZP dd(lQmRZR dd)lSmTZT dd*lUmVZV d+eWd,eWfd-ZXd.eWd,eeWef         fd/ZY	 d>d0d0d0d0d0d0d0d1d.eeW         d2eeeWef                  d3eeW         d4eeW         d5eeeWef                  d6ee         d7eeZ         d8eeeeWef         ef                  d9ed,efd:Z[d2ed,efd;Z\d2ed,efd<Z]d2ed,efd=Z^d0S )?    )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)TextToSpeechPipeline)TSAnomalyDetPipeline)TSClsPipeline)TSFcPipeline)VideoClassificationPipeline)VideoDetectionPipelinepipeline_namereturnc                     t          t                    j        j        j        dz  |  dz                                  }t          |                                          sdS |S )a  
    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)r6   pipeline_paths     d/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddlex/inference/pipelines/__init__.pyget_pipeline_pathr@   <   sh     	X$+
	
!
!
!	" gii	 
 %%'' t    pipelinec                     |                      d          s:|                      d          s%t          |           }|t          d|  d          n| }t          |          }|S )a  
    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.ymlr9   NzThe pipeline (zC) does not exist! Please use a pipeline name or a config file path!)endswithr@   	Exceptionr
   )rB   r>   configs      r?   load_pipeline_configrG   P   s     f%% !):):7)C)C !)(33 nnnn   !
 !-((FMrA   NrF   deviceengineengine_config	pp_optionuse_hpip
hpi_configrF   rI   rJ   rK   rL   rM   rN   kwargsc                b   | |t          d          |t          |           }nE| /|d         | k    r#t          j        d|d         | |d                    |                                }|d         }	||                    dd          }n|                    dd           ||                    dd          }n|                    dd           ||                    dd          }n||d<   ||                    d	d          }n||d	<    t          j        |	          d|||||||d
|} | S )a,  Create a pipeline instance from a pipeline name or config.


    Args:
        pipeline (Optional[str], optional): Pipeline name (e.g. "OCR", "object_detection") or
            path to a YAML config file. Required if `config` is None.
        config (Optional[Dict[str, Any]], optional): Pipeline configuration dict. If provided,
            `pipeline` name is optional and used only for validation. If both are provided
            and pipeline names differ, `config` takes precedence.
        device (Optional[str], optional): Device to run on (e.g. "gpu", "cpu", "npu:0").
        engine (Optional[str], optional): Inference engine for models in the pipeline.
        engine_config (Optional[Dict[str, Any]], optional): Engine-specific config.
        pp_option (Optional[PaddlePredictorOption], optional): Paddle predictor options.
        use_hpip (Optional[bool], optional): Whether to use HPIP.
        hpi_config (Optional[Union[Dict[str, Any], HPIConfig]], optional): HPIP configuration.

    Returns:
        BasePipeline: The created pipeline instance.
    Nz=Both `pipeline` and `config` cannot be None at the same time.r6   ziThe pipeline name in the config (%r) is different from the specified pipeline name (%r). %r will be used.rM   FrN   rJ   rK   rH    )
ValueErrorrG   r	   warningcopypopgetr   )
rB   rF   rI   rJ   rK   rL   rM   rN   rO   r6   s
             r?   create_pipelinerW   i   s   > FNK
 
 	
 ~%h//F?$;x$G$GO{''	   ?+M::j%00

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



<&&&~Hd++!x

?D99"/.|.. 	#	 	 	 	H OrA   c                     d| v rt          | d                   | d         } t          j        |          |           }|S )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)rR   r   rV   )rF   argsrO   rZ   chat_bots        r?   create_chat_botr]      sK     &(( 78999j!H%x|H%%f--HOrA   c                     d| v rt          | d                   | d         } t          j        |          |           }|S )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_errorrZ   )rR   r   rV   )rF   r[   rO   rZ   	retrievers        r?   create_retrieverra      sM       6)) 89:::j!H+!(++F33IrA   c                     d| v rt          | d                   | d         } t          j        |          |           }|S )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)rR   r   rV   )rF   r[   rO   rd   pes        r?   create_prompt_engineeringrf      sM      F"" 12333{#I	*				*	*6	2	2BIrA   )N)_pathlibr   typingr   r   r   r   utilsr	   utils.configr
   modelsr   r   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/   text_to_speechr0   ts_anomaly_detectionr1   ts_classificationr2   ts_forecastingr3   video_classificationr4   video_detectionr5   strr@   rG   boolrW   r]   ra   rf   rQ   rA   r?   <module>r      s         - - - - - - - - - - - -       ( ( ( ( ( ( 5 5 5 5 5 5 5 5 7 7 7 7 7 7              C C C C C C C C C C 5 5 5 5 5 5 7 7 7 7 7 7 - - - - - - ; ; ; ; ; ; = = = = = = R R R R R R ? ? ? ? ? ? 9 9 9 9 9 9 1 1 1 1 1 1 0 0 0 0 0 0 R R R R R R 5 5 5 5 5 5       F F F F F F L L L L L L - - - - - - D D D D D D D D 9 9 9 9 9 9 ( ( ( ( ( ( D D D D D D 5 5 5 5 5 5 ? ? ? ? ? ? @ @ @ @ @ @ S S S S S S S S 0 0 0 0 0 0 6 6 6 6 6 6 , , , , , , ( ( ( ( ( ( = = = = = = 3 3 3 3 3 3S S    (3 4S>    4 #J (,  .215#=AJ J JsmJ T#s(^$J SM	J
 SMJ DcN+J -.J tnJ tCH~y89:J J J J J JZD h    & 	   . 	     rA   