Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yavuzKomecoglu/2146977a86e4b5ca2907fc95929c525e to your computer and use it in GitHub Desktop.
Save yavuzKomecoglu/2146977a86e4b5ca2907fc95929c525e to your computer and use it in GitHub Desktop.
$('#upload-file-btn').click(function () {
$('.loader').show();
$("#results").html('');
var form_data = new FormData($('#upload-file')[0]);
$.ajax({
type: 'POST',
url: '/predict',
data: form_data,
contentType: false,
cache: false,
processData: false,
async: false,
success: function (data) {
console.log(data.success);
$('.loader').hide();
$.each(data.predictions, function (i, item) {
console.log(item);
label = item["label"];
prob = item["probability"].toFixed(2);
percent = prob * 100;
$("#results").append('<label>' + percent + '% ' + label + '</label><div class="progress"><div class="progress-bar" role="progressbar" aria-valuenow="' + percent + '" aria-valuemin="0" aria-valuemax="100" style="width:' + percent + '%"></div></div>');
});
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment