img-class / index.html
HedronCreeper's picture
Update index.html
ea7e162 verified
Raw
History Blame Contribute Delete
20.6 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Neural Vision AI</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #0f1419;
--surface: #1a1f2e;
--accent-cyan: #00d9ff;
--accent-purple: #9d4edd;
--accent-pink: #ff006e;
--text-primary: #ffffff;
--text-secondary: #a0a9be;
--glow-intensity: 0.8;
}
body {
background: linear-gradient(135deg, var(--primary) 0%, #0d0f18 50%, var(--surface) 100%);
color: var(--text-primary);
font-family: 'Inter', sans-serif;
min-height: 100vh;
overflow-x: hidden;
position: relative;
}
/* Animated background grid */
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image:
linear-gradient(0deg, transparent 24%, rgba(0, 217, 255, 0.05) 25%, rgba(0, 217, 255, 0.05) 26%, transparent 27%, transparent 74%, rgba(0, 217, 255, 0.05) 75%, rgba(0, 217, 255, 0.05) 76%, transparent 77%, transparent),
linear-gradient(90deg, transparent 24%, rgba(0, 217, 255, 0.05) 25%, rgba(0, 217, 255, 0.05) 26%, transparent 27%, transparent 74%, rgba(0, 217, 255, 0.05) 75%, rgba(0, 217, 255, 0.05) 76%, transparent 77%, transparent);
background-size: 50px 50px;
pointer-events: none;
z-index: 0;
animation: gridShift 20s linear infinite;
}
@keyframes gridShift {
0% { transform: translate(0, 0); }
100% { transform: translate(50px, 50px); }
}
.container {
max-width: 900px;
margin: 0 auto;
padding: 40px 20px;
position: relative;
z-index: 1;
}
/* Header with glow */
.header {
text-align: center;
margin-bottom: 60px;
animation: fadeInDown 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.logo {
font-family: 'Space Mono', monospace;
font-size: 14px;
letter-spacing: 2px;
text-transform: uppercase;
color: var(--accent-cyan);
margin-bottom: 8px;
opacity: 0.8;
font-weight: 700;
text-shadow: 0 0 20px rgba(0, 217, 255, 0.3);
}
h1 {
font-family: 'Space Mono', monospace;
font-size: 48px;
font-weight: 700;
margin-bottom: 16px;
background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-purple) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
letter-spacing: 1px;
}
.subtitle {
color: var(--text-secondary);
font-size: 16px;
font-weight: 300;
letter-spacing: 0.5px;
}
/* Main content card */
.card {
background: linear-gradient(135deg, rgba(26, 31, 46, 0.8) 0%, rgba(30, 35, 52, 0.8) 100%);
border: 1px solid rgba(0, 217, 255, 0.2);
border-radius: 20px;
padding: 50px;
backdrop-filter: blur(10px);
box-shadow:
0 0 40px rgba(0, 217, 255, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
animation: fadeInUp 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Upload area */
.upload-area {
margin-bottom: 40px;
}
.upload-label {
display: block;
font-size: 14px;
font-weight: 600;
letter-spacing: 0.5px;
text-transform: uppercase;
color: var(--accent-cyan);
margin-bottom: 16px;
opacity: 0.9;
}
.file-input-wrapper {
position: relative;
cursor: pointer;
}
#imageUpload {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
cursor: pointer;
z-index: 1;
}
.file-input-label {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 40px;
border: 2px dashed rgba(0, 217, 255, 0.4);
border-radius: 16px;
background: linear-gradient(135deg, rgba(0, 217, 255, 0.05) 0%, rgba(157, 78, 221, 0.05) 100%);
transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
position: relative;
overflow: hidden;
}
.file-input-label::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, rgba(0, 217, 255, 0.1) 0%, rgba(157, 78, 221, 0.1) 100%);
opacity: 0;
transition: opacity 0.3s ease;
z-index: -1;
}
.file-input-wrapper:hover .file-input-label {
border-color: rgba(0, 217, 255, 0.8);
background: linear-gradient(135deg, rgba(0, 217, 255, 0.1) 0%, rgba(157, 78, 221, 0.1) 100%);
box-shadow: 0 0 30px rgba(0, 217, 255, 0.2);
transform: translateY(-2px);
}
.upload-icon {
font-size: 32px;
margin-bottom: 12px;
opacity: 0.8;
animation: float 3s ease-in-out infinite;
}
@keyframes float {
0%, 100% { transform: translateY(0px); }
50% { transform: translateY(-8px); }
}
.upload-text {
color: var(--text-primary);
font-size: 16px;
font-weight: 600;
margin-bottom: 4px;
}
.upload-subtext {
color: var(--text-secondary);
font-size: 13px;
font-weight: 300;
}
/* Preview section */
.preview-section {
margin-bottom: 40px;
text-align: center;
}
#preview {
max-width: 100%;
max-height: 350px;
border-radius: 12px;
border: 1px solid rgba(0, 217, 255, 0.3);
object-fit: contain;
box-shadow:
0 0 40px rgba(0, 217, 255, 0.2),
0 0 80px rgba(157, 78, 221, 0.1),
inset 0 0 30px rgba(0, 217, 255, 0.05);
animation: imageGlow 2s ease-in-out infinite;
display: none;
}
#preview.loaded {
display: block;
animation: slideInImage 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes slideInImage {
from {
opacity: 0;
transform: scale(0.95);
}
to {
opacity: 1;
transform: scale(1);
}
}
@keyframes imageGlow {
0%, 100% { box-shadow: 0 0 40px rgba(0, 217, 255, 0.2), 0 0 80px rgba(157, 78, 221, 0.1), inset 0 0 30px rgba(0, 217, 255, 0.05); }
50% { box-shadow: 0 0 50px rgba(0, 217, 255, 0.3), 0 0 100px rgba(157, 78, 221, 0.15), inset 0 0 30px rgba(0, 217, 255, 0.08); }
}
/* Results section */
#label-container {
min-height: 80px;
display: flex;
flex-direction: column;
gap: 12px;
justify-content: flex-start;
}
.prediction {
padding: 16px 20px;
border-radius: 12px;
background: linear-gradient(135deg, rgba(0, 217, 255, 0.05) 0%, rgba(157, 78, 221, 0.05) 100%);
border: 1px solid rgba(0, 217, 255, 0.2);
display: flex;
justify-content: space-between;
align-items: center;
font-family: 'Space Mono', monospace;
font-size: 14px;
font-weight: 500;
transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
animation: slideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
cursor: pointer;
position: relative;
overflow: hidden;
}
.prediction::before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 0;
background: linear-gradient(90deg, rgba(0, 217, 255, 0.2) 0%, transparent 100%);
transition: width 0.4s ease;
z-index: 0;
}
.prediction:hover {
transform: translateX(8px);
border-color: rgba(0, 217, 255, 0.6);
box-shadow: 0 0 25px rgba(0, 217, 255, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
.prediction:hover::before {
width: 100%;
}
.prediction-content {
position: relative;
z-index: 1;
flex: 1;
text-align: left;
}
.prediction-class {
color: var(--text-primary);
font-weight: 700;
margin-bottom: 2px;
}
.prediction-bar {
height: 6px;
background: rgba(0, 217, 255, 0.1);
border-radius: 3px;
overflow: hidden;
margin-top: 6px;
}
.prediction-fill {
height: 100%;
background: linear-gradient(90deg, var(--accent-cyan) 0%, var(--accent-purple) 100%);
border-radius: 3px;
animation: fillBar 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
box-shadow: 0 0 15px rgba(0, 217, 255, 0.5);
}
@keyframes fillBar {
from {
width: 0%;
box-shadow: 0 0 15px rgba(0, 217, 255, 0.5);
}
to {
width: var(--percentage);
box-shadow: 0 0 10px rgba(0, 217, 255, 0.3);
}
}
.prediction-percent {
color: var(--accent-cyan);
font-weight: 700;
margin-left: 12px;
position: relative;
z-index: 1;
white-space: nowrap;
font-size: 13px;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.loading-indicator {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
color: var(--accent-cyan);
font-family: 'Space Mono', monospace;
font-size: 14px;
font-weight: 600;
animation: fadeInUp 0.4s ease;
}
.loading-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent-cyan);
animation: pulse 1.4s ease-in-out infinite;
}
.loading-dot:nth-child(2) {
animation-delay: 0.2s;
}
.loading-dot:nth-child(3) {
animation-delay: 0.4s;
}
@keyframes pulse {
0%, 100% {
opacity: 0.3;
transform: scale(0.8);
}
50% {
opacity: 1;
transform: scale(1.2);
}
}
.status-badge {
display: inline-block;
padding: 6px 12px;
border-radius: 20px;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.5px;
margin-top: 12px;
background: linear-gradient(135deg, rgba(0, 217, 255, 0.1) 0%, rgba(157, 78, 221, 0.1) 100%);
border: 1px solid rgba(0, 217, 255, 0.3);
color: var(--accent-cyan);
text-transform: uppercase;
animation: slideInUp 0.4s ease 0.6s both;
}
@keyframes slideInUp {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Responsive design */
@media (max-width: 768px) {
.container {
padding: 20px 16px;
}
.card {
padding: 30px 20px;
}
h1 {
font-size: 32px;
}
.prediction {
flex-direction: column;
align-items: flex-start;
gap: 8px;
}
.prediction-percent {
margin-left: 0;
}
}
/* Scroll behavior */
html {
scroll-behavior: smooth;
}
/* Selection styling */
::selection {
background: rgba(0, 217, 255, 0.3);
color: var(--text-primary);
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<div class="logo">⚡ Neural Vision</div>
<h1>AI Image Classifier</h1>
<p class="subtitle">Powered by TensorFlow & Teachable Machine</p>
</div>
<div class="card">
<div class="upload-area">
<label class="upload-label">Upload Image</label>
<div class="file-input-wrapper">
<input type="file" id="imageUpload" accept="image/*">
<label class="file-input-label">
<div class="upload-icon">🚀</div>
<div class="upload-text">Drop your image here</div>
<div class="upload-subtext">or click to browse</div>
</label>
</div>
</div>
<div class="preview-section">
<img id="preview" alt="Preview" />
</div>
<div id="label-container"></div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@latest/dist/teachablemachine-image.min.js"></script>
<script>
// Model configuration
const MODEL_URL = "https://huggingface.co/HedronCreeper/img-class/resolve/main/";
let model, maxPredictions;
let isProcessing = false;
// Load model from HF
async function loadModel() {
try {
const modelURL = MODEL_URL + "model.json";
const metadataURL = MODEL_URL + "metadata.json";
model = await tmImage.load(modelURL, metadataURL);
maxPredictions = model.getTotalClasses();
console.log("✅ Model loaded successfully");
return true;
} catch (error) {
console.error("❌ Model load error:", error);
showError("Failed to load model. Please refresh and try again.");
return false;
}
}
// Show error state
function showError(message) {
const labelContainer = document.getElementById("label-container");
labelContainer.innerHTML = `<div style="color: #ff006e; padding: 16px; text-align: center; border-radius: 8px; background: rgba(255, 0, 110, 0.1); border: 1px solid rgba(255, 0, 110, 0.3);">${message}</div>`;
}
// Predict function
async function predict(image) {
if (!image.complete || image.naturalHeight === 0) {
return;
}
try {
const prediction = await model.predict(image);
const labelContainer = document.getElementById("label-container");
labelContainer.innerHTML = "";
// Sort by highest probability
prediction.sort((a, b) => b.probability - a.probability);
// Create prediction elements
prediction.forEach((pred, index) => {
const percentage = (pred.probability * 100).toFixed(1);
const div = document.createElement("div");
div.className = "prediction";
div.innerHTML = `
<div class="prediction-content">
<div class="prediction-class">${pred.className}</div>
<div class="prediction-bar">
<div class="prediction-fill" style="--percentage: ${percentage}%; animation-delay: ${index * 0.1}s;"></div>
</div>
</div>
<div class="prediction-percent">${percentage}%</div>
`;
labelContainer.appendChild(div);
});
// Add status badge
const badge = document.createElement("div");
badge.className = "status-badge";
badge.textContent = "✓ Classification Complete";
labelContainer.appendChild(badge);
} catch (error) {
console.error("Prediction error:", error);
showError("Error during classification. Please try another image.");
} finally {
isProcessing = false;
}
}
// Handle file upload
document.getElementById("imageUpload").addEventListener("change", async function(event) {
const file = event.target.files[0];
if (!file) return;
if (isProcessing) return;
isProcessing = true;
const img = document.getElementById("preview");
const labelContainer = document.getElementById("label-container");
// Show loading state
labelContainer.innerHTML = `
<div class="loading-indicator">
<span>Processing</span>
<div class="loading-dot"></div>
<div class="loading-dot"></div>
<div class="loading-dot"></div>
</div>
`;
// Reset and load image
img.classList.remove("loaded");
img.src = "";
const objectURL = window.URL.createObjectURL(file);
img.src = objectURL;
img.onload = async () => {
img.classList.add("loaded");
// Load model if not already loaded
if (!model) {
const loaded = await loadModel();
if (!loaded) {
isProcessing = false;
window.URL.revokeObjectURL(objectURL);
return;
}
}
// Perform prediction
await predict(img);
window.URL.revokeObjectURL(objectURL);
};
img.onerror = () => {
isProcessing = false;
showError("Failed to load image. Please try another file.");
window.URL.revokeObjectURL(objectURL);
};
});
// Initialize model on page load
window.addEventListener("load", () => {
loadModel();
});
</script>
</body>
</html>