|
|
|
|
|
function displayFilename() { |
|
|
const fileInput = document.getElementById('file'); |
|
|
const filenameLabel = document.getElementById('filename'); |
|
|
|
|
|
if (fileInput && fileInput.files.length > 0) { |
|
|
let fileName = fileInput.files[0].name; |
|
|
const maxLength = 20; |
|
|
|
|
|
if (fileName.length > maxLength) { |
|
|
const start = fileName.substring(0, 10); |
|
|
const end = fileName.substring(fileName.length - 7); |
|
|
fileName = `${start}...${end}`; |
|
|
} |
|
|
if(filenameLabel) { |
|
|
filenameLabel.textContent = fileName; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function validateFileType() { |
|
|
const fileInput = document.getElementById('file'); |
|
|
const filePath = fileInput.value; |
|
|
const allowedExtensions = /(\.jpg|\.jpeg|\.png|\.bmp)$/i; |
|
|
|
|
|
if (fileInput && !allowedExtensions.exec(filePath)) { |
|
|
alert('Please upload a valid image file (JPG, JPEG, PNG, BMP).'); |
|
|
fileInput.value = ''; |
|
|
return false; |
|
|
} |
|
|
return true; |
|
|
} |
|
|
|
|
|
|
|
|
document.addEventListener("DOMContentLoaded", function() { |
|
|
|
|
|
|
|
|
const sectionForm = document.getElementById('sectionForm'); |
|
|
const loadingOverlay = document.getElementById('loading'); |
|
|
const fileInput = document.getElementById('file'); |
|
|
const symptomTextArea = document.getElementById('symptomTextArea'); |
|
|
|
|
|
if (sectionForm) { |
|
|
sectionForm.addEventListener('submit', function (event) { |
|
|
|
|
|
if (!fileInput.value) { |
|
|
alert('กรุณาอัปโหลดรูปภาพ'); |
|
|
event.preventDefault(); |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
console.clear(); |
|
|
console.log("============================================="); |
|
|
console.log("🔬 DATA TO BE SENT TO BACKEND (main.py)"); |
|
|
console.log("============================================="); |
|
|
|
|
|
|
|
|
const checkedBoxes = document.querySelectorAll('input[name="checkboxes"]:checked'); |
|
|
const checkboxValues = Array.from(checkedBoxes).map(cb => cb.value); |
|
|
console.log("✅ Checkbox values (name='checkboxes'):", checkboxValues); |
|
|
|
|
|
|
|
|
const textAreaValue = symptomTextArea.value; |
|
|
console.log("📝 Text Area value (name='symptom_text'):", textAreaValue); |
|
|
|
|
|
|
|
|
const modelVersion = document.querySelector('input[name="model_version"]:checked').value; |
|
|
console.log("🤖 Model Version (name='model_version'):", modelVersion); |
|
|
|
|
|
console.log("---------------------------------------------"); |
|
|
console.log("Backend (main.py) จะได้รับข้อมูล 3 ส่วนนี้จากฟอร์ม"); |
|
|
console.log("คุณสามารถนำข้อมูลเหล่านี้ไปสร้างเป็น 'final_prompt' สำหรับ preprocessingwangchan.py ต่อไป"); |
|
|
console.log("============================================="); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loadingOverlay) { |
|
|
loadingOverlay.classList.remove('d-none'); |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
const noSymptomCheckbox = document.getElementById('check6'); |
|
|
const spicyFoodCheckbox = document.getElementById('check4'); |
|
|
const alwaysHurtsCheckbox = document.getElementById('check7'); |
|
|
|
|
|
function manageCheckboxStates() { |
|
|
if (!noSymptomCheckbox || !spicyFoodCheckbox || !alwaysHurtsCheckbox) return; |
|
|
|
|
|
const isAnySymptomChecked = spicyFoodCheckbox.checked || alwaysHurtsCheckbox.checked; |
|
|
|
|
|
noSymptomCheckbox.disabled = isAnySymptomChecked; |
|
|
spicyFoodCheckbox.disabled = noSymptomCheckbox.checked; |
|
|
alwaysHurtsCheckbox.disabled = noSymptomCheckbox.checked; |
|
|
} |
|
|
|
|
|
if (noSymptomCheckbox && spicyFoodCheckbox && alwaysHurtsCheckbox) { |
|
|
[noSymptomCheckbox, spicyFoodCheckbox, alwaysHurtsCheckbox].forEach(checkbox => { |
|
|
checkbox.addEventListener('change', manageCheckboxStates); |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
const resultImageDataElement = document.getElementById('result-image-data'); |
|
|
if (resultImageDataElement) { |
|
|
const imageUrl = resultImageDataElement.getAttribute('data-url'); |
|
|
|
|
|
if (imageUrl) { |
|
|
const outputModalElement = document.getElementById('outputModal'); |
|
|
if (outputModalElement) { |
|
|
const outputModal = new bootstrap.Modal(outputModalElement); |
|
|
outputModal.show(); |
|
|
if (loadingOverlay) { |
|
|
loadingOverlay.classList.add('d-none'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (fileInput) { |
|
|
fileInput.addEventListener('change', function() { |
|
|
if (!this.value) return; |
|
|
const allowedExtensions = /(\.jpg|\.jpeg|\.png|\.bmp)$/i; |
|
|
if (!allowedExtensions.exec(this.value)) { |
|
|
alert('กรุณาอัปโหลดไฟล์รูปภาพที่ถูกต้อง (JPG, JPEG, PNG, BMP)'); |
|
|
this.value = ''; |
|
|
} |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
manageCheckboxStates(); |
|
|
|
|
|
const resultTrigger = document.getElementById('result-data-trigger'); |
|
|
if (resultTrigger) { |
|
|
const outputModalElement = document.getElementById('outputModal'); |
|
|
if (outputModalElement) { |
|
|
const outputModal = new bootstrap.Modal(outputModalElement); |
|
|
outputModal.show(); |
|
|
if (loadingOverlay) { |
|
|
loadingOverlay.classList.add('d-none'); |
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
|
|
|
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); |
|
|
const tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { |
|
|
return new bootstrap.Tooltip(tooltipTriggerEl); |
|
|
}); |