提交 d6901933 编写于 作者: J Jiawei Wang

fix web service config

上级 ec6fa1ad
......@@ -22,7 +22,55 @@ from paddle_serving_app.reader import Div, Normalize, Transpose
from paddle_serving_app.reader import DBPostProcess, FilterBoxes, GetRotateCropImage, SortedBoxes
_LOGGER = logging.getLogger()
import yaml
from argparse import ArgumentParser,RawDescriptionHelpFormatter
class ArgsParser(ArgumentParser):
def __init__(self):
super(ArgsParser, self).__init__(
formatter_class=RawDescriptionHelpFormatter)
self.add_argument("-c", "--config", help="configuration file to use")
self.add_argument(
"-o", "--opt", nargs='+', help="set configuration options")
def parse_args(self, argv=None):
args = super(ArgsParser, self).parse_args(argv)
assert args.config is not None, \
"Please specify --config=configure_file_path."
args.conf_dict = self._parse_opt(args.opt, args.config)
return args
def _parse_helper(self, v):
if v.isnumeric():
if "." in v:
v = float(v)
else:
v = int(v)
elif v == "True" or v == "False":
v = (v == "True")
return v
def _parse_opt(self, opts, conf_path):
f = open(conf_path)
config = yaml.load(f, Loader=yaml.Loader)
if not opts:
return config
for s in opts:
s = s.strip()
k, v = s.split('=')
v = self._parse_helper(v)
print(k,v, type(v))
cur = config
parent = cur
for kk in k.split("."):
if kk not in cur:
cur[kk] = {}
parent = cur
cur = cur[kk]
else:
parent = cur
cur = cur[kk]
parent[k.split(".")[-1]] = v
return config
class DetOp(Op):
def init_op(self):
......@@ -176,5 +224,6 @@ class OcrService(WebService):
ocr_service = OcrService(name="ocr")
ocr_service.prepare_pipeline_config("config.yml")
FLAGS = ArgsParser().parse_args()
ocr_service.prepare_pipeline_config(yml_dict=FLAGS.conf_dict)
ocr_service.run_service()
......@@ -50,7 +50,7 @@ class WebService(object):
def get_pipeline_response(self, read_op):
return None
def prepare_pipeline_config(self, yaml_file):
def prepare_pipeline_config(self, yml_file=None, yml_dict=None):
# build dag
read_op = pipeline.RequestOp()
last_op = self.get_pipeline_response(read_op)
......@@ -60,7 +60,7 @@ class WebService(object):
"`get_pipeline_response`.")
response_op = pipeline.ResponseOp(input_ops=[last_op])
self._server.set_response_op(response_op)
self._server.prepare_server(yaml_file)
self._server.prepare_server(yml_file=yml_file, yml_dict=yml_dict)
def run_service(self):
self._server.run_server()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册