Yunpeng-26 commited on
Commit
43aa397
·
verified ·
1 Parent(s): 8af8e3b

Sync updated image classification teaching demo

Browse files

Add randomized example bank, comparison log, student How to Start guide, and updated static browser inference UI.

.gitattributes CHANGED
@@ -2,3 +2,5 @@ examples/astronaut.png filter=lfs diff=lfs merge=lfs -text
2
  examples/chelsea.png filter=lfs diff=lfs merge=lfs -text
3
  examples/coffee.png filter=lfs diff=lfs merge=lfs -text
4
  examples/rocket.jpg filter=lfs diff=lfs merge=lfs -text
 
 
 
2
  examples/chelsea.png filter=lfs diff=lfs merge=lfs -text
3
  examples/coffee.png filter=lfs diff=lfs merge=lfs -text
4
  examples/rocket.jpg filter=lfs diff=lfs merge=lfs -text
5
+ examples/tower.jpg filter=lfs diff=lfs merge=lfs -text
6
+ how-to-start.pdf filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -20,11 +20,12 @@ The project shows how a pretrained model can turn image classification into a ca
20
 
21
  ## The learning story
22
 
23
- 1. Choose a tested example or upload an image.
24
  2. Choose a browser-compatible classifier: ResNet-18, ViT-B/16, or CLIP.
25
  3. Inspect the predicted labels and confidence scores.
26
  4. Keep the image fixed and switch models to compare decisions.
27
  5. For CLIP, change the candidate labels and observe how the result changes.
 
28
 
29
  ## Model and data
30
 
@@ -44,6 +45,7 @@ All three models are already trained. This demo performs inference only; no trai
44
  - `app.js` — interaction, image handling, and result rendering
45
  - `classifier.js` — the online Hugging Face model call
46
  - `examples/` — tested example images
 
47
 
48
  ## Runtime
49
 
@@ -51,15 +53,27 @@ The Space is static. `classifier.js` imports Transformers.js from jsDelivr and c
51
 
52
  This is the same online model-loading pattern used by the reference object-detection Space, with the task and models changed to image classification.
53
 
 
 
 
 
 
 
 
 
 
 
54
  ## Classroom check before use
55
 
56
  Before presenting, verify that:
57
 
58
- - all four bundled examples can be selected;
 
59
  - an uploaded image can be classified;
60
  - ResNet-18 and ViT-B/16 return ImageNet labels;
61
  - CLIP responds to changes in candidate labels;
62
  - the top-k slider changes the number of displayed predictions;
 
63
  - the first uncached run shows download progress;
64
  - the page works at a narrow/mobile width.
65
 
 
20
 
21
  ## The learning story
22
 
23
+ 1. Choose one of eight tested examples (four are shown at random), or upload an image.
24
  2. Choose a browser-compatible classifier: ResNet-18, ViT-B/16, or CLIP.
25
  3. Inspect the predicted labels and confidence scores.
26
  4. Keep the image fixed and switch models to compare decisions.
27
  5. For CLIP, change the candidate labels and observe how the result changes.
28
+ 6. Use the comparison log to discuss changes in the top label, score, and runtime.
29
 
30
  ## Model and data
31
 
 
45
  - `app.js` — interaction, image handling, and result rendering
46
  - `classifier.js` — the online Hugging Face model call
47
  - `examples/` — tested example images
48
+ - `how-to-start.html` / `how-to-start.pdf` — student guide for duplicating, editing, testing, and submitting a Space
49
 
50
  ## Runtime
51
 
 
53
 
54
  This is the same online model-loading pattern used by the reference object-detection Space, with the task and models changed to image classification.
55
 
56
+ Reference object-detection Space: <https://huggingface.co/spaces/wr92-course/test>
57
+
58
+ ## Student assignment
59
+
60
+ Students can duplicate this Space as a working starting point, then build their own AI mini app. They may extend image classification or adapt the project to a different AI task. A submission should make the app's purpose, input, output, and AI model or service easy to understand and demonstrate at least one working example.
61
+
62
+ In the App tab, select **How to Start** for the browser-based steps to create an account, duplicate the Space, edit files, test, and submit a public Space URL. Students are not required to train an AI model from scratch.
63
+
64
+ Higher-scoring work should deepen the selected AI task: compare or replace models, change label spaces, test another image domain, study failure cases, or improve speed and evaluation.
65
+
66
  ## Classroom check before use
67
 
68
  Before presenting, verify that:
69
 
70
+ - every image in the eight-example bank can be selected;
71
+ - Shuffle changes the four visible examples drawn from the eight-image bank;
72
  - an uploaded image can be classified;
73
  - ResNet-18 and ViT-B/16 return ImageNet labels;
74
  - CLIP responds to changes in candidate labels;
75
  - the top-k slider changes the number of displayed predictions;
76
+ - the score bars and comparison log update after every successful run;
77
  - the first uncached run shows download progress;
78
  - the page works at a narrow/mobile width.
79
 
app.js CHANGED
@@ -17,19 +17,39 @@ const summary = document.querySelector('#summary');
17
  const tbody = document.querySelector('#predictions-body');
18
  const runtimeBadge = document.querySelector('#runtime-badge');
19
  const sampleGrid = document.querySelector('#sample-grid');
 
 
 
 
 
 
 
20
 
21
- const state = { dataUrl: null, sourceLabel: null, running: false };
22
 
23
  const EXAMPLES = [
24
  { src: './examples/chelsea.png', label: 'Cat' },
25
  { src: './examples/coffee.png', label: 'Coffee' },
26
  { src: './examples/rocket.jpg', label: 'Rocket' },
27
  { src: './examples/astronaut.png', label: 'Astronaut' },
 
 
 
 
28
  ];
29
 
 
 
 
 
 
 
 
 
30
  function resetResults() {
31
  summary.textContent = 'No predictions yet.';
32
  tbody.innerHTML = '<tr class="empty-row"><td colspan="3">Run the classifier to see details.</td></tr>';
 
33
  }
34
 
