Skip to content

Instantly share code, notes, and snippets.

@MattKovtun
Created July 26, 2018 13:04
Show Gist options
  • Save MattKovtun/a56f10c9be13322e1eef37df0d5a86ac to your computer and use it in GitHub Desktop.
Save MattKovtun/a56f10c9be13322e1eef37df0d5a86ac to your computer and use it in GitHub Desktop.
let model;
const modelURL = 'http://localhost:5000/model';
const preview = document.getElementById("preview");
const predictButton = document.getElementById("predict");
const clearButton = document.getElementById("clear");
const numberOfFiles = document.getElementById("number-of-files");
const fileInput = document.getElementById('file');
const predict = async (modelURL) => {
if (!model) model = await tf.loadModel(modelURL);
const files = fileInput.files;
[...files].map(async (img) => {
const data = new FormData();
data.append('file', img);
const processedImage = await fetch("/api/prepare",
{
method: 'POST',
body: data
}).then(response => {
return response.json();
}).then(result => {
return tf.tensor2d(result['image']);
});
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment