Spaces:
Sleeping

ScratchNet / templates /index.html
SnippyCodes's picture
Deploy flower classifier to Hugging Face Space with Git LFS
fb14bd4
Raw History Blame Contribute Delete
16.7 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ScratchNet β€” 7-Class Flower Image Detector & AI Classifier</title>
<meta name="description" content="AI Flower Classifier powered by a deep Convolutional Neural Network (PyTorch). Detect Daisy, Dandelion, Rose, Sunflower, Tulip, Bellflower, and Lotus in real-time.">
<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=Outfit:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<div class="background-ambient">
<div class="glow-orb orb-1"></div>
<div class="glow-orb orb-2"></div>
<div class="glow-orb orb-3"></div>
</div>
<!-- Main Navigation Bar -->
<header class="navbar">
<div class="nav-container">
<div class="brand">
<span class="brand-icon">πŸͺ·</span>
<div class="brand-text">
<span class="brand-name">ScratchNet <span class="brand-ai">AI</span></span>
<span class="brand-tag">Botanical CNN Vision</span>
</div>
</div>
<div class="nav-actions">
<div class="status-badge" id="hardwareStatusBadge" title="Hardware Acceleration Status">
<span class="status-dot"></span>
<span id="hardwareStatusText">Checking Hardware...</span>
</div>
<a href="#howToUseSection" class="btn-ghost" id="howToUseNavBtn">
<span>πŸ“– How to Use Model</span>
</a>
</div>
</div>
</header>
<main class="main-content">
<!-- Hero Header -->
<section class="hero-section">
<div class="hero-badge">
<span class="badge-sparkle">✨</span>
<span>PyTorch 2D CNN β€’ 7 Flower Classes β€’ 150Γ—150 Spatial Architecture</span>
</div>
<h1 class="hero-title">
Detect & Identify Flowers with <span class="gradient-text">Deep Learning</span>
</h1>
<p class="hero-subtitle">
Upload or drag any flower image to classify between <strong>Daisy, Dandelion, Rose, Sunflower, Tulip, Bellflower,</strong> and <strong>Lotus</strong> with instant confidence scores and botanical profiles.
</p>
</section>
<!-- Quick Sample Selector Carousel -->
<section class="samples-section">
<div class="samples-header">
<span class="samples-label">⚑ Quick Test With 1-Click Samples:</span>
<span class="samples-hint">Click any flower below to detect instantly</span>
</div>
<div class="samples-grid" id="samplesContainer">
<!-- Injected via JavaScript from /api/samples -->
<div class="sample-skeleton">Loading sample flowers...</div>
</div>
</section>
<!-- Interactive Workbench Grid -->
<section class="workbench-grid">
<!-- Left Panel: Image Upload & Dropzone -->
<div class="panel-card upload-panel">
<div class="panel-header">
<h2 class="panel-title">
<span class="panel-icon">πŸ“Έ</span> Input Flower Photo
</h2>
<span class="panel-badge">RGB 150Γ—150 Normalization</span>
</div>
<!-- Dropzone Area -->
<div class="dropzone" id="dropzone" tabindex="0" role="button" aria-label="Upload flower image">
<input type="file" id="fileInput" accept="image/png, image/jpeg, image/webp, image/bmp" style="display: none;">
<div class="dropzone-empty" id="dropzoneEmpty">
<div class="dropzone-icon-ring">
<svg class="upload-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
<polyline points="17 8 12 3 7 8"></polyline>
<line x1="12" y1="3" x2="12" y2="15"></line>
</svg>
</div>
<h3 class="dropzone-title">Drag & drop your flower photo here</h3>
<p class="dropzone-desc">Supports JPG, PNG, WEBP, BMP up to 20MB</p>
<div class="dropzone-actions">
<button type="button" class="btn-primary" id="browseFilesBtn">
<span>Browse Files</span>
</button>
<span class="paste-hint">or press <kbd>Ctrl</kbd> + <kbd>V</kbd> to paste</span>
</div>
</div>
<!-- Image Preview (Hidden by default) -->
<div class="dropzone-preview" id="dropzonePreview" style="display: none;">
<div class="preview-wrapper">
<img id="previewImage" alt="Uploaded flower preview">
<div class="preview-overlay">
<button type="button" class="btn-icon" id="clearImageBtn" title="Remove image">
<svg viewBox="0 0 24 24" width="18" height="18" stroke="currentColor" stroke-width="2" fill="none">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
</div>
</div>
<div class="preview-meta">
<span class="preview-filename" id="previewFilename">image.jpg</span>
<span class="preview-filesize" id="previewFilesize">-- KB</span>
</div>
</div>
</div>
<!-- Analysis Action Trigger -->
<div class="upload-controls">
<button type="button" class="btn-submit" id="analyzeBtn" disabled>
<span class="btn-spinner" id="btnSpinner" style="display: none;"></span>
<span id="analyzeBtnText">Analyze Flower</span>
<span class="btn-arrow">β†’</span>
</button>
</div>
</div>
<!-- Right Panel: Detection Results -->
<div class="panel-card result-panel">
<div class="panel-header">
<h2 class="panel-title">
<span class="panel-icon">πŸ”¬</span> Detection & Confidence
</h2>
<span class="panel-badge" id="inferenceDeviceBadge">Ready</span>
</div>
<!-- Result Placeholder (When no prediction yet) -->
<div class="result-placeholder" id="resultPlaceholder">
<div class="placeholder-art">
<span class="placeholder-emoji">🌺</span>
</div>
<h3 class="placeholder-title">Awaiting Flower Photo</h3>
<p class="placeholder-desc">
Upload your photo on the left or select any sample flower above to run the neural network.
</p>
</div>
<!-- Live Results Container (Shown on prediction) -->
<div class="result-content" id="resultContent" style="display: none;">
<!-- Primary Winner Card -->
<div class="winner-card" id="winnerCard">
<div class="winner-header">
<div class="winner-icon-circle" id="winnerIcon">🌸</div>
<div class="winner-titles">
<span class="winner-tag">Predicted Category</span>
<h3 class="winner-name" id="winnerName">Sunflower</h3>
<span class="winner-scientific" id="winnerScientific">Helianthus annuus</span>
</div>
<div class="winner-gauge">
<span class="gauge-value" id="winnerConfidence">99.8%</span>
<span class="gauge-label">Confidence</span>
</div>
</div>
<div class="winner-body">
<p class="winner-description" id="winnerDescription">
A tall, radiant flower celebrated for tracking the sun across the sky.
</p>
<div class="winner-attributes">
<div class="attr-pill">
<span class="attr-key">Family:</span>
<span class="attr-val" id="winnerFamily">Asteraceae</span>
</div>
<div class="attr-pill">
<span class="attr-key">Blooms:</span>
<span class="attr-val" id="winnerSeason">Summer</span>
</div>
</div>
</div>
</div>
<!-- 7 Class Probabilities Breakdown -->
<div class="probabilities-section">
<h4 class="prob-section-title">Class Probabilities (Softmax Spectrum)</h4>
<div class="prob-list" id="probabilitiesList">
<!-- Injected dynamically via app.js -->
</div>
</div>
<!-- Developer JSON Payload Toggle -->
<details class="json-details">
<summary class="json-summary">View Raw API Response (JSON)</summary>
<pre class="json-pre"><code id="jsonCodeOutput">{}</code></pre>
</details>
</div>
</div>
</section>
<!-- Comprehensive Guide: "How Will Users Use My Model?" -->
<section class="guide-section" id="howToUseSection">
<div class="section-title-wrapper">
<span class="section-badge">πŸ“˜ Architecture & Deployment Guide</span>
<h2 class="section-heading">How Users Can Run & Integrate Your Model</h2>
<p class="section-subheading">
Your model is trained, validated, and ready for production. Here are the 4 ways users and developers can consume it:
</p>
</div>
<div class="guide-cards-grid">
<!-- Card 1: Web Interface -->
<div class="guide-card">
<div class="guide-icon-bubble">🌐</div>
<h3 class="guide-card-title">1. Interactive Web App (Current)</h3>
<p class="guide-card-desc">
Run this local web application. Anyone on your local network or Wi-Fi can open it in their browser and drag-and-drop photos.
</p>
<div class="code-snippet">
<code># Start the web server
py app.py
# Or run with host 0.0.0.0 to share on local Wi-Fi</code>
</div>
</div>
<!-- Card 2: REST API -->
<div class="guide-card">
<div class="guide-icon-bubble">⚑</div>
<h3 class="guide-card-title">2. REST API for Web & Mobile Apps</h3>
<p class="guide-card-desc">
Developers can send HTTP POST requests with any image to your FastAPI endpoint to get instant JSON predictions.
</p>
<div class="code-snippet">
<code>curl -X POST "http://localhost:8000/api/predict" \
-F "file=@my_flower.jpg"</code>
</div>
</div>
<!-- Card 3: Python Package -->
<div class="guide-card">
<div class="guide-icon-bubble">🐍</div>
<h3 class="guide-card-title">3. Direct Python Import</h3>
<p class="guide-card-desc">
Import your trained model into any Python script, data science notebook, or batch processing pipeline.
</p>
<div class="code-snippet">
<code>from model import predict_flower
result = predict_flower("flower.jpg")
print(result["top_flower"], result["confidence_pct"])</code>
</div>
</div>
<!-- Card 4: Free Cloud Deployment -->
<div class="guide-card">
<div class="guide-icon-bubble">πŸš€</div>
<h3 class="guide-card-title">4. Free Cloud Hosting (Hugging Face)</h3>
<p class="guide-card-desc">
Deploy your model for free to <strong>Hugging Face Spaces</strong> or <strong>Render</strong> so anyone in the world can use it via public URL.
</p>
<div class="code-snippet">
<code># Launch the included Gradio interface
py gradio_app.py
# Push to Hugging Face Spaces for 24/7 public access</code>
</div>
</div>
</div>
</section>
<!-- Technical Deep-Dive: Architecture & History -->
<section class="tech-section">
<div class="tech-card">
<div class="tech-card-content">
<h3 class="tech-title">From NumPy MLP to PyTorch CNN: The Engineering Story</h3>
<p class="tech-text">
The project originated as <strong>ScratchNet</strong>, an MLP written in pure NumPy. While the MLP achieved 90% training accuracy, it flattened images into 67,500 1D vectors, losing all spatial geometry and dropping to 40% on real-world photos due to background color memorization.
</p>
<p class="tech-text">
Switching to this <strong>PyTorch Convolutional Neural Network</strong> solved the issue: 3 hierarchical convolutional blocks extract invariant edge and petal textures, while MaxPooling downsamples spatial dimensions (150 &rarr; 75 &rarr; 37 &rarr; 18). The model achieved a robust <strong>~79% test accuracy</strong> across 2,240 test images on the 7 flower classes.
</p>
</div>
<div class="tech-stats-grid">
<div class="stat-box">
<span class="stat-number">7</span>
<span class="stat-label">Flower Classes</span>
</div>
<div class="stat-box">
<span class="stat-number">150Γ—150</span>
<span class="stat-label">RGB Resolution</span>
</div>
<div class="stat-box">
<span class="stat-number">~79%</span>
<span class="stat-label">Test Accuracy</span>
</div>
<div class="stat-box">
<span class="stat-number">21.6 MB</span>
<span class="stat-label">Model Weights</span>
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="footer">
<div class="footer-container">
<div class="footer-brand">
<span>πŸͺ· ScratchNet AI β€” Deep Learning Flower Classifier</span>
</div>
<div class="footer-credits">
<span>Created with PyTorch, FastAPI & Vanilla Modern Web Standards</span>
</div>
</div>
</footer>
<script src="/static/app.js"></script>
</body>
</html>