Skip to content

Commit

Permalink
feat: add server response
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlo411 committed Aug 16, 2023
1 parent 0190e50 commit 4b017cb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions static/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ fetch( "/api/model?" + new URLSearchParams({

// Inject results into page
document.getElementById("pred-val").innerHTML = modelPrediction.prediction ?? "ERROR"
document.getElementById("code-response").innerHTML = JSON.stringify(modelPrediction, null, 4)
document.querySelectorAll('pre code').forEach((el) => {
hljs.highlightElement(el);
});
} catch (error) {
document.getElementById("pred-val").innerHTML = "ERROR"
}
Expand Down Expand Up @@ -229,6 +233,20 @@ fetch( "/api/model?" + new URLSearchParams({
initResultTable()
}
renderResultTable();

let formatedResponse = rawResponse;
let formatedPreds = {
"1": rawResponse.prediction[1],
"2": rawResponse.prediction[2],
"3": rawResponse.prediction[3],
"last": "val"
}
formatedResponse.prediction = formatedPreds
document.getElementById("code-response").innerHTML = JSON.stringify(formatedResponse, null, 4)
.replace('"last": "val"', "<...>")
document.querySelectorAll('pre code').forEach((el) => {
hljs.highlightElement(el);
});
} catch {
document.getElementById("pred-val").innerHTML = "ERROR"
}
Expand Down
4 changes: 4 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ <h2>Requests</h2>
</div>
</div>
</div>
<div class="container" id="Responses">
<h2>Server Response</h2>
<pre><code id="code-response" class="language-json"></code></pre>
</div>
</body>
</html>

0 comments on commit 4b017cb

Please sign in to comment.