let labels = []; let dataValues = []; //fungsi tombol clear data function clearImage() { document.getElementById("upload_image").value = ""; $("#result").empty(); $("#penjelasan").hide(); $("#penjelasan").empty(); $("#hasilDeteksi").hide(); $("#pie").hide(); // clearChartData(); // Tambahkan pemanggilan AJAX untuk menghapus gambar $.ajax({ url: "/delete_image", type: "POST", success: function (response) { console.log(response); }, error: function (error) { console.error(error); }, }); } function getLink(prediction) { if (prediction === "GIANT") { return "/giant"; } else if (prediction === "LEUKOSIT") { return "/leukosit"; } else if (prediction === "NORMAL") { return "/normal"; } } //Cropping $(document).ready(function () { var $modal = $("#modal"); var image = document.getElementById("sample_image"); var cropper; $("#upload_image").change(function (event) { var files = event.target.files; var done = function (url) { image.src = url; $modal.modal("show"); }; if (files && files.length > 0) { reader = new FileReader(); reader.onload = function (event) { done(reader.result); }; reader.readAsDataURL(files[0]); } }); //halaman modal image crop $modal .on("shown.bs.modal", function () { cropper = new Cropper(image, { aspectRatio: 1, viewMode: 3, preview: ".preview", minCropBoxWidth: 100, // Menetapkan lebar minimum crop box menjadi 100 piksel minCropBoxHeight: 100, // Menetapkan tinggi minimum crop box menjadi 100 piksel maxCropBoxWidth: 100, // Menetapkan lebar maksimum crop box menjadi 100 piksel maxCropBoxHeight: 100, // Menetapkan tinggi maksimum crop box menjadi 100 piksel }); }) .on("hidden.bs.modal", function () { cropper.destroy(); cropper = null; }); $("#crop").click(function () { canvas = cropper.getCroppedCanvas({ width: 224, height: 224, }); canvas.toBlob(function (blob) { var reader = new FileReader(); reader.onloadend = function () { var base64data = reader.result.split(",")[1]; while (base64data.length % 4 !== 0) { base64data += "="; } //hasil deteksi $.ajax({ url: "/submit", method: "POST", data: { image: base64data }, success: function (data) { $modal.modal("hide"); $("#uploaded_image").attr("src", data.img_path); var label = data.label; var highest_probability = data.highest_probability; $("#hasilDeteksi").show(); $("#result").empty(); $("#result").append(`
Greatest Probability: ${highest_probability.toFixed(2)}%
The system identifies that the selected object belongs to the class ${label}. For a full explanation, you can click the following button