Spaces:
Sleeping

File size: 16,696 Bytes
fb14bd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!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>