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

1123
ZhangGe6 3 years ago
parent 8795a9a2ba
commit 49de3e7f21

@ -22,9 +22,7 @@ def open_model():
@app.route('/download', methods=['POST']) @app.route('/download', methods=['POST'])
def modify_and_download_model(): def modify_and_download_model():
modify_info = request.get_json() modify_info = request.get_json()
# print(modify_info)
onnx_modifier.reload() # allow downloading for multiple times onnx_modifier.reload() # allow downloading for multiple times
onnx_modifier.modify(modify_info) onnx_modifier.modify(modify_info)
onnx_modifier.check_and_save_model() onnx_modifier.check_and_save_model()
@ -34,7 +32,7 @@ def parse_args():
parser = argparse.ArgumentParser() 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('--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('--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() args = parser.parse_args()
return args return args

@ -344,6 +344,21 @@ host.BrowserHost = class {
if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length > 0) { if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length > 0) {
const files = Array.from(e.dataTransfer.files); const files = Array.from(e.dataTransfer.files);
const file = files.find((file) => this._view.accept(file.name)); 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) { if (file) {
this._open(file, files); this._open(file, files);
} }

@ -1094,7 +1094,7 @@ onnx.Tensor = class {
} }
context.limit = 10000; context.limit = 10000;
const value = this._decode(context, 0); const value = this._decode(context, 0);
console.log(value) // console.log(value)
return onnx.Tensor._stringify(value, '', ' '); return onnx.Tensor._stringify(value, '', ' ');
} }

Loading…
Cancel
Save