2025-05-04 15:59:02 +08:00
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2025-05-19 03:01:27 +08:00
from paddlex . utils . pipeline_arguments import custom_type
from . . _utils . cli import (
2025-05-04 15:59:02 +08:00
add_simple_inference_args ,
get_subcommand_args ,
perform_simple_inference ,
)
from . base import PaddleXPredictorWrapper , PredictorCLISubcommandExecutor
2025-05-18 21:19:31 +08:00
from paddlex . utils . pipeline_arguments import custom_type
2025-05-04 15:59:02 +08:00
class DocVLM ( PaddleXPredictorWrapper ) :
def __init__ (
self ,
* args ,
* * kwargs ,
) :
self . _extra_init_args = { }
super ( ) . __init__ ( * args , * * kwargs )
@property
def default_model_name ( self ) :
2025-05-19 23:02:27 +08:00
return " PP-DocBee2-3B "
2025-05-04 15:59:02 +08:00
@classmethod
def get_cli_subcommand_executor ( cls ) :
return DocVLMSubcommandExecutor ( )
def _get_extra_paddlex_predictor_init_args ( self ) :
return self . _extra_init_args
class DocVLMSubcommandExecutor ( PredictorCLISubcommandExecutor ) :
2025-05-18 21:19:31 +08:00
input_validator = staticmethod ( custom_type ( dict ) )
2025-05-04 15:59:02 +08:00
@property
def subparser_name ( self ) :
return " doc_vlm "
def _update_subparser ( self , subparser ) :
2025-05-19 03:01:27 +08:00
add_simple_inference_args (
subparser ,
input_help = ' Input dict, e.g. ` { " image " : " https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.png " , " query " : " Recognize this table " }`. ' ,
)
2025-05-04 15:59:02 +08:00
def execute_with_args ( self , args ) :
params = get_subcommand_args ( args )
2025-05-18 21:19:31 +08:00
params [ " input " ] = self . input_validator ( params [ " input " ] )
2025-05-04 15:59:02 +08:00
perform_simple_inference ( DocVLM , params )