in src/js/app.js [89:142]
async function submitInference() {
try {
//================================================
// Validate the user inputs:
validateUserInputs();
//================================================
// Remove any spaces from the endpointNameSelect that can happen from copy and paste.
let epName = endpointNameSelect.value.replace(/ /g, '');
// Update the text output div
inferenceText.innerHTML = `Image Selected: ${imageFileSelect.files[0].name}<br />`;
inferenceText.innerHTML += `Sagemaker Endpoint: ${epName}<br />`;
// Get the inference classes the user entered into a list.
classMap = [];
for (let i = 0; i <= classCnt; i++) {
classMap[i] = $(`#inference-class-${i}`).val();
}
inferenceText.innerHTML += `Inference Classes: ${JSON.stringify(classMap)}<br />`;
inferenceText.innerHTML += `Sending the image for inference to the Sagemaker Endpoint......<br />`;
// Post the request
// TODO: If image source is very large can cause long delay, add option to scale image down before POST'ing
let apiInit = {
body: {
endpoint: epName,
region: regionSelect.value,
imageBase64: originalImage.src
}
// headers: {} // OPTIONAL
}
let response = await API.post(apiName, inferenceApiPath, apiInit);
if (!response.statusCode) {
throw Error("An unknown error occured")
} else if (response.statusCode !== 200) {
throw Error(response.error_message);
}
// if no error, get the predictions and process.
predictions = response.predictions;
// Makes prediction vaues more readable and display to UI
inferenceText.innerHTML += getPredictionHtmlPrettyPrint();
applyPredictionsToImage();
} catch (err) {
inferenceText.innerHTML += `ERROR: An error occured:<br />${err}`;
console.log(err, err.stack);
}
}