未验证 提交 686cf212 编写于 作者: C chenjian 提交者: GitHub

Optimize for better compatibility (#1254)

* Optimize for better compatibility

* load api dynamically
上级 96f4c9c2
...@@ -140,7 +140,7 @@ Parameter details: ...@@ -140,7 +140,7 @@ Parameter details:
| --language | The language of the VisualDL panel. Language can be specified as 'en' or 'zh', and the default is the language used by the browser. | | --language | The language of the VisualDL panel. Language can be specified as 'en' or 'zh', and the default is the language used by the browser. |
| --public-path | The URL path of the VisualDL panel. The default path is '/app', meaning that the access address is 'http://<host>:<port>/app'. | | --public-path | The URL path of the VisualDL panel. The default path is '/app', meaning that the access address is 'http://<host>:<port>/app'. |
| --api-only | Decide whether or not to provide only API. If this parameter is set, VisualDL will only provides API service without displaying the web page, and the API address is 'http://<host>:<port>/<public_path>/api'. Additionally, If the public_path parameter is not specified, the default address is 'http://<host>:<port>/api'. | | --api-only | Decide whether or not to provide only API. If this parameter is set, VisualDL will only provides API service without displaying the web page, and the API address is 'http://<host>:<port>/<public_path>/api'. Additionally, If the public_path parameter is not specified, the default address is 'http://<host>:<port>/api'. |
| --component_tabs | Decide which components are presented in page, currently support 15 components, i.e. 'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'. If this parameter is set, only specified components will be presented. If not set, and specify --logdir parameter, only components with data in vdlrecords log are presented. If both --component_tabs and --logdir are not set, only present 'static_graph', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client' components by default | | --component_tabs | Decide which components are presented in page, currently support 15 components, i.e. 'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'. If this parameter is set, only specified components will be presented. If not set, and specify --logdir parameter, only components with data in vdlrecords log are presented. If both --component_tabs and --logdir are not set, only present 'static_graph' by default |
To visualize the log file generated in the previous step, developers can launch the panel through the command: To visualize the log file generated in the previous step, developers can launch the panel through the command:
...@@ -177,7 +177,7 @@ The interface parameters are as follows: ...@@ -177,7 +177,7 @@ The interface parameters are as follows:
| public_path | string | The URL path of the VisualDL panel. The default path is '/app', meaning that the access address is 'http://<host>:<port>/app'. | | public_path | string | The URL path of the VisualDL panel. The default path is '/app', meaning that the access address is 'http://<host>:<port>/app'. |
| api_only | boolean | Decide whether or not to provide only API. If this parameter is set, VisualDL will only provides API service without displaying the web page, and the API address is 'http://<host>:<port>/<public_path>/api'. Additionally, If the parameter public_path is not specified, the default address is 'http://<host>:<port>/api'. | | api_only | boolean | Decide whether or not to provide only API. If this parameter is set, VisualDL will only provides API service without displaying the web page, and the API address is 'http://<host>:<port>/<public_path>/api'. Additionally, If the parameter public_path is not specified, the default address is 'http://<host>:<port>/api'. |
| open_browser | boolean | Whether or not to open the browser. If this parameter is set as True, the browser will be openned automatically and VisualDL panel will be launched at the same time. If parameter api_only is specified as True, parameter open_browser can be ignored. | | open_browser | boolean | Whether or not to open the browser. If this parameter is set as True, the browser will be openned automatically and VisualDL panel will be launched at the same time. If parameter api_only is specified as True, parameter open_browser can be ignored. |
| component_tabs | string or list[string_1, string_2, ... , string_n] | Decide which components are presented in page, currently support 15 components, i.e. 'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'. If this parameter is set, only specified components will be presented. If not set, and specify --logdir parameter, only components with data in vdlrecords log are presented. If both --component_tabs and --logdir are not set, only present 'static_graph', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client' components by default | | component_tabs | string or list[string_1, string_2, ... , string_n] | Decide which components are presented in page, currently support 15 components, i.e. 'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'. If this parameter is set, only specified components will be presented. If not set, and specify --logdir parameter, only components with data in vdlrecords log are presented. If both --component_tabs and --logdir are not set, only present 'static_graph' by default |
To visualize the log file generated in the previous step, developers can launch the panel through the command: To visualize the log file generated in the previous step, developers can launch the panel through the command:
......
...@@ -150,7 +150,7 @@ visualdl --logdir <dir_1, dir_2, ... , dir_n> --host <host> --port <port> --cach ...@@ -150,7 +150,7 @@ visualdl --logdir <dir_1, dir_2, ... , dir_n> --host <host> --port <port> --cach
| --language | VisualDL面板语言,可指定为'en'或'zh',默认为浏览器使用语言 | | --language | VisualDL面板语言,可指定为'en'或'zh',默认为浏览器使用语言 |
| --public-path | VisualDL面板URL路径,默认是'/app',即访问地址为'http://&lt;host&gt;:&lt;port&gt;/app' | | --public-path | VisualDL面板URL路径,默认是'/app',即访问地址为'http://&lt;host&gt;:&lt;port&gt;/app' |
| --api-only | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://&lt;host&gt;:&lt;port&gt;/&lt;public_path&gt;/api';若没有设置public_path参数,则默认为'http://&lt;host&gt;:&lt;port&gt;/api' | | --api-only | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://&lt;host&gt;:&lt;port&gt;/&lt;public_path&gt;/api';若没有设置public_path参数,则默认为'http://&lt;host&gt;:&lt;port&gt;/api' |
| --component_tabs | 设定需要显示的组件,当前支持'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'共15个组件。如果设置了此参数,将只展示所指定的组件。如果没有设置此参数,当指定了--logdir参数时候,将会根据日志文件中拥有的数据类型来自动显示相应的组件。当没有指定--logdir参数,默认显示'static_graph', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'这四个名称代表的组件 | | --component_tabs | 设定需要显示的组件,当前支持'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'共15个组件。如果设置了此参数,将只展示所指定的组件。如果没有设置此参数,当指定了--logdir参数时候,将会根据日志文件中拥有的数据类型来自动显示相应的组件。当没有指定--logdir参数,默认显示'static_graph'组件 |
针对上一步生成的日志,启动命令为: 针对上一步生成的日志,启动命令为:
...@@ -189,7 +189,7 @@ visualdl.server.app.run(logdir, ...@@ -189,7 +189,7 @@ visualdl.server.app.run(logdir,
| public_path | string | VisualDL面板URL路径,默认是'/app',即访问地址为'http://&lt;host&gt;:&lt;port&gt;/app' | | public_path | string | VisualDL面板URL路径,默认是'/app',即访问地址为'http://&lt;host&gt;:&lt;port&gt;/app' |
| api_only | boolean | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://&lt;host&gt;:&lt;port&gt;/&lt;public_path&gt;/api';若没有设置public_path参数,则默认为'http://&lt;host&gt;:&lt;port&gt;/api' | | api_only | boolean | 是否只提供API,如果设置此参数,则VisualDL不提供页面展示,只提供API服务,此时API地址为'http://&lt;host&gt;:&lt;port&gt;/&lt;public_path&gt;/api';若没有设置public_path参数,则默认为'http://&lt;host&gt;:&lt;port&gt;/api' |
| open_browser | boolean | 是否打开浏览器,设置为True则在启动后自动打开浏览器并访问VisualDL面板,若设置api_only,则忽略此参数 | | open_browser | boolean | 是否打开浏览器,设置为True则在启动后自动打开浏览器并访问VisualDL面板,若设置api_only,则忽略此参数 |
| --component_tabs | string或list[string_1, string_2, ... , string_n] | 设定需要显示的组件,当前支持'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'共15个组件。如果设置了此参数,将只展示所指定的组件。如果没有设置此参数,当指定了--logdir参数时候,将会根据日志文件中拥有的数据类型来自动显示相应的组件。当没有指定--logdir参数,默认显示'static_graph', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'这四个名称代表的组件 | | --component_tabs | string或list[string_1, string_2, ... , string_n] | 设定需要显示的组件,当前支持'scalar', 'image', 'text', 'embeddings', 'audio', 'histogram', 'hyper_parameters', 'static_graph', 'dynamic_graph', 'pr_curve', 'roc_curve', 'profiler', 'x2paddle', 'fastdeploy_server', 'fastdeploy_client'共15个组件。如果设置了此参数,将只展示所指定的组件。如果没有设置此参数,当指定了--logdir参数时候,将会根据日志文件中拥有的数据类型来自动显示相应的组件。当没有指定--logdir参数,默认显示'static_graph'组件 |
针对上一步生成的日志,我们的启动脚本为: 针对上一步生成的日志,我们的启动脚本为:
......
...@@ -9,10 +9,5 @@ six >= 1.14.0 ...@@ -9,10 +9,5 @@ six >= 1.14.0
matplotlib matplotlib
pandas pandas
packaging packaging
x2paddle >= 1.4.0
paddle2onnx >= 1.0.5
rarfile rarfile
gradio == 3.11.0
tritonclient[all]
psutil psutil
onnx >= 1.6.0
...@@ -417,10 +417,7 @@ def get_component_tabs(*apis, vdl_args, request_args): ...@@ -417,10 +417,7 @@ def get_component_tabs(*apis, vdl_args, request_args):
all_tabs.update(api('component_tabs', request_args)) all_tabs.update(api('component_tabs', request_args))
all_tabs.add('static_graph') all_tabs.add('static_graph')
else: else:
return [ return ['static_graph']
'static_graph', 'x2paddle', 'fastdeploy_server',
'fastdeploy_client'
]
return list(all_tabs) return list(all_tabs)
......
...@@ -36,8 +36,6 @@ from flask_babel import Babel ...@@ -36,8 +36,6 @@ from flask_babel import Babel
import visualdl.server import visualdl.server
from visualdl import __version__ from visualdl import __version__
from visualdl.component.inference.fastdeploy_lib import get_start_arguments from visualdl.component.inference.fastdeploy_lib import get_start_arguments
from visualdl.component.inference.fastdeploy_server import create_fastdeploy_api_call
from visualdl.component.inference.model_convert_server import create_model_convert_api_call
from visualdl.component.profiler.profiler_server import create_profiler_api_call from visualdl.component.profiler.profiler_server import create_profiler_api_call
from visualdl.server.api import create_api_call from visualdl.server.api import create_api_call
from visualdl.server.api import get_component_tabs from visualdl.server.api import get_component_tabs
...@@ -83,323 +81,305 @@ def create_app(args): # noqa: C901 ...@@ -83,323 +81,305 @@ def create_app(args): # noqa: C901
signal.SIGINT, signal.SIG_DFL signal.SIGINT, signal.SIG_DFL
) # we add this to prevent SIGINT not work in multiprocess queue waiting ) # we add this to prevent SIGINT not work in multiprocess queue waiting
babel = Babel(app, locale_selector=get_locale) # noqa:F841 babel = Babel(app, locale_selector=get_locale) # noqa:F841
# Babel api from flask_babel v3.0.0
api_call = create_api_call(args.logdir, args.model, args.cache_timeout)
profiler_api_call = create_profiler_api_call(args.logdir)
inference_api_call = create_model_convert_api_call()
fastdeploy_api_call = create_fastdeploy_api_call()
if args.telemetry: if args.telemetry:
update_util.PbUpdater(args.product).start() update_util.PbUpdater(args.product).start()
public_path = args.public_path public_path = args.public_path
api_path = public_path + '/api' api_path = public_path + '/api'
# Babel api from flask_babel v3.0.0
def append_query_string(url): api_call = create_api_call(args.logdir, args.model, args.cache_timeout)
query_string = '' profiler_api_call = create_profiler_api_call(args.logdir)
if request.query_string: if args.component_tabs is not None:
query_string = '?' + request.query_string.decode() if 'x2paddle' in args.component_tabs:
return url + query_string try:
import x2paddle # noqa F401
if not args.api_only: except Exception:
os.system('pip install x2paddle')
template = Template( os.system('pip install onnx')
os.path.join(server_path, template_file_path), try:
PUBLIC_PATH=public_path, import paddle2onnx # noqa F401
BASE_URI=public_path, except Exception:
API_URL=api_path, os.system('pip install paddle2onnx')
TELEMETRY_ID='63a600296f8a71f576c4806376a9245b' from visualdl.component.inference.model_convert_server import create_model_convert_api_call
if args.telemetry else '', inference_api_call = create_model_convert_api_call()
THEME='' if args.theme is None else args.theme)
@app.route(
@app.route('/') api_path + '/inference/<path:method>', methods=["GET", "POST"])
def base(): def serve_inference_api(method):
return redirect(append_query_string(public_path), code=302) if request.method == 'POST':
data, mimetype, headers = inference_api_call(
@app.route('/favicon.ico') method, request.form)
def favicon(): else:
icon = os.path.join(template_file_path, 'favicon.ico') data, mimetype, headers = inference_api_call(
if os.path.exists(icon): method, request.args)
return send_file(icon) return make_response(
return 'file not found', 404 Response(data, mimetype=mimetype, headers=headers))
@app.route(public_path + '/') if 'fastdeploy_server' in args.component_tabs or 'fastdeploy_client' in args.component_tabs:
def index(): try:
return redirect( import tritonclient # noqa F401
append_query_string(public_path + '/index'), code=302) except Exception:
os.system('pip install tritonclient[all]')
@app.route(public_path + '/<path:filename>') try:
def serve_static(filename): import gradio # noqa F401
is_not_page_request = re.search(r'\..+$', filename) except Exception:
response = template.render( os.system('pip install gradio==3.11.0')
filename if is_not_page_request else 'index.html') from visualdl.component.inference.fastdeploy_server import create_fastdeploy_api_call
if not is_not_page_request: fastdeploy_api_call = create_fastdeploy_api_call()
response.set_cookie(
'vdl_lng', @app.route(
get_locale(), api_path + '/fastdeploy/<path:method>',
path='/', methods=["GET", "POST"])
samesite='Strict', def serve_fastdeploy_api(method):
secure=False, if request.method == 'POST':
httponly=False) data, mimetype, headers = fastdeploy_api_call(
return response method, request.form)
else:
@app.route(api_path + '/<path:method>', methods=["GET", "POST"]) data, mimetype, headers = fastdeploy_api_call(
def serve_api(method): method, request.args)
data, mimetype, headers = api_call(method, request.args) return make_response(
return make_response( Response(data, mimetype=mimetype, headers=headers))
Response(data, mimetype=mimetype, headers=headers))
@app.route(
@app.route(api_path + '/profiler/<path:method>', methods=["GET", "POST"]) api_path + '/fastdeploy/fastdeploy_client',
def serve_profiler_api(method): methods=["GET", "POST"])
data, mimetype, headers = profiler_api_call(method, request.args) def serve_fastdeploy_create_fastdeploy_client():
return make_response(
Response(data, mimetype=mimetype, headers=headers))
@app.route(api_path + '/inference/<path:method>', methods=["GET", "POST"])
def serve_inference_api(method):
if request.method == 'POST':
data, mimetype, headers = inference_api_call(method, request.form)
else:
data, mimetype, headers = inference_api_call(method, request.args)
return make_response(
Response(data, mimetype=mimetype, headers=headers))
@app.route(api_path + '/fastdeploy/<path:method>', methods=["GET", "POST"])
def serve_fastdeploy_api(method):
if request.method == 'POST':
data, mimetype, headers = fastdeploy_api_call(method, request.form)
else:
data, mimetype, headers = fastdeploy_api_call(method, request.args)
return make_response(
Response(data, mimetype=mimetype, headers=headers))
@app.route(
api_path + '/fastdeploy/fastdeploy_client', methods=["GET", "POST"])
def serve_fastdeploy_create_fastdeploy_client():
try:
if request.method == 'POST':
fastdeploy_api_call('create_fastdeploy_client', request.form)
request_args = request.form
else:
fastdeploy_api_call('create_fastdeploy_client', request.args)
request_args = request.args
except Exception as e:
error_msg = '{}'.format(e)
return make_response(error_msg)
args = urllib.parse.urlencode(request_args)
if args:
return redirect(
api_path + "/fastdeploy/fastdeploy_client/app?{}".format(args),
code=302)
return redirect(
api_path + "/fastdeploy/fastdeploy_client/app", code=302)
@app.route(
api_path + "/fastdeploy/fastdeploy_client/<path:path>",
methods=["GET", "POST"])
def request_fastdeploy_create_fastdeploy_client_app(path: str):
'''
Gradio app server url interface. We route urls for gradio app to gradio server.
Args:
path(str): All resource path from gradio server.
Returns:
Any thing from gradio server.
'''
lang = 'zh'
if request.method == 'POST':
if request.mimetype == 'application/json':
request_args = request.json
else:
request_args = request.form.to_dict()
if 'data' in request_args:
lang = request_args['data'][-1]
request_args['lang'] = lang
elif 'lang' in request_args:
lang = request_args['lang']
port = fastdeploy_api_call('create_fastdeploy_client',
request_args)
else:
request_args = request.args.to_dict()
if 'data' in request_args:
lang = request_args['data'][-1]
request_args['lang'] = lang
elif 'lang' in request_args:
lang = request_args['lang']
port = fastdeploy_api_call('create_fastdeploy_client',
request_args)
if path == 'app':
proxy_url = request.url.replace(
request.host_url.rstrip('/') + api_path +
'/fastdeploy/fastdeploy_client/app',
'http://localhost:{}/'.format(port))
else:
proxy_url = request.url.replace(
request.host_url.rstrip('/') + api_path +
'/fastdeploy/fastdeploy_client/',
'http://localhost:{}/'.format(port))
resp = requests.request(
method=request.method,
url=proxy_url,
headers={
key: value
for (key, value) in request.headers if key != 'Host'
},
data=request.get_data(),
cookies=request.cookies,
allow_redirects=False)
if path == 'app':
content = resp.content
if request_args and 'server_id' in request_args:
server_id = request_args.get('server_id')
start_args = get_start_arguments(server_id)
http_port = start_args.get('http-port', '')
metrics_port = start_args.get('metrics-port', '')
model_name = start_args.get('default_model_name', '')
content = content.decode()
try: try:
if request_args.get('lang', 'zh') == 'en': if request.method == 'POST':
server_addr_match = re.search( fastdeploy_api_call('create_fastdeploy_client',
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format( request.form)
json.dumps("server ip", request_args = request.form
ensure_ascii=True).replace( else:
'\\', '\\\\')), content) fastdeploy_api_call('create_fastdeploy_client',
if not server_addr_match or server_addr_match.group( request.args)
0).count('"label"') >= 2: request_args = request.args
server_addr_match = re.search( except Exception as e:
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format( error_msg = '{}'.format(e)
json.dumps("server ip", return make_response(error_msg)
ensure_ascii=True).replace( args = urllib.parse.urlencode(request_args)
'\\', '\\\\')), content)
default_server_addr = server_addr_match.group(0) if args:
if '"value": ""' in default_server_addr: return redirect(
cur_server_addr = default_server_addr.replace( api_path +
'"value": ""', '"value": "localhost"') "/fastdeploy/fastdeploy_client/app?{}".format(args),
else: code=302)
cur_server_addr = default_server_addr.replace( return redirect(
'"value":""', '"value": "localhost"') api_path + "/fastdeploy/fastdeploy_client/app", code=302)
content = content.replace(default_server_addr,
cur_server_addr) @app.route(
http_port_match = re.search( api_path + "/fastdeploy/fastdeploy_client/<path:path>",
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format( methods=["GET", "POST"])
json.dumps("server port", def request_fastdeploy_create_fastdeploy_client_app(path: str):
ensure_ascii=True).replace( '''
'\\', '\\\\')), content) Gradio app server url interface. We route urls for gradio app to gradio server.
if not http_port_match or http_port_match.group(
0).count('"label"') >= 2: Args:
http_port_match = re.search( path(str): All resource path from gradio server.
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps( Returns:
"server port", Any thing from gradio server.
ensure_ascii=True).replace( '''
'\\', '\\\\')), content) lang = 'zh'
default_http_port = http_port_match.group(0) if request.method == 'POST':
if request.mimetype == 'application/json':
if '"value": ""' in default_http_port: request_args = request.json
cur_http_port = default_http_port.replace(
'"value": ""',
'"value": "{}"'.format(http_port))
else:
cur_http_port = default_http_port.replace(
'"value":""',
'"value": "{}"'.format(http_port))
if http_port:
content = content.replace(default_http_port,
cur_http_port)
metrics_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("metrics port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not metrics_port_match or metrics_port_match.group(
0).count('"label"') >= 2:
metrics_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps(
"metrics port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_metrics_port = metrics_port_match.group(0)
if '"value": ""' in default_metrics_port:
cur_metrics_port = default_metrics_port.replace(
'"value": ""',
'"value": "{}"'.format(metrics_port))
else:
cur_metrics_port = default_metrics_port.replace(
'"value":""',
'"value": "{}"'.format(metrics_port))
if metrics_port:
content = content.replace(default_metrics_port,
cur_metrics_port)
model_name_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("model name",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not model_name_match or model_name_match.group(
0).count('"label"') >= 2:
model_name_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps(
"model name",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_model_name = model_name_match.group(0)
if '"value": ""' in default_model_name:
cur_model_name = default_model_name.replace(
'"value": ""',
'"value": "{}"'.format(model_name))
else:
cur_model_name = default_model_name.replace(
'"value":""',
'"value": "{}"'.format(model_name))
if model_name:
content = content.replace(default_model_name,
cur_model_name)
model_version_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format(
json.dumps("model version",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not model_version_match or model_version_match.group(
0).count('"label"') >= 2:
model_version_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps(
"model version",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_model_version = model_version_match.group(0)
if '"value": ""' in default_model_version:
cur_model_version = default_model_version.replace(
'"value": ""', '"value": "{}"'.format('1'))
else:
cur_model_version = default_model_version.replace(
'"value":""', '"value": "{}"'.format('1'))
content = content.replace(default_model_version,
cur_model_version)
else: else:
server_addr_match = re.search( request_args = request.form.to_dict()
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format( if 'data' in request_args:
json.dumps("服务ip", ensure_ascii=True).replace( lang = request_args['data'][-1]
'\\', '\\\\')), content) request_args['lang'] = lang
if not server_addr_match or server_addr_match.group( elif 'lang' in request_args:
0).count('"label"') >= 2: lang = request_args['lang']
server_addr_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format( port = fastdeploy_api_call('create_fastdeploy_client',
json.dumps("服务ip", request_args)
ensure_ascii=True).replace( else:
'\\', '\\\\')), content) request_args = request.args.to_dict()
if not server_addr_match: if 'data' in request_args:
lang = request_args['data'][-1]
request_args['lang'] = lang
elif 'lang' in request_args:
lang = request_args['lang']
port = fastdeploy_api_call('create_fastdeploy_client',
request_args)
if path == 'app':
proxy_url = request.url.replace(
request.host_url.rstrip('/') + api_path +
'/fastdeploy/fastdeploy_client/app',
'http://localhost:{}/'.format(port))
else:
proxy_url = request.url.replace(
request.host_url.rstrip('/') + api_path +
'/fastdeploy/fastdeploy_client/',
'http://localhost:{}/'.format(port))
resp = requests.request(
method=request.method,
url=proxy_url,
headers={
key: value
for (key, value) in request.headers if key != 'Host'
},
data=request.get_data(),
cookies=request.cookies,
allow_redirects=False)
if path == 'app':
content = resp.content
if request_args and 'server_id' in request_args:
server_id = request_args.get('server_id')
start_args = get_start_arguments(server_id)
http_port = start_args.get('http-port', '')
metrics_port = start_args.get('metrics-port', '')
model_name = start_args.get('default_model_name', '')
content = content.decode()
try:
if request_args.get('lang', 'zh') == 'en':
server_addr_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps(
"server ip",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not server_addr_match or server_addr_match.group(
0).count('"label"') >= 2:
server_addr_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"server ip",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_server_addr = server_addr_match.group(
0)
if '"value": ""' in default_server_addr:
cur_server_addr = default_server_addr.replace(
'"value": ""', '"value": "localhost"')
else:
cur_server_addr = default_server_addr.replace(
'"value":""', '"value": "localhost"')
content = content.replace(
default_server_addr, cur_server_addr)
http_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps(
"server port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not http_port_match or http_port_match.group(
0).count('"label"') >= 2:
http_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"server port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_http_port = http_port_match.group(0)
if '"value": ""' in default_http_port:
cur_http_port = default_http_port.replace(
'"value": ""',
'"value": "{}"'.format(http_port))
else:
cur_http_port = default_http_port.replace(
'"value":""',
'"value": "{}"'.format(http_port))
if http_port:
content = content.replace(
default_http_port, cur_http_port)
metrics_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps(
"metrics port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not metrics_port_match or metrics_port_match.group(
0).count('"label"') >= 2:
metrics_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"metrics port",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_metrics_port = metrics_port_match.group(
0)
if '"value": ""' in default_metrics_port:
cur_metrics_port = default_metrics_port.replace(
'"value": ""',
'"value": "{}"'.format(metrics_port))
else:
cur_metrics_port = default_metrics_port.replace(
'"value":""',
'"value": "{}"'.format(metrics_port))
if metrics_port:
content = content.replace(
default_metrics_port, cur_metrics_port)
model_name_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps(
"model name",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not model_name_match or model_name_match.group(
0).count('"label"') >= 2:
model_name_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"model name",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_model_name = model_name_match.group(0)
if '"value": ""' in default_model_name:
cur_model_name = default_model_name.replace(
'"value": ""',
'"value": "{}"'.format(model_name))
else:
cur_model_name = default_model_name.replace(
'"value":""',
'"value": "{}"'.format(model_name))
if model_name:
content = content.replace(
default_model_name, cur_model_name)
model_version_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.
format(
json.dumps(
"model version",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
if not model_version_match or model_version_match.group(
0).count('"label"') >= 2:
model_version_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.
format(
json.dumps(
"model version",
ensure_ascii=True).replace(
'\\', '\\\\')), content)
default_model_version = model_version_match.group(
0)
if '"value": ""' in default_model_version:
cur_model_version = default_model_version.replace(
'"value": ""',
'"value": "{}"'.format('1'))
else:
cur_model_version = default_model_version.replace(
'"value":""',
'"value": "{}"'.format('1'))
content = content.replace(
default_model_version, cur_model_version)
else:
server_addr_match = re.search( server_addr_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'. '"label":\\s*{}.*?"value":\\s*"".*?}}'.
format( format(
json.dumps("服务ip", json.dumps("服务ip",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
if not server_addr_match or server_addr_match.group( if not server_addr_match or server_addr_match.group(
0).count('"label"') >= 2: 0).count('"label"') >= 2:
...@@ -408,37 +388,43 @@ def create_app(args): # noqa: C901 ...@@ -408,37 +388,43 @@ def create_app(args): # noqa: C901
format( format(
json.dumps( json.dumps(
"服务ip", "服务ip",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
if not server_addr_match:
default_server_addr = server_addr_match.group(0) server_addr_match = re.search(
if '"value": ""' in default_server_addr: '"label":\\s*{}.*?"value":\\s*"".*?}}'
cur_server_addr = default_server_addr.replace( .format(
'"value": ""', '"value": "localhost"') json.dumps(
else: "服务ip", ensure_ascii=False
cur_server_addr = default_server_addr.replace( ).replace('\\',
'"value":""', '"value": "localhost"') '\\\\')), content)
content = content.replace(default_server_addr, if not server_addr_match or server_addr_match.group(
cur_server_addr) 0).count('"label"') >= 2:
http_port_match = re.search( server_addr_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format( '"value":\\s*"".*?"label":\\s*{}.*?}}'
json.dumps("推理服务端口", .format(
ensure_ascii=True).replace( json.dumps(
'\\', '\\\\')), content) "服务ip",
if not http_port_match or http_port_match.group( ensure_ascii=False).
0).count('"label"') >= 2: replace('\\',
http_port_match = re.search( '\\\\')), content)
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format(
json.dumps("推理服务端口", default_server_addr = server_addr_match.group(
ensure_ascii=True).replace( 0)
'\\', '\\\\')), content) if '"value": ""' in default_server_addr:
if not http_port_match: cur_server_addr = default_server_addr.replace(
'"value": ""', '"value": "localhost"')
else:
cur_server_addr = default_server_addr.replace(
'"value":""', '"value": "localhost"')
content = content.replace(
default_server_addr, cur_server_addr)
http_port_match = re.search( http_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'. '"label":\\s*{}.*?"value":\\s*"".*?}}'.
format( format(
json.dumps( json.dumps(
"推理服务端口", "推理服务端口",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
if not http_port_match or http_port_match.group( if not http_port_match or http_port_match.group(
0).count('"label"') >= 2: 0).count('"label"') >= 2:
...@@ -447,40 +433,46 @@ def create_app(args): # noqa: C901 ...@@ -447,40 +433,46 @@ def create_app(args): # noqa: C901
format( format(
json.dumps( json.dumps(
"推理服务端口", "推理服务端口",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
default_http_port = http_port_match.group(0) if not http_port_match:
http_port_match = re.search(
if '"value": ""' in default_http_port: '"label":\\s*{}.*?"value":\\s*"".*?}}'
cur_http_port = default_http_port.replace( .format(
'"value": ""', json.dumps(
'"value": "{}"'.format(http_port)) "推理服务端口",
else: ensure_ascii=False).
cur_http_port = default_http_port.replace( replace('\\',
'"value":""', '\\\\')), content)
'"value": "{}"'.format(http_port)) if not http_port_match or http_port_match.group(
if http_port: 0).count('"label"') >= 2:
content = content.replace(default_http_port, http_port_match = re.search(
cur_http_port) '"value":\\s*"".*?"label":\\s*{}.*?}}'
metrics_port_match = re.search( .format(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format( json.dumps(
json.dumps("性能服务端口", "推理服务端口",
ensure_ascii=True).replace( ensure_ascii=False).
'\\', '\\\\')), content) replace('\\',
if not metrics_port_match or metrics_port_match.group( '\\\\')), content)
0).count('"label"') >= 2: default_http_port = http_port_match.group(0)
metrics_port_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format( if '"value": ""' in default_http_port:
json.dumps("性能服务端口", cur_http_port = default_http_port.replace(
ensure_ascii=True).replace( '"value": ""',
'\\', '\\\\')), content) '"value": "{}"'.format(http_port))
if not metrics_port_match: else:
cur_http_port = default_http_port.replace(
'"value":""',
'"value": "{}"'.format(http_port))
if http_port:
content = content.replace(
default_http_port, cur_http_port)
metrics_port_match = re.search( metrics_port_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'. '"label":\\s*{}.*?"value":\\s*"".*?}}'.
format( format(
json.dumps( json.dumps(
"性能服务端口", "性能服务端口",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
if not metrics_port_match or metrics_port_match.group( if not metrics_port_match or metrics_port_match.group(
0).count('"label"') >= 2: 0).count('"label"') >= 2:
...@@ -489,37 +481,45 @@ def create_app(args): # noqa: C901 ...@@ -489,37 +481,45 @@ def create_app(args): # noqa: C901
format( format(
json.dumps( json.dumps(
"性能服务端口", "性能服务端口",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
default_metrics_port = metrics_port_match.group(0) if not metrics_port_match:
if '"value": ""' in default_metrics_port: metrics_port_match = re.search(
cur_metrics_port = default_metrics_port.replace( '"label":\\s*{}.*?"value":\\s*"".*?}}'
'"value": ""', .format(
'"value": "{}"'.format(metrics_port)) json.dumps(
else: "性能服务端口",
cur_metrics_port = default_metrics_port.replace( ensure_ascii=False).
'"value":""', replace('\\',
'"value": "{}"'.format(metrics_port)) '\\\\')), content)
if metrics_port: if not metrics_port_match or metrics_port_match.group(
content = content.replace(default_metrics_port, 0).count('"label"') >= 2:
cur_metrics_port) metrics_port_match = re.search(
model_name_match = re.search( '"value":\\s*"".*?"label":\\s*{}.*?}}'
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format( .format(
json.dumps("模型名称", ensure_ascii=True).replace( json.dumps(
'\\', '\\\\')), content) "性能服务端口",
if not model_name_match or model_name_match.group( ensure_ascii=False).
0).count('"label"') >= 2: replace('\\',
model_name_match = re.search( '\\\\')), content)
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format( default_metrics_port = metrics_port_match.group(
json.dumps("模型名称", 0)
ensure_ascii=True).replace( if '"value": ""' in default_metrics_port:
'\\', '\\\\')), content) cur_metrics_port = default_metrics_port.replace(
if not model_name_match: '"value": ""',
'"value": "{}"'.format(metrics_port))
else:
cur_metrics_port = default_metrics_port.replace(
'"value":""',
'"value": "{}"'.format(metrics_port))
if metrics_port:
content = content.replace(
default_metrics_port, cur_metrics_port)
model_name_match = re.search( model_name_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'. '"label":\\s*{}.*?"value":\\s*"".*?}}'.
format( format(
json.dumps("模型名称", json.dumps("模型名称",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
if not model_name_match or model_name_match.group( if not model_name_match or model_name_match.group(
0).count('"label"') >= 2: 0).count('"label"') >= 2:
...@@ -528,37 +528,43 @@ def create_app(args): # noqa: C901 ...@@ -528,37 +528,43 @@ def create_app(args): # noqa: C901
format( format(
json.dumps( json.dumps(
"模型名称", "模型名称",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
default_model_name = model_name_match.group(0) if not model_name_match:
if '"value": ""' in default_model_name: model_name_match = re.search(
cur_model_name = default_model_name.replace( '"label":\\s*{}.*?"value":\\s*"".*?}}'
'"value": ""', .format(
'"value": "{}"'.format(model_name)) json.dumps(
else: "模型名称", ensure_ascii=False
cur_model_name = default_model_name.replace( ).replace('\\',
'"value":""', '\\\\')), content)
'"value": "{}"'.format(model_name)) if not model_name_match or model_name_match.group(
if model_name: 0).count('"label"') >= 2:
content = content.replace(default_model_name, model_name_match = re.search(
cur_model_name) '"value":\\s*"".*?"label":\\s*{}.*?}}'
model_version_match = re.search( .format(
'"label":\\s*{}.*?"value":\\s*"".*?}}'.format( json.dumps(
json.dumps("模型版本", ensure_ascii=True).replace( "模型名称",
'\\', '\\\\')), content) ensure_ascii=False).
if not model_version_match or model_version_match.group( replace('\\',
0).count('"label"') >= 2: '\\\\')), content)
model_version_match = re.search( default_model_name = model_name_match.group(0)
'"value":\\s*"".*?"label":\\s*{}.*?}}'.format( if '"value": ""' in default_model_name:
json.dumps("模型版本", cur_model_name = default_model_name.replace(
ensure_ascii=True).replace( '"value": ""',
'\\', '\\\\')), content) '"value": "{}"'.format(model_name))
if not model_version_match: else:
cur_model_name = default_model_name.replace(
'"value":""',
'"value": "{}"'.format(model_name))
if model_name:
content = content.replace(
default_model_name, cur_model_name)
model_version_match = re.search( model_version_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'. '"label":\\s*{}.*?"value":\\s*"".*?}}'.
format( format(
json.dumps("模型版本", json.dumps("模型版本",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
if not model_version_match or model_version_match.group( if not model_version_match or model_version_match.group(
0).count('"label"') >= 2: 0).count('"label"') >= 2:
...@@ -567,27 +573,109 @@ def create_app(args): # noqa: C901 ...@@ -567,27 +573,109 @@ def create_app(args): # noqa: C901
format( format(
json.dumps( json.dumps(
"模型版本", "模型版本",
ensure_ascii=False).replace( ensure_ascii=True).replace(
'\\', '\\\\')), content) '\\', '\\\\')), content)
if not model_version_match:
model_version_match = re.search(
'"label":\\s*{}.*?"value":\\s*"".*?}}'
.format(
json.dumps(
"模型版本", ensure_ascii=False
).replace('\\',
'\\\\')), content)
if not model_version_match or model_version_match.group(
0).count('"label"') >= 2:
model_version_match = re.search(
'"value":\\s*"".*?"label":\\s*{}.*?}}'
.format(
json.dumps(
"模型版本",
ensure_ascii=False).
replace('\\',
'\\\\')), content)
default_model_version = model_version_match.group(
0)
if '"value": ""' in default_model_version:
cur_model_version = default_model_version.replace(
'"value": ""',
'"value": "{}"'.format('1'))
else:
cur_model_version = default_model_version.replace(
'"value":""',
'"value": "{}"'.format('1'))
content = content.replace(
default_model_version, cur_model_version)
except Exception:
pass
finally:
content = content.encode()
else:
content = resp.content
headers = [(name, value)
for (name, value) in resp.raw.headers.items()]
response = Response(content, resp.status_code, headers)
return response
def append_query_string(url):
query_string = ''
if request.query_string:
query_string = '?' + request.query_string.decode()
return url + query_string
if not args.api_only:
default_model_version = model_version_match.group(0) template = Template(
if '"value": ""' in default_model_version: os.path.join(server_path, template_file_path),
cur_model_version = default_model_version.replace( PUBLIC_PATH=public_path,
'"value": ""', '"value": "{}"'.format('1')) BASE_URI=public_path,
else: API_URL=api_path,
cur_model_version = default_model_version.replace( TELEMETRY_ID='63a600296f8a71f576c4806376a9245b'
'"value":""', '"value": "{}"'.format('1')) if args.telemetry else '',
content = content.replace(default_model_version, THEME='' if args.theme is None else args.theme)
cur_model_version)
except Exception: @app.route('/')
pass def base():
finally: return redirect(append_query_string(public_path), code=302)
content = content.encode()
else: @app.route('/favicon.ico')
content = resp.content def favicon():
headers = [(name, value) for (name, value) in resp.raw.headers.items()] icon = os.path.join(template_file_path, 'favicon.ico')
response = Response(content, resp.status_code, headers) if os.path.exists(icon):
return response return send_file(icon)
return 'file not found', 404
@app.route(public_path + '/')
def index():
return redirect(
append_query_string(public_path + '/index'), code=302)
@app.route(public_path + '/<path:filename>')
def serve_static(filename):
is_not_page_request = re.search(r'\..+$', filename)
response = template.render(
filename if is_not_page_request else 'index.html')
if not is_not_page_request:
response.set_cookie(
'vdl_lng',
get_locale(),
path='/',
samesite='Strict',
secure=False,
httponly=False)
return response
@app.route(api_path + '/<path:method>', methods=["GET", "POST"])
def serve_api(method):
data, mimetype, headers = api_call(method, request.args)
return make_response(
Response(data, mimetype=mimetype, headers=headers))
@app.route(api_path + '/profiler/<path:method>', methods=["GET", "POST"])
def serve_profiler_api(method):
data, mimetype, headers = profiler_api_call(method, request.args)
return make_response(
Response(data, mimetype=mimetype, headers=headers))
@app.route(api_path + '/component_tabs') @app.route(api_path + '/component_tabs')
def component_tabs(): def component_tabs():
......
...@@ -13,4 +13,4 @@ ...@@ -13,4 +13,4 @@
# limitations under the License. # limitations under the License.
# ======================================================================= # =======================================================================
vdl_version = '2.5.2' vdl_version = '2.5.3'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册