pltnhan07's picture
upload
96794d4
<!doctype html>
<html>
<head>
<title>Skin Lesion Screening</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, sans-serif;
margin: 40px;
background-color: #f9f9f9;
}
.container {
max-width: 500px;
margin: auto;
background: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
text-align: center;
}
input, select, button {
width: 100%;
padding: 10px;
margin: 10px 0;
font-size: 1em;
}
button {
background-color: #007BFF;
border: none;
color: white;
cursor: pointer;
border-radius: 4px;
}
button:hover {
background-color: #0056b3;
}
.result {
margin-top: 20px;
font-size: 1.2em;
color: #333;
white-space: pre-line;
}
</style>
</head>
<body>
<div class="container">
<h1>Skin Lesion Screening</h1>
<form id="upload-form">
<!-- Image File Input -->
<label for="file">Upload Image:</label>
<input type="file" id="file" accept="image/*" capture="camera" required>
<!-- Metadata: Age -->
<label for="age">Age:</label>
<input type="number" id="age" placeholder="Enter your age" required>
<!-- Metadata: Gender -->
<label for="gender">Gender:</label>
<select id="gender" required>
<option value="" disabled selected>Select your gender</option>
<option value="0">Male</option>
<option value="1">Female</option>
<option value="2">Other</option>
</select>
<!-- Metadata: Skin Cancer History -->
<label for="cancerHistory">History of Skin Cancer:</label>
<select id="cancerHistory" required>
<option value="" disabled selected>Do you have a history of skin cancer?</option>
<option value="0">No</option>
<option value="1">Yes</option>
</select>
<button type="submit">Analyze</button>
</form>
<div id="result" class="result"></div>
</div>
<script>
document.getElementById('upload-form').addEventListener('submit', async function(e) {
e.preventDefault();
// Get the inputs
const fileInput = document.getElementById('file');
const ageInput = document.getElementById('age');
const genderInput = document.getElementById('gender');
const cancerHistoryInput = document.getElementById('cancerHistory');
if (!fileInput.files.length) {
alert("Please select an image file.");
return;
}
// Create a FormData object and append file and metadata
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('age', ageInput.value);
formData.append('gender', genderInput.value);
formData.append('cancer_history', cancerHistoryInput.value);
// Replace this URL with your actual Cloud Function endpoint URL
const functionUrl = 'https://us-central1-skincancerscreening.cloudfunctions.net/predict';
// Send POST request to the backend
try {
const response = await fetch(functionUrl, {
method: 'POST',
body: formData
});
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
document.getElementById('result').innerText =
'Predicted Class: ' + data.predicted_class + '\nConfidence: ' + (data.confidence * 100).toFixed(2) + '%';
} catch (error) {
document.getElementById('result').innerText = 'Error: ' + error;
}
});
</script>
</body>
</html>