Skip to content

Instantly share code, notes, and snippets.

@rizalespe
Last active January 24, 2019 06:44
Show Gist options
  • Save rizalespe/17bb29b2b400c11b2748e9531e8eeb22 to your computer and use it in GitHub Desktop.
Save rizalespe/17bb29b2b400c11b2748e9531e8eeb22 to your computer and use it in GitHub Desktop.
<body>
<input type='file' onchange="resnetPredict(this);" />
</body>
<script>
function resnetPredict(input) {
if (input.files && input.files[0]) {
$('#images_show').show();
var reader = new FileReader();
reader.onload = function (e) {
$('#images_show')
.attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
if (input.files && input.files[0]) {
var file = input.files[0];
var formData = new FormData();
formData.append('image', file);
$.ajax({
url: "http://godal.sys.cs.tut.ac.jp:5000/predict_resnet",
type: "post",
data: formData,
processData: false, contentType: false,
cache: false,
success: function(reponse) {
table = "<table class='table table-bordered'><tr><td>Label</td><td>Probability</td></tr>";
if(reponse) {
for(var i =0;i < reponse["predictions"].length;i++)
{
var item = reponse["predictions"][i];
table += "<tr><td>"+item["label"]+"</td><td>"+item["probability"]+"</td></tr>";
}
table += "</table>";
$("#contentResult").html(table);
} else {
alert('Erreur');
}
}
});
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment