Loading server.py +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ def predict(): print(json) # message = json["message"] # return message # just for debugging, for now... TODO integrate the code with ml.py to get a response return return "hi" # TODO hopefully it's obvious that these functions need to be implemented @app.route('/correctPrediction', methods=["POST"]) Loading web/js/main.js +23 −25 Original line number Diff line number Diff line Loading @@ -6,31 +6,29 @@ function getPrediction() { message: "Hi" }); var url = "http://localhost:8080"; var endpoint = "/predict"; var url = "http://localhost:8080" var endpoint = "/predict" var replyObj var http = new XMLHttpRequest(); http.open("GET", url + endpoint, true); // set content header to turn a 500 error into a 400 error http.setRequestHeader('Content-type', 'application/json'); http.onreadystatechange = function () { var DONE = 4; // 4 means that the request is done var OK = 200; // 200 means a successful return if (http.readyState == DONE && http.status == OK && http.responseText) { // JSON string replyString = http.responseText; // JSON -> JS obj replyObj = JSON.parse(replyString); // JSON -> JS object //replyObj = JSON.parse(replyString); console.log(replyString) // change the prediction label document.getElementById("prediction").innerText = replyObj.prediction; // signifies that we need a string called prediction from the backend } } http.send(data); http.send(); } // todo fix this to actually send the message data Loading Loading
server.py +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ def predict(): print(json) # message = json["message"] # return message # just for debugging, for now... TODO integrate the code with ml.py to get a response return return "hi" # TODO hopefully it's obvious that these functions need to be implemented @app.route('/correctPrediction', methods=["POST"]) Loading
web/js/main.js +23 −25 Original line number Diff line number Diff line Loading @@ -6,31 +6,29 @@ function getPrediction() { message: "Hi" }); var url = "http://localhost:8080"; var endpoint = "/predict"; var url = "http://localhost:8080" var endpoint = "/predict" var replyObj var http = new XMLHttpRequest(); http.open("GET", url + endpoint, true); // set content header to turn a 500 error into a 400 error http.setRequestHeader('Content-type', 'application/json'); http.onreadystatechange = function () { var DONE = 4; // 4 means that the request is done var OK = 200; // 200 means a successful return if (http.readyState == DONE && http.status == OK && http.responseText) { // JSON string replyString = http.responseText; // JSON -> JS obj replyObj = JSON.parse(replyString); // JSON -> JS object //replyObj = JSON.parse(replyString); console.log(replyString) // change the prediction label document.getElementById("prediction").innerText = replyObj.prediction; // signifies that we need a string called prediction from the backend } } http.send(data); http.send(); } // todo fix this to actually send the message data Loading