o
    {qi3                     @   s`   d dl mZmZmZmZ ddlmZmZ ddlm	Z	 g dZ
G dd deZG dd	 d	eZd
S )   )add_simple_inference_argsget_subcommand_argsperform_simple_inferencestr2bool   )PaddleXPipelineWrapperPipelineCLISubcommandExecutor)create_config_from_structure)nativezvllm-serverzsglang-serverc                       s   e Zd Z																				d fdd	Zedd ZdddddddddddddddddddZdddddddddddddddddd	d
Zdd Ze	dd Z
dd Z  ZS )PaddleOCRVLNc                    s`   |	d ur|	t vrtd|	 dt  dt  }|d |d || _t jdi | d S )Nz/Invalid backend for the VL recognition module: z. Supported values are .selfkwargs )_SUPPORTED_VL_BACKENDS
ValueErrorlocalscopypop_paramssuper__init__)r   layout_detection_model_namelayout_detection_model_dirlayout_threshold
layout_nmslayout_unclip_ratiolayout_merge_bboxes_modevl_rec_model_namevl_rec_model_dirvl_rec_backendvl_rec_server_urlZvl_rec_max_concurrency#doc_orientation_classify_model_name"doc_orientation_classify_model_dirdoc_unwarping_model_namedoc_unwarping_model_diruse_doc_orientation_classifyuse_doc_unwarpinguse_layout_detectionuse_chart_recognitionformat_block_contentr   params	__class__r   h/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddleocr/_pipelines/paddleocr_vl.pyr      s   


zPaddleOCRVL.__init__c                 C      dS )NzPaddleOCR-VLr   r   r   r   r.   _paddlex_pipeline_nameA      z"PaddleOCRVL._paddlex_pipeline_name)r&   r'   r(   r)   r   r   r   r   
use_queuesprompt_labelr*   repetition_penaltytemperaturetop_p
min_pixels
max_pixelsc                K   st   | j j|fi d|d|d|d|d|d|d|d|	d	|
d
|d|d|d|d|d|d||S Nr&   r'   r(   r)   r   r   r   r   r3   r4   r*   r5   r6   r7   r8   r9   )paddlex_pipelinepredictr   inputr&   r'   r(   r)   r   r   r   r   r3   r4   r*   r5   r6   r7   r8   r9   r   r   r   r.   predict_iterE   sH   	
zPaddleOCRVL.predict_iterc                K   sv   t | j|fi d|d|d|d|d|d|d|d|	d	|
d
|d|d|d|d|d|d||S r:   )listr?   r=   r   r   r.   r<   p   sL   	
zPaddleOCRVL.predictc                 C   s   | j |S N)r;   concatenate_markdown_pages)r   Zmarkdown_listr   r   r.   rB      s   z&PaddleOCRVL.concatenate_markdown_pagesc                 C   s   t  S rA   ) PaddleOCRVLCLISubcommandExecutor)clsr   r   r.   get_cli_subcommand_executor   s   z'PaddleOCRVL.get_cli_subcommand_executorc                 C   s   i d| j d d| j d d| j d p| j d d| j d d| j d d| j d d	| j d
 d| j d d| j d d| j d d| j d d| j d d| j d d| j d d| j d d| j d d| j d | j d | j d  | j d! d"}t|S )#Nz9SubPipelines.DocPreprocessor.use_doc_orientation_classifyr&   z.SubPipelines.DocPreprocessor.use_doc_unwarpingr'   Zuse_doc_preprocessorr(   r)   r*   z%SubModules.LayoutDetection.model_namer   z$SubModules.LayoutDetection.model_dirr   z$SubModules.LayoutDetection.thresholdr   z%SubModules.LayoutDetection.layout_nmsr   z.SubModules.LayoutDetection.layout_unclip_ratior   z3SubModules.LayoutDetection.layout_merge_bboxes_moder   z#SubModules.VLRecognition.model_namer   z"SubModules.VLRecognition.model_dirr   z-SubModules.VLRecognition.genai_config.backendr    z0SubModules.VLRecognition.genai_config.server_urlr!   zISubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_namer"   r#   r$   r%   )zHSubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_dirz?SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_namez>SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_dir)r   r	   )r   Z	STRUCTUREr   r   r.   _get_paddlex_config_overrides   s   
	






