diff --git a/.env.development b/.env.development index acfda19..151dc2e 100644 --- a/.env.development +++ b/.env.development @@ -3,9 +3,9 @@ VITE_APP_PORT = 3000 # 代理前缀 VITE_APP_BASE_API = '/api' -# VITE_APP_API_URL = http://62.234.3.186/mk/ai/api +VITE_APP_API_URL = http://62.234.3.186/mk/ai/api # 线上接口地址 -VITE_APP_API_URL = http://10.5.1.137:8800 +#VITE_APP_API_URL = http://10.5.1.137:8800 # 开发接口地址 # VITE_APP_API_URL = http://localhost:8989 diff --git a/public/onnx/main.js b/public/onnx/main.js index 1321dd4..a88fee9 100644 --- a/public/onnx/main.js +++ b/public/onnx/main.js @@ -1 +1,57 @@ -function init(){var s=location.search;var url="";var onnxModelName="";if(s.indexOf("=")>=0){url=s.substring(s.indexOf("=")+1);if(url.toLocaleLowerCase().indexOf(".onnx")>=0){onnxModelName=url.substring(url.lastIndexOf("/")+1)}else{console.error("使用方法:onnx.html?url=[onnx路径]");return}}else{console.error("使用方法:onnx.html?url=[onnx路径]");return}document.body.title=onnxModelName;var http=new XMLHttpRequest;http.responseType="arraybuffer";http.open("GET",url);http.onload=function(){if(http.status==200){var reader=proto.protobuf.Reader.create(new Uint8Array(http.response));var onnxProtoModel=window.proto.onnx.ModelProto.decode(reader);let{locations,graphs}=window.getExternalLocations(onnxProtoModel);let model=new window.onnx.Model(onnxProtoModel,graphs,new Map);let host=window;let view=new window.View(host);view.start().then(data=>{view.open(model,onnxModelName)}).catch(err=>{console.log(err)});window.mainView=view}};http.send()}function exportImg(file,blob){const element=this.document.createElement("a");element.download=file;element.href=URL.createObjectURL(blob);this.document.body.appendChild(element);element.click();this.document.body.removeChild(element)}function toggleMenu(){let el=document.getElementById("menu");if(el.style.display=="none"){el.style.display="block";updateState()}else{el.style.display="none"}}function doToggle(att){mainView.toggle(att);updateState()}function updateState(){var op=mainView.options;document.getElementById("opAtt").innerText=op.attributes?"Hide Attributes":"Show Attributes";document.getElementById("opWeight").innerText=op.weights?"Hide Weights":"Show Weights";document.getElementById("opName").innerText=op.names?"Hide Names":"Show Names";document.getElementById("opDir").innerText=op.direction=="vertical"?"Show Horizontal":"Show Vertical";document.getElementById("opMouse").innerText=op.mousewheel=="scroll"?"Mouse Wheel: Zoom":"Mouse Wheel: Scroll"}init(); \ No newline at end of file +function init() { + var s = location.search; + var url = ""; + var onnxModelName = ""; + if (s.indexOf("=") >= 0) { + url = s.substring(s.indexOf("=") + 1); + } else { + console.error("使用方法:onnx.html?id=[模型ID]") + return; + } + + document.body.title = onnxModelName; + var accessToken = localStorage.getItem("accessToken"); + var http = new XMLHttpRequest(); + http.responseType = "json" + + http.open('GET', MODELDOWNLOADAPI + `${url}/download`); + http.setRequestHeader("Authorization", accessToken); + http.onload = function () { + if (http.status == 200) { + var reader = proto.protobuf.Reader.create(base64ToUint8Array(http.response.data.file_content)); + var onnxProtoModel = window.proto.onnx.ModelProto.decode(reader); + let { locations, graphs } = window.getExternalLocations(onnxProtoModel); + let model = new window.onnx.Model(onnxProtoModel, graphs, new Map()); + + let host = window; + let view = new window.View(host); + view.start().then((data) => { + view.open(model, onnxModelName); + }).catch((err) => { + console.log(err); + }) + window.mainView = view; + } + }; + http.send(); +} + +function base64ToUint8Array(base64String) { + try { + let padding = '='.repeat((4 - base64String.length % 4) % 4); + let base64 = (base64String + padding) + .replace(/\-/g, '+') + .replace(/_/g, '/'); + let rawData = atob(base64); + let outputArray = new Uint8Array(rawData.length); + for (let i = 0; i < rawData.length; ++i) { + outputArray[i] = rawData.charCodeAt(i); + } + return outputArray; + } + catch (e) { + throw e; + } +} + +init(); \ No newline at end of file diff --git a/public/onnx/onnx.html b/public/onnx/onnx.html index ca8d9df..67fade4 100644 --- a/public/onnx/onnx.html +++ b/public/onnx/onnx.html @@ -2,392 +2,1403 @@
-