diff --git a/Dockerfile b/Dockerfile index 9b289dd..bc99086 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,5 +11,5 @@ COPY ./utils /utils COPY ./*.py / RUN chmod +x /app.py -CMD ["/bin/bash", "-c", "/app.py"] +CMD ["/bin/bash", "-c", "/app.py --host='0.0.0.0' --debug=True"] diff --git a/app.py b/app.py index fad078f..2f4b052 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3.8 - +import argparse from flask import Flask, render_template, request from onnx_modifier import onnxModifier + app = Flask(__name__) @app.route('/') @@ -18,12 +19,10 @@ def open_model(): return 'OK', 200 - @app.route('/download', methods=['POST']) def modify_and_download_model(): modify_info = request.get_json() # print(modify_info) - onnx_modifier.reload() # allow downloading for multiple times onnx_modifier.modify(modify_info) @@ -31,6 +30,18 @@ def modify_and_download_model(): return 'OK', 200 +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--host', type=str, default='127.0.0.1', help='the hostname to listen on. Set this to "0.0.0.0" to have the server available externally as well') + parser.add_argument('--port', type=int, default=5000, help='the port of the webserver. Defaults to 5000.') + parser.add_argument('--debug', type=bool, default=True, help='enable or disable debug mode.') + + args = parser.parse_args() + return args + +def main(): + args = parse_args() + app.run(host=args.host, port=args.port, debug=args.debug) + if __name__ == '__main__': - app.debug = True - app.run(host="0.0.0.0") + main() diff --git a/app_desktop.py b/app_desktop.py index 29ac1a5..0bd9861 100644 --- a/app_desktop.py +++ b/app_desktop.py @@ -15,7 +15,7 @@ The following are some notes about How I worked for it. - flaskwebgui github repo: https://github.com/ClimenteA/flaskwebgui b. add some scripts to keep server running while gui is running - see here: https://github.com/ClimenteA/flaskwebgui#install - - I added the code in the index.js (around line 355) + - I added the code in the static/index.js (around line 355) c. Then run: `python app_desktop.py`, the web browser will be automatically lauched for onnx-modifier 2. How to generate excutable files: diff --git a/readme.md b/readme.md index 1d253a3..3cb121e 100644 --- a/readme.md +++ b/readme.md @@ -48,7 +48,7 @@ Then run python app.py ``` -Click the url in the output info generated by flask (`http://127.0.0.1:5000/` for example), then `onnx-modifier` will be launched in the web browser. +Click the url in the output info generated by flask (defaults to `http://127.0.0.1:5000/`), then `onnx-modifier` will be launched in the web browser. ## launch from executable file
diff --git a/readme_zh-CN.md b/readme_zh-CN.md index 0a4432c..5f66f60 100644 --- a/readme_zh-CN.md +++ b/readme_zh-CN.md @@ -53,7 +53,7 @@ - 默认使用Edge浏览器作为运行环境。 > 生成可执行文件的步骤记录在`app_desktop.py`文件中。未来会为其他平台生成可执行文件。 -点击输出中的url(如`http://127.0.0.1:5000/`),即可在浏览器中进入onnx-modifier界面。点击`Open Model...`,上传所需要编辑的模型文件,上传完毕后,网络可视化结构会自动显示。 +点击输出中的url(默认为`http://127.0.0.1:5000/`),即可在浏览器中进入onnx-modifier界面。点击`Open Model...`,上传所需要编辑的模型文件,上传完毕后,网络可视化结构会自动显示。 # 用法