"%/z)PaddleOCRVL._get_paddlex_config_overrides)NNNNNNNNNNNNNNNNNNNN)__name__
__module____qualname__r   propertyr1   r?   r<   rB   classmethodrE   rF   __classcell__r   r   r,   r.   r      s|    $
/-
r   c                   @   s(   e Zd Zedd Zdd Zdd ZdS )rC   c                 C   r/   )NZ
doc_parserr   r0   r   r   r.   subparser_name   r2   z/PaddleOCRVLCLISubcommandExecutor.subparser_namec                 C   s  t | |jdtdd |jdtdd |jdtdd |jdtd	d |jd
tdd |jdtdd |jdtdd |jdtdd |jdtdtd |jdtdd |jdtdd |jdtdd |jdtdd |jdtdd |jdtd d |jd!td"d |jd#td$d |jd%td&d |jd'td(d |jd)td*d |jd+td,d |jd-td.d |jd/td0d |jd1td2d |jd3td4d |jd5td6d |jd7td8d d S )9Nz--layout_detection_model_namez#Name of the layout detection model.)typehelpz--layout_detection_model_dirz-Path to the layout detection model directory.z--layout_thresholdz/Score threshold for the layout detection model.z--layout_nmsz'Whether to use NMS in layout detection.z--layout_unclip_ratioz+Expansion coefficient for layout detection.z--layout_merge_bboxes_modez!Overlapping box filtering method.z--vl_rec_model_namez!Name of the VL recognition model.z--vl_rec_model_dirz+Path to the VL recognition model directory.z--vl_rec_backendz*Backend used by the VL recognition module.)rN   rO   choicesz--vl_rec_server_urlz-Server URL used by the VL recognition module.z--vl_rec_max_concurrencyz,Maximum concurrency for making VLM requests.z%--doc_orientation_classify_model_namez<Name of the document image orientation classification model.z$--doc_orientation_classify_model_dirzFPath to the document image orientation classification model directory.z--doc_unwarping_model_namez'Name of the text image unwarping model.z--doc_unwarping_model_dirz,Path to the image unwarping model directory.z--use_doc_orientation_classifyz9Whether to use document image orientation classification.z--use_doc_unwarpingz$Whether to use text image unwarping.z--use_layout_detectionz Whether to use layout detection.z--use_chart_recognitionz!Whether to use chart recognition.z--format_block_contentz,Whether to format block content to Markdown.z--use_queuesz2Whether to use queues for asynchronous processing.z--prompt_labelzPrompt label for the VLM.z--repetition_penaltyz0Repetition penalty used in sampling for the VLM.z--temperaturez3Temperature parameter used in sampling for the VLM.z--top_pz-Top-p parameter used in sampling for the VLM.z--min_pixelsz3Minimum pixels for image preprocessing for the VLM.z--max_pixelsz3Maximum pixels for image preprocessing for the VLM.)r   add_argumentstrfloatr   r   int)r   Z	subparserr   r   r.   _update_subparser   s  
z2PaddleOCRVLCLISubcommandExecutor._update_subparserc                 C   s   t |}tt|h dd d S )N>   r5   r4   r8   r7   r3   r9   r6   )Zpredict_param_names)r   r   r   )r   argsr+   r   r   r.   execute_with_argsk  s   
z2PaddleOCRVLCLISubcommandExecutor.execute_with_argsN)rG   rH   rI   rJ   rM   rU   rW   r   r   r   r.   rC      s    
 rC   N)Z
_utils.clir   r   r   r   baser   r   utilsr	   r   r   rC   r   r   r   r.   <module>   s    <