35
  function setBadge(text, mode = '') {
@@ -44,6 +64,7 @@ function setRunning(running) {
44
  imageInput.disabled = running;
45
  topK.disabled = running;
46
  candidateLabels.disabled = running;
 
47
  document.querySelectorAll('.sample-card').forEach((card) => { card.disabled = running; });
48
  }
49
 
@@ -106,7 +127,8 @@ function renderModelChoices() {
106
  }
107
 
108
  function renderExampleChoices() {
109
- for (const example of EXAMPLES) {
 
110
  const button = document.createElement('button');
111
  button.type = 'button';
112
  button.className = 'sample-card';
@@ -119,7 +141,11 @@ function renderExampleChoices() {
119
 
120
  const label = document.createElement('span');
121
  label.textContent = example.label;
122
- button.append(image, label);
 
 
 
 
123
  button.addEventListener('click', () => loadExample(example, button));
124
  sampleGrid.appendChild(button);
125
  }
@@ -152,12 +178,28 @@ function renderPredictions(predictions) {
152
 
153
  predictions.forEach((prediction, index) => {
154
  const row = document.createElement('tr');
155
- const values = [index + 1, prediction.label, `${(Number(prediction.score) * 100).toFixed(2)}%`];
156
- for (const value of values) {
157
- const cell = document.createElement('td');
158
- cell.textContent = value;
159
- row.appendChild(cell);
160
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  tbody.appendChild(row);
162
  });
163
 
@@ -167,6 +209,53 @@ function renderPredictions(predictions) {
167
  : `${option.label} returned no predictions.`;
168
  }
169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  topK.addEventListener('input', () => { topKValue.value = topK.value; });
171
 
172
  modelSelect.addEventListener('change', () => {
@@ -202,6 +291,18 @@ imageInput.addEventListener('change', () => {
202
  reader.readAsDataURL(file);
203
  });
204
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  runButton.addEventListener('click', async () => {
206
  if (!state.dataUrl || state.running) return;
207
 
@@ -228,8 +329,9 @@ runButton.addEventListener('click', async () => {
228
  progressCallback: setProgress,
229
  });
230
  renderPredictions(predictions);
231
- const seconds = ((performance.now() - started) / 1000).toFixed(1);
232
- statusEl.textContent = `Done in ${seconds}s with ${option.label}. Change the model or image to compare.`;
 
233
  setBadge(`${predictions.length} predictions`, 'ready');
234
  } catch (error) {
235
  console.error(error);
@@ -243,3 +345,4 @@ runButton.addEventListener('click', async () => {
243
 
244
  renderModelChoices();
245
  renderExampleChoices();
 
 
17
  const tbody = document.querySelector('#predictions-body');
18
  const runtimeBadge = document.querySelector('#runtime-badge');
19
  const sampleGrid = document.querySelector('#sample-grid');
20
+ const shuffleButton = document.querySelector('#shuffle-examples');
21
+ const runMeta = document.querySelector('#run-meta');
22
+ const metaModel = document.querySelector('#meta-model');
23
+ const metaImage = document.querySelector('#meta-image');
24
+ const metaRuntime = document.querySelector('#meta-runtime');
25
+ const historyBody = document.querySelector('#history-body');
26
+ const clearHistory = document.querySelector('#clear-history');
27
 
28
+ const state = { dataUrl: null, sourceLabel: null, running: false, history: [] };
29
 
30
  const EXAMPLES = [
31
  { src: './examples/chelsea.png', label: 'Cat' },
32
  { src: './examples/coffee.png', label: 'Coffee' },
33
  { src: './examples/rocket.jpg', label: 'Rocket' },
34
  { src: './examples/astronaut.png', label: 'Astronaut' },
35
+ { src: './examples/cheetah.jpg', label: 'Cheetah' },
36
+ { src: './examples/lion.jpg', label: 'Lion' },
37
+ { src: './examples/tower.jpg', label: 'Tower' },
38
+ { src: './examples/bus.png', label: 'Bus illustration' },
39
  ];
40
 
41
+ function chooseRandom(items, count) {
42
+ return [...items]
43
+ .map((item) => ({ item, sort: Math.random() }))
44
+ .sort((a, b) => a.sort - b.sort)
45
+ .slice(0, count)
46
+ .map(({ item }) => item);
47
+ }
48
+
49
  function resetResults() {
50
  summary.textContent = 'No predictions yet.';
51
  tbody.innerHTML = '<tr class="empty-row"><td colspan="3">Run the classifier to see details.</td></tr>';
52
+ runMeta.hidden = true;
53
  }
54
 
55
  function setBadge(text, mode = '') {
 
64
  imageInput.disabled = running;
65
  topK.disabled = running;
66
  candidateLabels.disabled = running;
67
+ shuffleButton.disabled = running;
68
  document.querySelectorAll('.sample-card').forEach((card) => { card.disabled = running; });
69
  }
70
 
 
127
  }
128
 
129
  function renderExampleChoices() {
130
+ sampleGrid.innerHTML = '';
131
+ for (const example of chooseRandom(EXAMPLES, 4)) {
132
  const button = document.createElement('button');
133
  button.type = 'button';
134
  button.className = 'sample-card';
 
141
 
142
  const label = document.createElement('span');
143
  label.textContent = example.label;
144
+
145
+ const source = document.createElement('small');
146
+ source.textContent = 'Tested teaching sample';
147
+
148
+ button.append(image, label, source);
149
  button.addEventListener('click', () => loadExample(example, button));
150
  sampleGrid.appendChild(button);
151
  }
 
178
 
179
  predictions.forEach((prediction, index) => {
180
  const row = document.createElement('tr');
181
+ const rankCell = document.createElement('td');
182
+ rankCell.textContent = index + 1;
183
+
184
+ const labelCell = document.createElement('td');
185
+ labelCell.textContent = prediction.label;
186
+
187
+ const score = Math.max(0, Math.min(1, Number(prediction.score)));
188
+ const scoreCell = document.createElement('td');
189
+ const scoreWrap = document.createElement('div');
190
+ scoreWrap.className = 'score-wrap';
191
+ const scoreText = document.createElement('span');
192
+ scoreText.textContent = `${(score * 100).toFixed(2)}%`;
193
+ const scoreTrack = document.createElement('span');
194
+ scoreTrack.className = 'score-track';
195
+ const scoreFill = document.createElement('span');
196
+ scoreFill.className = 'score-fill';
197
+ scoreFill.style.width = `${score * 100}%`;
198
+ scoreTrack.appendChild(scoreFill);
199
+ scoreWrap.append(scoreText, scoreTrack);
200
+ scoreCell.appendChild(scoreWrap);
201
+
202
+ row.append(rankCell, labelCell, scoreCell);
203
  tbody.appendChild(row);
204
  });
205
 
 
209
  : `${option.label} returned no predictions.`;
210
  }
211
 
212
+ function renderHistory() {
213
+ clearHistory.disabled = state.history.length === 0;
214
+ if (!state.history.length) {
215
+ historyBody.innerHTML = '<tr class="empty-row"><td colspan="6">Run two models on the same image to start a comparison.</td></tr>';
216
+ return;
217
+ }
218
+
219
+ historyBody.innerHTML = '';
220
+ state.history.forEach((item, index) => {
221
+ const row = document.createElement('tr');
222
+ const values = [
223
+ index + 1,
224
+ item.image,
225
+ item.model,
226
+ item.label,
227
+ `${(item.score * 100).toFixed(1)}%`,
228
+ `${item.seconds.toFixed(1)}s`,
229
+ ];
230
+ values.forEach((value) => {
231
+ const cell = document.createElement('td');
232
+ cell.textContent = value;
233
+ row.appendChild(cell);
234
+ });
235
+ historyBody.appendChild(row);
236
+ });
237
+ }
238
+
239
+ function recordRun(option, predictions, seconds) {
240
+ const best = predictions[0];
241
+ if (!best) return;
242
+
243
+ state.history.unshift({
244
+ image: state.sourceLabel || 'Selected image',
245
+ model: option.label,
246
+ label: best.label,
247
+ score: Number(best.score),
248
+ seconds,
249
+ });
250
+ state.history = state.history.slice(0, 12);
251
+ renderHistory();
252
+
253
+ metaModel.textContent = option.label;
254
+ metaImage.textContent = state.sourceLabel || 'Selected image';
255
+ metaRuntime.textContent = `${seconds.toFixed(1)}s`;
256
+ runMeta.hidden = false;
257
+ }
258
+
259
  topK.addEventListener('input', () => { topKValue.value = topK.value; });
260
 
261
  modelSelect.addEventListener('change', () => {
 
291
  reader.readAsDataURL(file);
292
  });
293
 
294
+ clearHistory.addEventListener('click', () => {
295
+ state.history = [];
296
+ renderHistory();
297
+ });
298
+
299
+ shuffleButton.addEventListener('click', () => {
300
+ renderExampleChoices();
301
+ statusEl.textContent = state.dataUrl
302
+ ? 'New examples shown. Your current image is still selected.'
303
+ : 'Choose an example, or upload your own image.';
304
+ });
305
+
306
  runButton.addEventListener('click', async () => {
307
  if (!state.dataUrl || state.running) return;
308
 
 
329
  progressCallback: setProgress,
330
  });
331
  renderPredictions(predictions);
332
+ const seconds = (performance.now() - started) / 1000;
333
+ recordRun(option, predictions, seconds);
334
+ statusEl.textContent = `Done in ${seconds.toFixed(1)}s with ${option.label}. Change the model or image to compare.`;
335
  setBadge(`${predictions.length} predictions`, 'ready');
336
  } catch (error) {
337
  console.error(error);
 
345
 
346
  renderModelChoices();
347
  renderExampleChoices();
348
+ renderHistory();
examples/bus.png ADDED
examples/cheetah.jpg ADDED
examples/lion.jpg ADDED
examples/tower.jpg ADDED

Git LFS Details

  • SHA256: f57f96f7a71f89739d27ae8ffc09f73cd2f17415d16c94d42dcb0d571f4eb0ee
  • Pointer size: 131 Bytes
  • Size of remote file: 112 kB
how-to-start.html ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="description" content="A beginner guide to duplicating the course Hugging Face Space and publishing your own AI mini app.">
7
+ <title>How to Start - AI Mini App</title>
8
+ <style>
9
+ :root { color-scheme: light; --ink:#162033; --muted:#526176; --line:#d9e4ef; --blue:#2156a5; --light:#f4f8fc; --gold:#ffe49a; }
10
+ * { box-sizing:border-box; }
11
+ body { margin:0; color:var(--ink); background:#f7fafd; font:16px/1.58 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif; }
12
+ a { color:var(--blue); }
13
+ a:focus-visible { outline:3px solid #faad23; outline-offset:3px; }
14
+ .shell { max-width:1080px; margin:auto; padding:24px 28px 72px; }
15
+ .topbar { display:flex; justify-content:space-between; gap:14px; flex-wrap:wrap; align-items:center; margin-bottom:34px; }
16
+ .brand { font-weight:760; letter-spacing:-.02em; color:var(--ink); text-decoration:none; }
17
+ .top-actions { display:flex; gap:10px; flex-wrap:wrap; }
18
+ .top-actions a { text-decoration:none; border:1px solid var(--line); background:white; border-radius:999px; padding:8px 13px; font-size:13px; font-weight:650; }
19
+ .hero { background:linear-gradient(135deg,#e7f1ff 0%,#f9fbff 65%,#fff5d5 100%); border:1px solid #cbdcf0; border-radius:26px; padding:40px 42px; }
20
+ .eyebrow { font-size:12px; font-weight:800; letter-spacing:.12em; color:#325f9b; margin:0 0 12px; }
21
+ h1 { margin:0; font-size:clamp(42px,6vw,70px); line-height:1.04; letter-spacing:-.055em; }
22
+ .subtitle { margin:16px 0 0; color:#32445d; font-size:21px; font-weight:600; }
23
+ .goal { margin:28px 0 0; padding:18px 20px; background:white; border-left:5px solid #2b67bb; border-radius:10px; font-size:17px; }
24
+ .time { margin:15px 0 0; color:var(--muted); font-size:14px; }
25
+ .route { display:flex; gap:8px; flex-wrap:wrap; align-items:center; margin:26px 0 14px; }
26
+ .route span { background:#e8f0fa; border-radius:999px; padding:7px 11px; font-size:13px; font-weight:750; }
27
+ .route b { color:#67819f; }
28
+ .section-kicker { margin:34px 0 15px; font-size:12px; font-weight:800; letter-spacing:.12em; color:#4c6b94; text-transform:uppercase; }
29
+ .step { border:1px solid var(--line); background:white; border-radius:19px; padding:26px 28px; margin:16px 0; box-shadow:0 8px 24px rgba(35,65,110,.035); }
30
+ .step-top { display:flex; gap:14px; align-items:center; margin-bottom:12px; }
31
+ .step-num { display:inline-grid; place-items:center; flex:none; width:40px; height:40px; border-radius:12px; color:white; background:#245aa7; font-weight:800; }
32
+ h2 { margin:0; font-size:23px; line-height:1.2; letter-spacing:-.025em; }
33
+ .step-grid { display:grid; grid-template-columns:minmax(0,1.15fr) minmax(260px,.85fr); gap:24px; }
34
+ .step-grid:has(.step-copy:only-child) { display:block; }
35
+ .step-copy p { margin:8px 0 12px; }
36
+ .screen { align-self:start; border:1px solid #bed2e9; border-radius:13px; overflow:hidden; background:#f8fbff; font-size:14px; }
37
+ .screen-label { display:block; background:#e6f0fc; padding:9px 14px; color:#315d97; font-size:11px; font-weight:800; letter-spacing:.09em; text-transform:uppercase; }
38
+ .screen div { margin:0 12px; padding:11px 2px; border-bottom:1px solid #dbe7f2; font-weight:650; }
39
+ .screen div:last-child { border:0; }
40
+ .shot { margin:18px 0 0; }
41
+ .shot-image { position:relative; border:1px solid #d2dce8; border-radius:12px; overflow:hidden; line-height:0; }
42
+ .shot-image img { display:block; width:100%; height:auto; }
43
+ .shot-mark { position:absolute; border:3px solid #df4c31; border-radius:6px; box-shadow:0 0 0 2px rgba(255,255,255,.9),0 0 0 5px rgba(223,76,49,.22); }
44
+ .shot-mark b { position:absolute; top:-13px; left:-13px; display:grid; place-items:center; width:25px; height:25px; background:#df4c31; border:2px solid white; border-radius:50%; color:white; font:800 13px/1 system-ui,sans-serif; }
45
+ .shot figcaption { margin:9px 2px 0; color:var(--muted); font-size:13px; line-height:1.4; }
46
+ .filemap, .finish, .trouble { background:white; border:1px solid var(--line); border-radius:19px; padding:26px 28px; margin:16px 0; }
47
+ .filemap h2,.finish h2,.trouble h2 { margin-bottom:15px; }
48
+ table { border-collapse:collapse; width:100%; }
49
+ th,td { text-align:left; vertical-align:top; border-bottom:1px solid #e6edf5; padding:10px 6px; }
50
+ th { width:23%; }
51
+ tr:last-child th,tr:last-child td { border-bottom:0; }
52
+ code { background:#edf3fa; border-radius:5px; padding:2px 5px; color:#174781; }
53
+ .finish ul { list-style:none; padding:0; margin:0; }
54
+ .finish li { padding:8px 0 8px 32px; position:relative; }
55
+ .finish li::before { content:"✓"; display:grid; place-items:center; position:absolute; left:0; top:9px; width:21px; height:21px; color:#155e58; background:#ddf4ef; border-radius:6px; font-weight:bold; }
56
+ .help-row { display:grid; grid-template-columns:220px 1fr; gap:14px; padding:13px 0; border-top:1px solid #e6edf5; }
57
+ .help-row p { margin:0; }
58
+ .sources { font-size:13px; color:var(--muted); }
59
+ .sources ul { padding-left:20px; }
60
+ .footnote { color:#64758a; font-size:12px; }
61
+ @media(max-width:720px) { .shell { padding:18px 16px 54px; } .hero { padding:28px 24px; } .step,.filemap,.finish,.trouble { padding:21px; } .step-grid { grid-template-columns:1fr; } .help-row { grid-template-columns:1fr; gap:2px; } th { width:31%; } }
62
+ @media print { @page { size:A4; margin:11mm 13mm; } body { background:white; font-size:9.5pt; line-height:1.42; } .shell { max-width:none; padding:0; } .topbar { display:none; } .hero { border-radius:0; padding:15px 18px; } .hero h1 { font-size:31px; } .subtitle { font-size:15px; } .goal { margin:12px 0 8px; padding:10px 12px; } .route { margin:12px 0; gap:5px; } .route span { padding:6px 8px; } .section-kicker { margin:10px 0 5px; } .step { margin:8px 0; padding:14px 16px; border-radius:12px; box-shadow:none; break-inside:avoid; } .filemap,.finish,.trouble { margin:5px 0; padding:10px 12px; border-radius:12px; box-shadow:none; break-inside:avoid; } .filemap h2,.finish h2,.trouble h2 { margin-bottom:6px; } .step-top { margin-bottom:7px; } .step-num { width:30px; height:30px; } h2 { font-size:18px; } .step-copy p { margin:0 0 7px; } .screen { font-size:8.5pt; } .screen div { padding:7px 9px; } th,td { padding:4px 6px; } .finish li { padding:4px 0 4px 26px; } .finish li::before { top:5px; width:17px; height:17px; } .help-row { padding:5px 0; } .sources { margin-top:6px; font-size:8.5pt; break-inside:avoid; } .sources ul { margin:3px 0; } .footnote { margin:3px 0; font-size:7.5pt; } a { color:#174781; } }
63
+ </style>
64
+ </head>
65
+ <body>
66
+ <main class="shell">
67
+ <nav class="topbar" aria-label="Guide navigation"><a class="brand" href="./index.html">← Back to App</a><div class="top-actions"><a href="./index.html">Open app</a><a href="./how-to-start.pdf" download>Download PDF</a></div></nav>
68
+ <header class="hero"><p class="eyebrow">STUDENT GUIDE - HUGGING FACE SPACES</p><h1>How to Start</h1><p class="subtitle">Turn the course demo into your own AI mini app</p><p class="goal">Your finish line: a public Space under your own account that shows what your AI app does. Submit its Space link so your instructor can open and try your work quickly.</p><p class="time">You can follow the basic route entirely in your browser. No Git commands are needed.</p></header>
69
+ <div class="route" aria-label="The route"><span>Sign up</span><b>→</b><span>Duplicate</span><b>→</b><span>Change the app</span><b>→</b><span>Test</span><b>→</b><span>Submit your URL</span></div>
70
+ <p class="section-kicker">The seven steps</p>
71
+ <section class="step" id="step-01"><div class="step-top"><span class="step-num">01</span><h2>Create your Hugging Face account</h2></div><div class="step-grid"><div class="step-copy"><p>Open <a href="https://huggingface.co/join" target="_blank" rel="noopener noreferrer">https://huggingface.co/join</a>. Enter an email address you check often. Your Gmail address, or the email you use for GitHub, is fine.</p><p>Create a password, click Next, and complete the account steps shown. Sign in when you are done.</p></div><aside class="screen"><span class="screen-label">On the sign-up page</span><div>Join Hugging Face</div><div>Email Address → Password → Next</div></aside></div></section>
72
+ <section class="step" id="step-02"><div class="step-top"><span class="step-num">02</span><h2>Explore the starter demo</h2></div><div class="step-grid"><div class="step-copy"><p>Open <a href="./index.html">this image-classification Space</a>. In App, choose an example image and try Run AI Classification. The first run may take longer while the selected model downloads. Try Shuffle, compare two classifiers on one image, and inspect the score changes.</p><p>Open Files to see the files you will receive in your own copy. You are looking at a working example, not a blank project.</p></div><aside class="screen"><span class="screen-label">On the starter Space</span><div>App | Files | Community | More (three dots)</div><div>Choose an image → Choose a classifier → Run AI Classification</div></aside></div></section>
73
+ <section class="step" id="step-03"><div class="step-top"><span class="step-num">03</span><h2>Duplicate it into your account</h2></div><div class="step-grid"><div class="step-copy"><p>On the starter Space, open the three-dot menu at the top right and choose Duplicate this Space.</p><p>Set Owner to your own account and give the Space a clear name. Set Visibility to Public so your instructor can open it. The duplicate form starts with Private selected.</p><p>Click Duplicate Space. The complete starter project is copied for you; you do not need to paste each code file by hand.</p></div><aside class="screen"><span class="screen-label">The two clicks to find</span><div>Top-right menu (three dots) → Duplicate this Space</div><div>Owner: your account | Space name: your-project</div><div>Visibility: Public → Duplicate Space</div></aside></div></section>
74
+ <section class="step" id="step-04"><div class="step-top"><span class="step-num">04</span><h2>Make a first edit in your copy</h2></div><div class="step-grid"><div class="step-copy"><p>Open your new Space. Select Files, open index.html, and use Edit to change the visible title and short introduction to describe your idea.</p><p>Save with a short commit message using Commit changes to main. Then return to App and check that your new text appears.</p><p>To add a new file or upload a replacement, use Files → Add file. Save the change with a commit.</p></div><aside class="screen"><span class="screen-label">Browser editing route</span><div>Your Space → Files → index.html → Edit</div><div>Change text → Commit changes to main → App</div></aside></div></section>
75
+ <section class="step" id="step-05"><div class="step-top"><span class="step-num">05</span><h2>Build your AI mini app</h2></div><div class="step-grid"><div class="step-copy"><p>You may keep improving image classification or change the template into another AI application. For classification, useful extensions include comparing models, changing CLIP candidate labels, testing a new image domain, and documenting failure cases. Give visitors a clear title, a short explanation, an obvious input, and a result they can understand.</p><p>Edit the relevant files below. Keep the README.md configuration lines sdk: static and app_file: index.html while using this browser-based route.</p><p>This Static Space runs HTML, CSS, and browser JavaScript. Uploading a Python file alone will not run a Python server. A server-based app needs a different Space type and may require a paid plan; check with your instructor before taking that route.</p><p>Never place an API key or access token in public HTML or JavaScript files.</p></div></div></section>
76
+ <section class="step" id="step-06"><div class="step-top"><span class="step-num">06</span><h2>Help your instructor understand it fast</h2></div><div class="step-grid"><div class="step-copy"><p>Make the App page answer these questions in the first few seconds: What does it do? What should I try? What result should I expect?</p><p>Update README.md with a brief project summary: purpose, input and output, AI model or service, what you changed from the starter, and one test or limitation.</p></div><aside class="screen"><span class="screen-label">Copy this mini summary into README.md</span><div>My app: [one-sentence purpose]</div><div>Input → output: [what a visitor provides and receives]</div><div>AI model/service: [name and link]</div><div>I changed: [your main additions]</div><div>Test / limitation: [one honest observation]</div></aside></div></section>
77
+ <section class="step" id="step-07"><div class="step-top"><span class="step-num">07</span><h2>Test and submit</h2></div><div class="step-grid"><div class="step-copy"><p>Return to App and wait for the Space to finish updating. Try at least one real input from beginning to end and check the output. If a model loads for the first time, allow extra time.</p><p>Open your Space link in a private browser window to check that other people can view it. If it shows 404, check Settings → Visibility and make it Public.</p><p>Submit the Space page URL, not the embedded .hf.space address, plus two sentences saying what your app does and what you changed.</p></div><aside class="screen"><span class="screen-label">Submit this URL shape</span><div>https://huggingface.co/spaces/your-username/your-project-name</div></aside></div></section>
78
+ <section class="filemap"><h2>Which file should I edit?</h2><table><tbody><tr><th scope='row'><code>index.html</code></th><td>Page structure, visible title, instructions and input/output areas</td></tr><tr><th scope='row'><code>style.css</code></th><td>Colours, spacing and layout</td></tr><tr><th scope='row'><code>app.js</code></th><td>Buttons, inputs and result display</td></tr><tr><th scope='row'><code>classifier.js</code></th><td>The starter&#x27;s image-classification model call; adapt or replace for a new task</td></tr><tr><th scope='row'><code>README.md</code></th><td>Space title/configuration and the summary your instructor can scan</td></tr></tbody></table></section>
79
+ <section class="finish"><h2>Before you submit</h2><ul><li>My Space is Public and opens from a private browser window.</li><li>The App page explains my project and a visitor can try it.</li><li>At least one input produces a useful result.</li><li>README.md says what I changed and names the AI model or service.</li><li>I submitted the Hugging Face Space page URL and a two-sentence summary.</li></ul></section>
80
+ <section class="trouble"><h2>If you get stuck</h2><div class='help-row'><strong>My teacher sees 404</strong><p>Check Settings → Visibility. A Private Space is only visible to its owner.</p></div><div class='help-row'><strong>My old page still appears</strong><p>Check that the edit was committed, then refresh App after the Space updates.</p></div><div class='help-row'><strong>The AI result does not appear</strong><p>Try a known example, allow first-time model download, and check that your model can run in the browser.</p></div><div class='help-row'><strong>I need Python on a server</strong><p>Ask your instructor about a Gradio or Docker Space and check current account requirements before changing SDK.</p></div></section>
81
+ <footer class="sources"><strong>Official Hugging Face references</strong><ul><li><a href="https://huggingface.co/docs/hub/spaces-overview" target="_blank" rel="noopener noreferrer">Spaces overview and duplication</a></li><li><a href="https://huggingface.co/docs/hub/spaces-sdks-static" target="_blank" rel="noopener noreferrer">Static HTML Spaces</a></li><li><a href="https://huggingface.co/docs/hub/repositories-getting-started" target="_blank" rel="noopener noreferrer">Editing files in the browser</a></li></ul><p class="footnote">Hugging Face labels and account rules can change. If a button looks different, use the linked official help pages.</p></footer>
82
+ </main>
83
+ </body>
84
+ </html>
how-to-start.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:52b60ca207ea231e030f07bdb14a0b2306b5d30a71c13696c0aef64ed189dd5c
3
+ size 161332
index.html CHANGED
@@ -6,10 +6,15 @@
6
  <meta name="description" content="AI-Powered Image Classification mini-lab using pretrained Hugging Face models">
7
  <title>AI-Powered Image Classification</title>
8
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🖼️</text></svg>">
9
- <link rel="stylesheet" href="./style.css?v=3">
10
  </head>
11
  <body>
12
  <main class="page-shell">
 
 
 
 
 
13
  <header class="hero">
14
  <p class="eyebrow">Creative Technology · Computer Vision</p>
15
  <h1>AI-Powered Image Classification</h1>
@@ -34,8 +39,9 @@
34
  <div class="sample-head example-head">
35
  <div>
36
  <p class="input-kicker">Start here · Example images</p>
37
- <p class="helper">Use one image across several models for a fair comparison.</p>
38
  </div>
 
39
  </div>
40
  <div id="sample-grid" class="sample-grid" aria-label="Example images"></div>
41
  <div class="or-row"><span>or try your own</span></div>
@@ -95,6 +101,12 @@
95
 
96
  <div id="summary" class="summary">No predictions yet.</div>
97
 
 
 
 
 
 
 
98
  <div class="table-wrap">
99
  <table>
100
  <thead><tr><th>Rank</th><th>Label</th><th>Score</th></tr></thead>
@@ -118,8 +130,33 @@
118
  <p class="extension-note"><strong>Compare models:</strong> keep the image fixed, switch classifier, and observe how labels, scores, and speed change.</p>
119
  </section>
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  <footer>Hosted as a Hugging Face Static Space · Powered by Transformers.js</footer>
122
  </main>
123
- <script type="module" src="./app.js"></script>
124
  </body>
125
  </html>
 
6
  <meta name="description" content="AI-Powered Image Classification mini-lab using pretrained Hugging Face models">
7
  <title>AI-Powered Image Classification</title>
8
  <link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>🖼️</text></svg>">
9
+ <link rel="stylesheet" href="./style.css?v=4">
10
  </head>
11
  <body>
12
  <main class="page-shell">
13
+ <nav class="guide-linkbar" aria-label="Course guide">
14
+ <span>Building your own AI mini app?</span>
15
+ <a href="./how-to-start.html">How to Start <span aria-hidden="true">→</span></a>
16
+ </nav>
17
+
18
  <header class="hero">
19
  <p class="eyebrow">Creative Technology · Computer Vision</p>
20
  <h1>AI-Powered Image Classification</h1>
 
39
  <div class="sample-head example-head">
40
  <div>
41
  <p class="input-kicker">Start here · Example images</p>
42
+ <p class="helper">Four images are drawn at random from eight tested teaching samples.</p>
43
  </div>
44
+ <button id="shuffle-examples" class="shuffle-button" type="button">Shuffle</button>
45
  </div>
46
  <div id="sample-grid" class="sample-grid" aria-label="Example images"></div>
47
  <div class="or-row"><span>or try your own</span></div>
 
101
 
102
  <div id="summary" class="summary">No predictions yet.</div>
103
 
104
+ <div id="run-meta" class="run-meta" hidden>
105
+ <span><b>Model</b><span id="meta-model">—</span></span>
106
+ <span><b>Image</b><span id="meta-image">—</span></span>
107
+ <span><b>Runtime</b><span id="meta-runtime">—</span></span>
108
+ </div>
109
+
110
  <div class="table-wrap">
111
  <table>
112
  <thead><tr><th>Rank</th><th>Label</th><th>Score</th></tr></thead>
 
130
  <p class="extension-note"><strong>Compare models:</strong> keep the image fixed, switch classifier, and observe how labels, scores, and speed change.</p>
131
  </section>
132
 
133
+ <section class="history card" aria-labelledby="history-title">
134
+ <div class="history-head">
135
+ <div>
136
+ <p class="section-kicker">Comparison log</p>
137
+ <h2 id="history-title" class="explain-title">Keep one image fixed and compare model decisions.</h2>
138
+ <p class="history-copy">Each successful run is added below. This makes the classroom comparison visible without reloading the page.</p>
139
+ </div>
140
+ <button id="clear-history" class="secondary-button" type="button" disabled>Clear log</button>
141
+ </div>
142
+ <div class="table-wrap">
143
+ <table>
144
+ <thead><tr><th>Run</th><th>Image</th><th>Model</th><th>Top prediction</th><th>Score</th><th>Time</th></tr></thead>
145
+ <tbody id="history-body">
146
+ <tr class="empty-row"><td colspan="6">Run two models on the same image to start a comparison.</td></tr>
147
+ </tbody>
148
+ </table>
149
+ </div>
150
+ </section>
151
+
152
+ <section class="runtime-note card" aria-label="Runtime and privacy notes">
153
+ <div><b>First run</b><span>Downloads the selected quantized model from Hugging Face.</span></div>
154
+ <div><b>Later runs</b><span>Can reuse the model stored in the browser cache.</span></div>
155
+ <div><b>Your image</b><span>Is processed in this browser and is not sent to an inference server.</span></div>
156
+ </section>
157
+
158
  <footer>Hosted as a Hugging Face Static Space · Powered by Transformers.js</footer>
159
  </main>
160
+ <script type="module" src="./app.js?v=4"></script>
161
  </body>
162
  </html>
style.css CHANGED
@@ -21,6 +21,25 @@ button, input, select, textarea { font: inherit; }
21
  padding: 28px 0 24px;
22
  }
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  .hero { width: 100%; margin-bottom: 20px; }
25
  .eyebrow, .section-kicker {
26
  margin: 0 0 10px;
@@ -91,6 +110,20 @@ h1 {
91
  .control-label { font-weight: 700; }
92
  .helper { margin: 6px 0 0; color: #667085; font-size: .92rem; line-height: 1.5; }
93
  .sample-title { margin: 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  .input-kicker {
95
  margin: 0 0 4px;
96
  color: #344054;
@@ -131,6 +164,7 @@ h1 {
131
  text-overflow: ellipsis;
132
  white-space: nowrap;
133
  }
 
134
 
135
  .or-row { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: #98a2b3; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
136
  .or-row::before, .or-row::after { content: ''; height: 1px; flex: 1; background: #eceff4; }
@@ -191,12 +225,25 @@ textarea { resize: vertical; line-height: 1.45; }
191
  #preview-placeholder { margin: 0; padding: 32px; color: #9aa4b2; text-align: center; }
192
  .preview-wrap:not(.empty) #preview-placeholder { display: none; }
193
  .summary { margin: 16px 0; padding: 13px 15px; border-radius: 13px; background: #f7f8fa; color: #344054; font-weight: 650; line-height: 1.5; }
 
 
 
 
 
 
 
 
 
 
194
  .table-wrap { overflow-x: auto; border: 1px solid #e8ebf0; border-radius: 14px; }
195
  table { width: 100%; border-collapse: collapse; font-size: .9rem; }
196
  th, td { padding: 11px 13px; border-bottom: 1px solid #edf0f4; text-align: left; vertical-align: top; }
197
  th { background: #fafbfc; color: #52627a; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
198
  tbody tr:last-child td { border-bottom: 0; }
199
  .empty-row td { color: #7d899a; text-align: center; }
 
 
 
200
 
201
  .explain { margin-top: 16px; padding: 18px 24px; }
202
  .explain-title { margin: 0; font-size: clamp(1.15rem, 1.8vw, 1.45rem); line-height: 1.25; letter-spacing: -.02em; }
@@ -205,6 +252,16 @@ tbody tr:last-child td { border-bottom: 0; }
205
  .flow span:not(.arrow) { padding: 8px 11px; border-radius: 10px; background: #f2f4f7; }
206
  .arrow { color: #98a2b3; }
207
  .extension-note { margin: 12px 0 0; padding-top: 11px; border-top: 1px solid #eceff4; color: #5d6879; font-size: .92rem; line-height: 1.5; }
 
 
 
 
 
 
 
 
 
 
208
  footer { padding: 14px 2px 0; color: #7a8595; font-size: .84rem; }
209
 
210
  @media (max-width: 820px) {
@@ -212,11 +269,15 @@ footer { padding: 14px 2px 0; color: #7a8595; font-size: .84rem; }
212
  .workspace { grid-template-columns: 1fr; }
213
  .result { position: static; }
214
  .preview-wrap { min-height: 280px; }
 
215
  }
216
 
217
  @media (max-width: 520px) {
218
  .card { border-radius: 17px; }
219
- .controls, .result, .explain { padding: 18px; }
220
  .result-head { align-items: center; }
 
 
 
221
  th, td { padding: 9px 10px; }
222
  }
 
21
  padding: 28px 0 24px;
22
  }
23
 
24
+ .guide-linkbar {
25
+ display: flex;
26
+ align-items: center;
27
+ justify-content: space-between;
28
+ flex-wrap: wrap;
29
+ gap: 10px;
30
+ margin: 0 0 24px;
31
+ padding: 11px 15px;
32
+ border: 1px solid #d6e3f4;
33
+ border-radius: 14px;
34
+ background: #edf5ff;
35
+ color: #334965;
36
+ font-size: .9rem;
37
+ font-weight: 700;
38
+ }
39
+ .guide-linkbar a { display: inline-flex; align-items: center; gap: 5px; border-radius: 8px; color: #174f9e; font-weight: 800; text-decoration: none; }
40
+ .guide-linkbar a:hover { text-decoration: underline; }
41
+ .guide-linkbar a:focus-visible { outline: 3px solid #f7b844; outline-offset: 3px; }
42
+
43
  .hero { width: 100%; margin-bottom: 20px; }
44
  .eyebrow, .section-kicker {
45
  margin: 0 0 10px;
 
110
  .control-label { font-weight: 700; }
111
  .helper { margin: 6px 0 0; color: #667085; font-size: .92rem; line-height: 1.5; }
112
  .sample-title { margin: 0; }
113
+ .sample-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
114
+ .shuffle-button {
115
+ flex: 0 0 auto;
116
+ padding: 7px 10px;
117
+ border: 1px solid #d8dee8;
118
+ border-radius: 10px;
119
+ background: #fff;
120
+ color: #344054;
121
+ cursor: pointer;
122
+ font-size: .82rem;
123
+ font-weight: 700;
124
+ }
125
+ .shuffle-button:hover:not(:disabled) { background: #f7f8fa; }
126
+ .shuffle-button:disabled { opacity: .45; cursor: not-allowed; }
127
  .input-kicker {
128
  margin: 0 0 4px;
129
  color: #344054;
 
164
  text-overflow: ellipsis;
165
  white-space: nowrap;
166
  }
167
+ .sample-card small { display: block; padding: 0 9px 9px; color: #8a94a4; font-size: .67rem; line-height: 1.2; letter-spacing: .01em; }
168
 
169
  .or-row { display: flex; align-items: center; gap: 10px; margin: 18px 0 14px; color: #98a2b3; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
170
  .or-row::before, .or-row::after { content: ''; height: 1px; flex: 1; background: #eceff4; }
 
225
  #preview-placeholder { margin: 0; padding: 32px; color: #9aa4b2; text-align: center; }
226
  .preview-wrap:not(.empty) #preview-placeholder { display: none; }
227
  .summary { margin: 16px 0; padding: 13px 15px; border-radius: 13px; background: #f7f8fa; color: #344054; font-weight: 650; line-height: 1.5; }
228
+ .run-meta {
229
+ display: grid;
230
+ grid-template-columns: repeat(3, minmax(0, 1fr));
231
+ gap: 8px;
232
+ margin: -5px 0 16px;
233
+ }
234
+ .run-meta[hidden] { display: none; }
235
+ .run-meta > span { min-width: 0; padding: 9px 10px; border: 1px solid #e8ebf0; border-radius: 11px; background: #fff; }
236
+ .run-meta b { display: block; margin-bottom: 3px; color: #7a8595; font-size: .7rem; letter-spacing: .05em; text-transform: uppercase; }
237
+ .run-meta span span { display: block; overflow: hidden; color: #344054; font-size: .82rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
238
  .table-wrap { overflow-x: auto; border: 1px solid #e8ebf0; border-radius: 14px; }
239
  table { width: 100%; border-collapse: collapse; font-size: .9rem; }
240
  th, td { padding: 11px 13px; border-bottom: 1px solid #edf0f4; text-align: left; vertical-align: top; }
241
  th { background: #fafbfc; color: #52627a; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
242
  tbody tr:last-child td { border-bottom: 0; }
243
  .empty-row td { color: #7d899a; text-align: center; }
244
+ .score-wrap { display: grid; grid-template-columns: 58px minmax(70px, 1fr); gap: 9px; align-items: center; font-variant-numeric: tabular-nums; }
245
+ .score-track { display: block; height: 7px; overflow: hidden; border-radius: 999px; background: #edf0f5; }
246
+ .score-fill { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #111827, #5e6c84); }
247
 
248
  .explain { margin-top: 16px; padding: 18px 24px; }
249
  .explain-title { margin: 0; font-size: clamp(1.15rem, 1.8vw, 1.45rem); line-height: 1.25; letter-spacing: -.02em; }
 
252
  .flow span:not(.arrow) { padding: 8px 11px; border-radius: 10px; background: #f2f4f7; }
253
  .arrow { color: #98a2b3; }
254
  .extension-note { margin: 12px 0 0; padding-top: 11px; border-top: 1px solid #eceff4; color: #5d6879; font-size: .92rem; line-height: 1.5; }
255
+ .history { margin-top: 16px; padding: 20px 24px 24px; }
256
+ .history-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 15px; }
257
+ .history-copy { margin: 8px 0 0; color: #5d6879; font-size: .92rem; line-height: 1.5; }
258
+ .secondary-button { flex: 0 0 auto; padding: 9px 12px; border: 1px solid #cfd7e3; border-radius: 11px; background: #fff; color: #344054; font-weight: 700; cursor: pointer; }
259
+ .secondary-button:hover:not(:disabled) { border-color: #8f9bad; }
260
+ .secondary-button:disabled { opacity: .45; cursor: not-allowed; }
261
+ .runtime-note { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin-top: 16px; overflow: hidden; background: #e5e9f0; }
262
+ .runtime-note div { padding: 16px 18px; background: rgba(255,255,255,.96); }
263
+ .runtime-note b { display: block; margin-bottom: 5px; color: #111827; font-size: .88rem; }
264
+ .runtime-note span { color: #667085; font-size: .84rem; line-height: 1.45; }
265
  footer { padding: 14px 2px 0; color: #7a8595; font-size: .84rem; }
266
 
267
  @media (max-width: 820px) {
 
269
  .workspace { grid-template-columns: 1fr; }
270
  .result { position: static; }
271
  .preview-wrap { min-height: 280px; }
272
+ .runtime-note { grid-template-columns: 1fr; }
273
  }
274
 
275
  @media (max-width: 520px) {
276
  .card { border-radius: 17px; }
277
+ .controls, .result, .explain, .history { padding: 18px; }
278
  .result-head { align-items: center; }
279
+ .run-meta { grid-template-columns: 1fr; }
280
+ .history-head { display: block; }
281
+ .secondary-button { margin-top: 12px; }
282
  th, td { padding: 9px 10px; }
283
  }