
    }-j3G                         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
dZg dZ G d d	e          Z G d
 de          ZdS )   )add_simple_inference_argsget_subcommand_argsperform_simple_inferencestr2bool   )PaddleXPipelineWrapperPipelineCLISubcommandExecutor)create_config_from_structure)v1v1.5v1.6r   )nativezvllm-serverzsglang-serverzfastdeploy-serverzmlx-vlm-serverzllama-cpp-serverc                   
    e Zd Zedddddddddddddddddddddddddddf fd	Zed             Zdddddd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ddddddZd Z		 ddZ
ed             Zd Z xZS )PaddleOCRVLNc                    |t           vrt          d| dt            d          |
$|
t          vrt          d|
 dt           d          t                                                      }|                    d           |                    d           |                    d           || _        || _         t                      j	        d	i | d S )
NzInvalid pipeline version: z. Supported versions are .z/Invalid backend for the VL recognition module: z. Supported values are selfpipeline_versionkwargs )
_AVAILABLE_PIPELINE_VERSIONS
ValueError_SUPPORTED_VL_BACKENDSlocalscopypop_paramsr   super__init__) r   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_urlvl_rec_max_concurrencyvl_rec_api_model_namevl_rec_api_key#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use_seal_recognitionuse_ocr_for_image_blockformat_block_contentmerge_layout_blocksmarkdown_ignore_labels
use_queuesr   params	__class__s                                   a/var/www/html/banglarbhumi/venv/lib/python3.11/site-packages/paddleocr/_pipelines/paddleocr_vl.pyr   zPaddleOCRVL.__init__&   s   @ #???w-=wwXtwww   %.@V*V*V C.  C  Ci  C  C  C   

6

%&&&

