205 lines
5.9 KiB
HTML
205 lines
5.9 KiB
HTML
|
|
<!DOCTYPE html>
|
||
|
|
<html lang="en">
|
||
|
|
<head>
|
||
|
|
<meta charset="UTF-8">
|
||
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
|
<title>Object Detection</title>
|
||
|
|
<style>
|
||
|
|
:root {
|
||
|
|
--primary-color: #2563eb;
|
||
|
|
--primary-hover: #1d4ed8;
|
||
|
|
--background-color: #f8fafc;
|
||
|
|
--text-color: #1e293b;
|
||
|
|
--border-color: #e2e8f0;
|
||
|
|
--shadow-color: rgba(0, 0, 0, 0.1);
|
||
|
|
}
|
||
|
|
|
||
|
|
body {
|
||
|
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||
|
|
max-width: 1200px;
|
||
|
|
margin: 0 auto;
|
||
|
|
padding: 40px 20px;
|
||
|
|
background-color: var(--background-color);
|
||
|
|
color: var(--text-color);
|
||
|
|
line-height: 1.5;
|
||
|
|
}
|
||
|
|
|
||
|
|
.container {
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
align-items: center;
|
||
|
|
gap: 40px;
|
||
|
|
}
|
||
|
|
|
||
|
|
h1 {
|
||
|
|
font-size: 2.5rem;
|
||
|
|
font-weight: 700;
|
||
|
|
margin-bottom: 10px;
|
||
|
|
background: linear-gradient(135deg, var(--primary-color), #4f46e5);
|
||
|
|
-webkit-background-clip: text;
|
||
|
|
-webkit-text-fill-color: transparent;
|
||
|
|
}
|
||
|
|
|
||
|
|
.upload-form {
|
||
|
|
width: 100%;
|
||
|
|
max-width: 500px;
|
||
|
|
background: white;
|
||
|
|
padding: 30px;
|
||
|
|
border-radius: 12px;
|
||
|
|
box-shadow: 0 4px 6px var(--shadow-color);
|
||
|
|
}
|
||
|
|
|
||
|
|
.upload-form form {
|
||
|
|
display: flex;
|
||
|
|
flex-direction: column;
|
||
|
|
gap: 20px;
|
||
|
|
}
|
||
|
|
|
||
|
|
input[type="file"] {
|
||
|
|
padding: 15px;
|
||
|
|
border: 2px dashed var(--border-color);
|
||
|
|
border-radius: 8px;
|
||
|
|
cursor: pointer;
|
||
|
|
transition: all 0.3s ease;
|
||
|
|
}
|
||
|
|
|
||
|
|
input[type="file"]:hover {
|
||
|
|
border-color: var(--primary-color);
|
||
|
|
background-color: rgba(37, 99, 235, 0.05);
|
||
|
|
}
|
||
|
|
|
||
|
|
.upload-btn {
|
||
|
|
background-color: var(--primary-color);
|
||
|
|
color: white;
|
||
|
|
padding: 12px 24px;
|
||
|
|
border: none;
|
||
|
|
border-radius: 8px;
|
||
|
|
cursor: pointer;
|
||
|
|
font-weight: 600;
|
||
|
|
font-size: 1rem;
|
||
|
|
transition: all 0.3s ease;
|
||
|
|
}
|
||
|
|
|
||
|
|
.upload-btn:hover {
|
||
|
|
background-color: var(--primary-hover);
|
||
|
|
transform: translateY(-2px);
|
||
|
|
box-shadow: 0 4px 6px var(--shadow-color);
|
||
|
|
}
|
||
|
|
|
||
|
|
.image-container {
|
||
|
|
display: flex;
|
||
|
|
justify-content: center;
|
||
|
|
gap: 40px;
|
||
|
|
width: 100%;
|
||
|
|
margin-top: 20px;
|
||
|
|
flex-wrap: wrap;
|
||
|
|
}
|
||
|
|
|
||
|
|
.image-box {
|
||
|
|
background: white;
|
||
|
|
padding: 20px;
|
||
|
|
border-radius: 12px;
|
||
|
|
box-shadow: 0 4px 6px var(--shadow-color);
|
||
|
|
transition: all 0.3s ease;
|
||
|
|
flex: 1;
|
||
|
|
min-width: 300px;
|
||
|
|
max-width: 500px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.image-box:hover {
|
||
|
|
transform: translateY(-5px);
|
||
|
|
box-shadow: 0 8px 12px var(--shadow-color);
|
||
|
|
}
|
||
|
|
|
||
|
|
.image-box h3 {
|
||
|
|
margin: 0 0 15px 0;
|
||
|
|
color: var(--text-color);
|
||
|
|
font-size: 1.25rem;
|
||
|
|
}
|
||
|
|
|
||
|
|
img {
|
||
|
|
max-width: 100%;
|
||
|
|
max-height: 400px;
|
||
|
|
border-radius: 8px;
|
||
|
|
object-fit: contain;
|
||
|
|
}
|
||
|
|
|
||
|
|
@media (max-width: 768px) {
|
||
|
|
body {
|
||
|
|
padding: 20px 10px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.image-container {
|
||
|
|
flex-direction: column;
|
||
|
|
gap: 20px;
|
||
|
|
}
|
||
|
|
|
||
|
|
.image-box {
|
||
|
|
width: 100%;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
</style>
|
||
|
|
</head>
|
||
|
|
<body>
|
||
|
|
<div class="container">
|
||
|
|
<h1>Object Detection</h1>
|
||
|
|
<div class="upload-form">
|
||
|
|
<form id="uploadForm" enctype="multipart/form-data">
|
||
|
|
<input type="file" id="imageInput" accept="image/*" required>
|
||
|
|
<button type="submit" class="upload-btn">Upload and Detect</button>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
<div class="image-container">
|
||
|
|
<div class="image-box">
|
||
|
|
<h3>Original Image</h3>
|
||
|
|
<img id="originalImage" style="display: none;">
|
||
|
|
</div>
|
||
|
|
<div class="image-box">
|
||
|
|
<h3>Detected Objects</h3>
|
||
|
|
<img id="resultImage" style="display: none;">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<script>
|
||
|
|
document.getElementById('uploadForm').addEventListener('submit', async (e) => {
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
const fileInput = document.getElementById('imageInput');
|
||
|
|
const file = fileInput.files[0];
|
||
|
|
|
||
|
|
if (!file) return;
|
||
|
|
|
||
|
|
// Display original image
|
||
|
|
const originalImage = document.getElementById('originalImage');
|
||
|
|
originalImage.src = URL.createObjectURL(file);
|
||
|
|
originalImage.style.display = 'block';
|
||
|
|
|
||
|
|
// Create form data
|
||
|
|
const formData = new FormData();
|
||
|
|
formData.append('file', file);
|
||
|
|
|
||
|
|
try {
|
||
|
|
const response = await fetch('/upload', {
|
||
|
|
method: 'POST',
|
||
|
|
body: formData
|
||
|
|
});
|
||
|
|
|
||
|
|
if (response.ok) {
|
||
|
|
const result = await response.json();
|
||
|
|
const resultImage = document.getElementById('resultImage');
|
||
|
|
|
||
|
|
// Set the base64 image directly
|
||
|
|
resultImage.src = `data:image/jpeg;base64,${result.image}`;
|
||
|
|
resultImage.style.display = 'block';
|
||
|
|
} else {
|
||
|
|
alert('Error processing image');
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
console.error('Error:', error);
|
||
|
|
alert('Error processing image');
|
||
|
|
}
|
||
|
|
});
|
||
|
|
</script>
|
||
|
|
</body>
|
||
|
|
</html>
|