Loading server.py +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ def get_script(): @app.route('/predict', methods=["GET"]) def predict(): json = request.get_json() print(json) message = json["message"] return message # just for debugging, for now... TODO integrate the code with ml.py to get a response Loading web/js/main.js +37 −5 Original line number Diff line number Diff line // todo fix this to actually send the message data function getPrediction() { var url = "http://localhost:8080" var endpoint = "/predict" var data = JSON.stringify({ "message": "Hi" }); var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log(this.responseText); } }); xhr.open("GET", "http://localhost:8080/predict"); xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("User-Agent", "PostmanRuntime/7.19.0"); xhr.setRequestHeader("Accept", "*/*"); xhr.setRequestHeader("Cache-Control", "no-cache"); xhr.setRequestHeader("Postman-Token", "25701512-a7b7-46d3-b614-d82adfe63972,89b19c6f-e712-4c75-9485-f81c5d2b9d3c"); xhr.setRequestHeader("Host", "localhost:8080"); xhr.setRequestHeader("Accept-Encoding", "gzip, deflate"); xhr.setRequestHeader("Content-Length", "20"); xhr.setRequestHeader("Connection", "keep-alive"); xhr.setRequestHeader("cache-control", "no-cache"); xhr.send(data); /* var url = "http://localhost:8080"; var endpoint = "/predict"; var http = new XMLHttpRequest(); var data = JSON.stringify({ "message": document.getElementById("message").value }); http.open("GET", url + endpoint, true); Loading @@ -18,12 +50,12 @@ function getPrediction() { // JSON -> JS obj replyObj = JSON.parse(replyString); // change the prediction label document.getElementById("prediction").innerText = replyObj.prediction; // signifies that we need a string called prediction from the backend } else { console.log("Error getting prediction from the backend server. (Is it running?)"); } } http.send(data); */ } // todo fix this to actually send the message data Loading Loading
server.py +1 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ def get_script(): @app.route('/predict', methods=["GET"]) def predict(): json = request.get_json() print(json) message = json["message"] return message # just for debugging, for now... TODO integrate the code with ml.py to get a response Loading
web/js/main.js +37 −5 Original line number Diff line number Diff line // todo fix this to actually send the message data function getPrediction() { var url = "http://localhost:8080" var endpoint = "/predict" var data = JSON.stringify({ "message": "Hi" }); var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function () { if (this.readyState === 4) { console.log(this.responseText); } }); xhr.open("GET", "http://localhost:8080/predict"); xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("User-Agent", "PostmanRuntime/7.19.0"); xhr.setRequestHeader("Accept", "*/*"); xhr.setRequestHeader("Cache-Control", "no-cache"); xhr.setRequestHeader("Postman-Token", "25701512-a7b7-46d3-b614-d82adfe63972,89b19c6f-e712-4c75-9485-f81c5d2b9d3c"); xhr.setRequestHeader("Host", "localhost:8080"); xhr.setRequestHeader("Accept-Encoding", "gzip, deflate"); xhr.setRequestHeader("Content-Length", "20"); xhr.setRequestHeader("Connection", "keep-alive"); xhr.setRequestHeader("cache-control", "no-cache"); xhr.send(data); /* var url = "http://localhost:8080"; var endpoint = "/predict"; var http = new XMLHttpRequest(); var data = JSON.stringify({ "message": document.getElementById("message").value }); http.open("GET", url + endpoint, true); Loading @@ -18,12 +50,12 @@ function getPrediction() { // JSON -> JS obj replyObj = JSON.parse(replyString); // change the prediction label document.getElementById("prediction").innerText = replyObj.prediction; // signifies that we need a string called prediction from the backend } else { console.log("Error getting prediction from the backend server. (Is it running?)"); } } http.send(data); */ } // todo fix this to actually send the message data Loading