8 0""6"""""    c                 ~    | j         dk    rdS | j         dk    rdS | j         dk    rdS t          d| j                    )Nr   zPaddleOCR-VLr   zPaddleOCR-VL-1.5r   zPaddleOCR-VL-1.6zUnknown pipeline version: )r   AssertionErrorr   s    r=   _paddlex_pipeline_namez"PaddleOCRVL._paddlex_pipeline_nameY   sW     D((!>"f,,%%"f,,%% !Ud>S!U!UVVVr>   auto)r1   r2   r3   r4   r5   r6   r"   r#   r$   r%   layout_shape_moder:   prompt_labelr7   repetition_penaltytemperaturetop_p
min_pixels
max_pixelsmax_new_tokensr8   r9   vlm_extra_argsc                     | j         j        |fi d|d|d|d|d|d|d|d|	d	|
d
|d|d|d|d|d|d|d|d|d|d|d|d|d||S Nr1   r2   r3   r4   r5   r6   r"   r#   r$   r%   rD   r:   rE   r7   rF   rG   rH   rI   rJ   rK   r8   r9   rL   )paddlex_pipelinepredictr   inputr1   r2   r3   r4   r5   r6   r"   r#   r$   r%   rD   r:   rE   r7   rF   rG   rH   rI   rJ   rK   r8   r9   rL   r   s                             r=   predict_iterzPaddleOCRVL.predict_iterd   sN   : -t$,
 
 
)E)E
 0/
 "6!5	

 #8"7
 "6!5
 %<$;
 .-
 "z
 !4 3
 &>%=
 0/
 "z
 &
 "6!5
   21!
" $#
$ %%
& "z'
( "z)
* *>+
, !4 3-
. $:#9/
0 *>3
 
 	
r>   c                    t           | j        |fi d|d|d|d|d|d|d|d|	d	|
d
|d|d|d|d|d|d|d|d|d|d|d|d|d||          S rN   )listrS   rQ   s                             r=   rP   zPaddleOCRVL.predict   sZ   : D  -I-I #4"3 &:%9	
 '<&; &:%9 )@(? "2!1 &: %8$7 *B)A #4"3 &: *\ &:%9  $6#5!" (K#$ e%& &:'( &:)*  .~+, %8$7-. (>'=/0  .~3 
 
 	
r>   c                 6    | j                             |          S N)rO   concatenate_markdown_pages)r   markdown_lists     r=   rX   z&PaddleOCRVL.concatenate_markdown_pages   s    $??NNNr>   TFc                 X    t          | j                            ||||                    S )N)merge_tablesrelevel_titlesconcatenate_pages)rU   rO   restructure_pages)r   res_listr[   r\   r]   s        r=   r^   zPaddleOCRVL.restructure_pages   s=     !33)-"3	 4  
 
 	
r>   c                     t                      S rW   ) PaddleOCRVLCLISubcommandExecutor)clss    r=   get_cli_subcommand_executorz'PaddleOCRVL.get_cli_subcommand_executor   s    /111r>   c                 (   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         | j         d         | j         d          | j         d!         | j         d"         | j         d#         | j         d$         | j         d%         | j         d&         d'}t          |          S )(Nz9SubPipelines.DocPreprocessor.use_doc_orientation_classifyr1   z.SubPipelines.DocPreprocessor.use_doc_unwarpingr2   use_doc_preprocessorr3   r4   r7   r8   r9   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'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r5   r6   )z-SubModules.VLRecognition.genai_config.backendz0SubModules.VLRecognition.genai_config.server_urlz5SubModules.VLRecognition.genai_config.max_concurrencyz>SubModules.VLRecognition.genai_config.client_kwargs.model_namez;SubModules.VLRecognition.genai_config.client_kwargs.api_keyzISubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_namezHSubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_dirz?SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_namez>SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_dirr5   r6   )r   r
   )r   	STRUCTUREs     r=   _get_paddlex_config_overridesz)PaddleOCRVL._get_paddlex_config_overrides   sS   <
G.J<
 =dl#?	<
 #DL1O$P %1|/0<
 #DL1G$H<
 $T\2I%J<
 #DL1G$H<
 "4<0E#F<
 %dl3K&L<
 $,|4<
 4T\-6<
$ 3DL,5%<
* 3DLAS4T+<
, 4T\,5O-<
. =dl%?/<
4 B4<*D5<
: 24<@S3T;<
< 1$,?Q2R=<
> >B\ > AE#A FJ\(F OSl'O LP< L Z^Ye5Z Y]Xd4Y PT|*P OSl)O %)L1G$H'+|4M'Nw<
 <
 <
	z ,I666r>   )TTF)__name__
__module____qualname___DEFAULT_PIPELINE_VERSIONr   propertyrB   rS   rP   rX   r^   classmethodrc   rg   __classcell__)r<   s   @r=   r   r   %   s        3$(#' !%#",0+/!% $%)!"! $! #;1# 1# 1# 1# 1# 1#f W W XW &*!"! $ !% ! #57
 7
 7
 7
 7
z &*!"! $ !% ! #59
 9
 9
 9
 9
vO O O SX

 

 

 

 2 2 [2>7 >7 >7 >7 >7 >7 >7r>   r   c                   0    e Zd Zed             Zd Zd ZdS )ra   c                     dS )N
doc_parserr   rA   s    r=   subparser_namez/PaddleOCRVLCLISubcommandExecutor.subparser_name-  s    |r>   c                 r   t          |           |                    dt          t          t                     |                    dt          d           |                    dt          d           |                    dt
          d	           |                    d
t          d           |                    dt
          d           |                    dt          d           |                    dt          d           |                    dt          d           |                    dt          dt                     |                    dt          d           |                    dt          d           |                    dt          d           |                    dt          d           |                    dt          d            |                    d!t          d"           |                    d#t          d$           |                    d%t          d&           |                    d't          d(           |                    d)t          d*           |                    d+t          d,           |                    d-t          d.           |                    d/t          d0           |                    d1t          d2           |                    d3t          d4           |                    d5t          d6           |                    d7t          d8d9:           |                    d;t          d<           |                    d=t          d>d?@           |                    dAt          dB           |                    dCt
          dD           |                    dEt
          dF           |                    dGt
          dH           |                    dIt          dJ           |                    dKt          dL           |                    dMt          dN           d S )ONz--pipeline_version)typedefaultchoicesz--layout_detection_model_namez"Name of the layout analysis model.)rt   helpz--layout_detection_model_dirz,Path to the layout analysis model directory.z--layout_thresholdz.Score threshold for the layout analysis model.z--layout_nmsz&Whether to use NMS in layout analysis.z--layout_unclip_ratioz*Expansion coefficient for layout analysis.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.)rt   rw   rv   z--vl_rec_server_urlz-Server URL used by the VL recognition module.z--vl_rec_max_concurrencyz,Maximum concurrency for making VLM requests.z--vl_rec_api_model_namezModel name for the VLM server.z--vl_rec_api_keyzAPI key for the VLM server.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 analysis.z--use_chart_recognitionz!Whether to use chart recognition.z--use_seal_recognitionz Whether to use seal recognition.z--use_ocr_for_image_blockz$Whether to use OCR for image blocks.z--format_block_contentz,Whether to format block content to Markdown.z--merge_layout_blockszWhether to merge layout blocks.z--markdown_ignore_labels+z3List of layout labels to ignore in Markdown output.)rt   nargsrw   z--use_queuesz2Whether to use queues for asynchronous processing.z--layout_shape_moderC   zMode for layout shape.)rt   ru   rw   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.z--max_new_tokensz.Maximum number of tokens generated by the VLM.)	r   add_argumentstrrk   r   floatr   r   int)r   	subparsers     r=   _update_subparserz2PaddleOCRVLCLISubcommandExecutor._update_subparser1  s   !),,, -0	 	 	
 	
 	
 	+5 	 	
 	
 	

 	*? 	 	
 	
 	

 	 A 	 	
 	
 	

 	9 	 	
 	
 	

 	#= 	 	
 	
 	

 	(4 	 	
 	
 	
 	!4 	 	
 	
 	

 	 > 	 	
 	
 	

 	=*	 	 	
 	
 	
 	!@ 	 	
 	
 	

 	&? 	 	
 	
 	

 	%1 	 	
 	
 	

 	. 	 	
 	
 	
 	3O 	 	
 	
 	

 	2Y 	 	
 	
 	

 	(: 	 	
 	
 	

 	'? 	 	
 	
 	
 	,L 	 	
 	
 	

 	!7 	 	
 	
 	

 	$2 	 	
 	
 	

 	%4 	 	
 	
 	

 	$3 	 	
 	
 	

 	'7 	 	
 	
 	

 	$? 	 	
 	
 	

 	#2 	 	
 	
 	

 	&F	 	 	
 	
 	
 	E 	 	
 	
 	
 	!)	 	 	
 	
 	
 	, 	 	
 	
 	

 	"C 	 	
 	
 	

 	F 	 	
 	
 	

 	@ 	 	
 	
 	

 	F 	 	
 	
 	

 	F 	 	
 	
 	

 	A 	 	
 	
 	
 	
 	
r>   c                 V    t          |          }t          t          |h d           d S )N>   rH   rJ   rI   rG   rE   rK   rD   rF   )predict_param_names)r   r   r   )r   argsr;   s      r=   execute_with_argsz2PaddleOCRVLCLISubcommandExecutor.execute_with_args  sE    $T** 	! 	! 	!	
 	
 	
 	
 	
 	
r>   N)rh   ri   rj   rl   rr   r   r   r   r>   r=   ra   ra   ,  sO          X@
 @
 @
D
 
 
 
 
r>   ra   N)
_utils.clir   r   r   r   baser   r	   utilsr
   r   rk   r   r   ra   r   r>   r=   <module>r      s              H G G G G G G G / / / / / /  655 "    D7 D7 D7 D7 D7( D7 D7 D7NV
 V
 V
 V
 V
'D V
 V
 V
 V
 V
r>   