add argparse module for custom configs, as refered in https://github.com/ZhangGe6/onnx-modifier/issues/15

1123
ZhangGe6 3 years ago
parent 58e5bb85ee
commit 8795a9a2ba

@ -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"]

@ -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()

@ -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:

@ -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
<details>

@ -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...`,上传所需要编辑的模型文件,上传完毕后,网络可视化结构会自动显示。
# 用法

Loading…
Cancel
Save