From 49de3e7f212afd1ac122fe50bc9df9d1ccfee222 Mon Sep 17 00:00:00 2001 From: ZhangGe6 Date: Wed, 7 Sep 2022 23:39:12 +0800 Subject: [PATCH] fix model parsing issue when the model is load in a drag-and-drop way, as refered in https://github.com/ZhangGe6/onnx-modifier/issues/14 --- app.py | 4 +--- static/index.js | 15 +++++++++++++++ static/onnx.js | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 2f4b052..51d3d78 100644 --- a/app.py +++ b/app.py @@ -22,9 +22,7 @@ def open_model(): @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) onnx_modifier.check_and_save_model() @@ -34,7 +32,7 @@ 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.') + parser.add_argument('--debug', type=bool, default=False, help='enable or disable debug mode.') args = parser.parse_args() return args diff --git a/static/index.js b/static/index.js index 3031e19..bf7e8ac 100644 --- a/static/index.js +++ b/static/index.js @@ -344,6 +344,21 @@ host.BrowserHost = class { if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length > 0) { const files = Array.from(e.dataTransfer.files); const file = files.find((file) => this._view.accept(file.name)); + this.upload_filename = file.name; + var form = new FormData(); + form.append('file', file); + + // https://stackoverflow.com/questions/66039996/javascript-fetch-upload-files-to-python-flask-restful + fetch('/open_model', { + method: 'POST', + body: form + }).then(function (response) { + return response.text(); + }).then(function (text) { + console.log('POST response: '); + // Should be 'OK' if everything was successful + console.log(text); + }); if (file) { this._open(file, files); } diff --git a/static/onnx.js b/static/onnx.js index 89eb18e..2e786d7 100644 --- a/static/onnx.js +++ b/static/onnx.js @@ -1094,7 +1094,7 @@ onnx.Tensor = class { } context.limit = 10000; const value = this._decode(context, 0); - console.log(value) + // console.log(value) return onnx.Tensor._stringify(value, '', ' '); }