easy-local-alpr/templates/index.html

158 lines
7.4 KiB
HTML
Raw Normal View History

2024-07-17 21:14:01 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
2024-07-19 21:43:47 +02:00
<title>Easy Local ALPR - API</title>
2024-07-17 21:14:01 +02:00
<script src="https://cdn.tailwindcss.com"></script>
2024-07-17 22:02:50 +02:00
<!-- Include Google Sans font -->
2024-07-17 21:14:01 +02:00
<link href="https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap" rel="stylesheet">
<style>
body {
background-color: #f0f2f5;
2024-07-17 22:02:50 +02:00
background-image: radial-gradient(#7c7c7c 1px, rgba(0, 0, 0, 0) 1px);
2024-07-17 21:14:01 +02:00
background-size: 20px 20px;
2024-07-19 21:42:16 +02:00
font-family: 'Google Sans', sans-serif;
2024-07-17 21:14:01 +02:00
}
2024-07-22 22:38:54 +02:00
.loading-circle {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #000;
border-radius: 50%;
width: 24px;
height: 24px;
animation: spin 1s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
input[type="text"], input[type="number"] {
background-color: white;
color: black;
}
input[type="text"].dark, input[type="number"].dark {
background-color: #3b3b3b;
color: white;
}
2024-07-17 21:14:01 +02:00
</style>
</head>
2024-07-19 21:42:16 +02:00
<body class="bg-neutral-100 dark:bg-neutral-900 dark:text-white flex items-center justify-center min-h-screen p-4">
2024-07-17 21:14:01 +02:00
<!-- Logo -->
2024-07-19 21:42:16 +02:00
<div class="absolute top-4 left-4 z-50">
2024-07-17 22:02:50 +02:00
<img id="logo" src="{{ url_for('static', filename='logo_black.webp') }}" alt="Logo" class="h-12 dark:hidden">
<img id="logoDark" src="{{ url_for('static', filename='logo_white.webp') }}" alt="Logo" class="h-12 hidden dark:block">
2024-07-17 21:14:01 +02:00
</div>
2024-07-19 21:42:16 +02:00
<div class="bg-white dark:bg-neutral-800 p-6 rounded-lg shadow-lg w-full max-w-md mt-16">
2024-07-17 22:02:50 +02:00
<h1 class="text-2xl font-bold mb-4 text-center dark:text-gray-200">Upload Image for ALPR</h1>
2024-07-17 21:14:01 +02:00
<form id="uploadForm" enctype="multipart/form-data" class="space-y-4">
<div>
2024-07-17 22:02:50 +02:00
<label for="upload" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Choose an image:</label>
2024-07-17 21:14:01 +02:00
<div class="mt-1 flex items-center">
<input type="file" id="upload" name="upload" accept="image/*" class="hidden" onchange="updateFileName()">
2024-07-17 22:02:50 +02:00
<label for="upload" class="cursor-pointer inline-flex items-center justify-center px-4 py-2 border border-gray-400 rounded-md shadow-sm text-sm font-medium text-gray-700 dark:text-gray-300 bg-white dark:bg-neutral-800 hover:bg-neutral-50 dark:hover:bg-neutral-600">
2024-07-17 21:14:01 +02:00
Select file
</label>
2024-07-17 22:02:50 +02:00
<span id="fileName" class="ml-2 text-sm text-gray-600 dark:text-gray-300"></span>
2024-07-17 21:14:01 +02:00
</div>
</div>
2024-07-22 22:38:54 +02:00
<div>
<label for="grid_size" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Grid Size:</label>
<input type="number" id="grid_size" name="grid_size" value="3" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark">
</div>
<div>
<label for="wanted_cells" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Wanted Cells:</label>
<input type="text" id="wanted_cells" name="wanted_cells" class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm dark">
</div>
2024-07-17 21:14:01 +02:00
<div id="imagePreview" class="mt-4 hidden">
<img id="previewImage" src="#" alt="Preview" class="max-w-full h-auto rounded-lg">
</div>
2024-07-22 22:38:54 +02:00
<button id="submitButton" type="submit" class="w-full py-2 px-4 bg-black text-white font-semibold rounded-md shadow-sm hover:bg-neutral-900 dark:bg-neutral-900 dark:hover:bg-neutral-950 relative flex justify-center items-center">
<span>Upload</span>
<div id="loadingCircle" class="loading-circle absolute hidden"></div>
</button>
2024-07-17 21:14:01 +02:00
</form>
<div class="mt-6">
2024-07-17 22:02:50 +02:00
<h2 class="text-xl font-semibold mb-2 dark:text-gray-200">Response</h2>
2024-07-19 21:42:16 +02:00
<pre id="responseBox" class="bg-neutral-100 dark:bg-neutral-900 p-4 border rounded-lg text-sm text-gray-900 dark:text-gray-200 overflow-x-auto"></pre>
2024-07-17 21:14:01 +02:00
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
function updateFileName() {
var input = document.getElementById('upload');
var fileName = document.getElementById('fileName');
var imagePreview = document.getElementById('imagePreview');
var previewImage = document.getElementById('previewImage');
fileName.textContent = input.files[0] ? input.files[0].name : '';
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
previewImage.src = e.target.result;
imagePreview.classList.remove('hidden');
}
reader.readAsDataURL(input.files[0]);
}
}
2024-07-17 22:02:50 +02:00
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
function toggleLogo() {
const logo = document.getElementById('logo');
const logoDark = document.getElementById('logoDark');
2024-07-22 22:38:54 +02:00
const upload = document.getElementById('upload');
const gridSize = document.getElementById('grid_size');
const wantedCells = document.getElementById('wanted_cells');
2024-07-17 22:02:50 +02:00
if (prefersDarkScheme.matches) {
logo.style.display = 'none';
logoDark.style.display = 'block';
2024-07-22 22:38:54 +02:00
upload.classList.add('dark');
gridSize.classList.add('dark');
wantedCells.classList.add('dark');
2024-07-17 22:02:50 +02:00
} else {
logo.style.display = 'block';
logoDark.style.display = 'none';
2024-07-22 22:38:54 +02:00
upload.classList.remove('dark');
gridSize.classList.remove('dark');
wantedCells.classList.remove('dark');
2024-07-17 22:02:50 +02:00
}
}
toggleLogo();
prefersDarkScheme.addEventListener('change', toggleLogo);
2024-07-17 21:14:01 +02:00
$(document).ready(function () {
$('#uploadForm').on('submit', function (e) {
e.preventDefault();
var formData = new FormData(this);
2024-07-22 22:38:54 +02:00
$('#submitButton').prop('disabled', true);
$('#loadingCircle').removeClass('hidden');
2024-07-17 21:14:01 +02:00
$.ajax({
url: '/v1/image/alpr',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function (data) {
$('#responseBox').text(JSON.stringify(data, null, 2));
},
error: function (xhr, status, error) {
var err = JSON.parse(xhr.responseText);
$('#responseBox').text(JSON.stringify(err, null, 2));
2024-07-22 22:38:54 +02:00
},
complete: function () {
$('#submitButton').prop('disabled', false);
$('#loadingCircle').addClass('hidden');
2024-07-17 21:14:01 +02:00
}
});
});
});
</script>
</body>
</html>