File size: 8,069 Bytes
f00d817
011f1af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43a0654
011f1af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f00d817
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
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="An image captioning mini-lab using pretrained Hugging Face models.">
  <title>AI-Powered Image Captioning</title>
  <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>">
  <link rel="stylesheet" href="./style.css">
  <link rel="stylesheet" href="./captioning.css">
</head>
<body>
  <main class="page-shell">
    <nav class="guide-linkbar" aria-label="Course guide">
      <span>Building your own AI mini app?</span>
      <a href="./how-to-start.html">How to Start <span aria-hidden="true">→</span></a>
    </nav>
    <header class="hero">
      <p class="eyebrow">Creative Technology · Computer Vision</p>
      <h1>AI-Powered Image Captioning</h1>
      <p class="lede">Choose an example or upload your own image. Then choose a pretrained captioner and let AI answer: <strong>what is happening in this image?</strong></p>
      <div class="lesson-strip" aria-label="Mini-lab overview">
        <span><b>Task</b> Image captioning</span>
        <span><b>Output</b> A description in English</span>
        <span><b>Models</b> ViT-GPT2 · Florence-2 · SmolVLM</span>
      </div>
    </header>
    <section class="workspace" aria-label="Image captioning mini-lab">
      <div class="controls card">
        <div class="step"><span class="step-number">1</span><div>
          <p class="control-label sample-title">Choose an image</p>
          <p class="helper">Start with an example, or try a photo of your own.</p>
        </div></div>
        <div class="sample-head example-head"><div>
          <p class="input-kicker">Start here · Example images</p>
          <p class="helper">Four images from a bank of teaching examples.</p>
        </div><button id="shuffle-examples" class="shuffle-button" type="button" disabled>Shuffle</button></div>
        <div id="sample-grid" class="sample-grid" aria-label="Example images"></div>
        <div class="or-row"><span>or try your own</span></div>
        <label class="control-label" for="image-input">Upload an image</label>
        <p class="helper">PNG, JPEG, or WebP · up to 12 MB.</p>
        <input id="image-input" class="file-input" type="file" accept="image/png,image/jpeg,image/webp">
        <div class="divider"></div>
        <div class="step"><span class="step-number">2</span><div class="grow">
          <label class="control-label" for="model-select">Choose captioner</label>
          <select id="model-select" class="model-select"></select>
          <p id="model-note" class="helper"></p>
        </div></div>
        <div class="divider"></div>
        <div class="step"><span class="step-number">3</span><div class="grow">
          <label class="control-label" for="detail-select">Description style</label>
          <select id="detail-select" class="model-select"><option value="short">Short caption</option><option value="detailed">Detailed description</option></select>
          <p id="detail-note" class="helper"></p>
          <div id="instruction-controls" class="clip-controls" hidden>
            <label class="control-label" for="instruction">Description instruction</label>
            <textarea id="instruction" rows="3" maxlength="400" spellcheck="false">Describe this image in one short sentence.</textarea>
            <p class="helper">Keep the image fixed and change the instruction to compare.</p>
          </div>
          <div class="token-controls">
            <div class="slider-row"><label class="control-label" for="max-tokens">Maximum new tokens</label><output id="token-value" for="max-tokens">64</output></div>
            <input id="max-tokens" type="range" min="32" max="128" value="64" step="16">
            <p class="helper">An output limit, not an exact word count. A low limit may cut a sentence short.</p>
          </div>
        </div></div>
        <button id="run-button" class="run-button" type="button" disabled>Run AI Captioning</button>
        <button id="stop-button" class="secondary-button stop-button" type="button" hidden>Stop this run</button>
        <p id="status" class="status" role="status" aria-live="polite">Choose an example or upload your own image.</p>
        <div id="progress-wrap" class="progress-wrap" hidden><div id="progress-bar" class="progress-bar"></div></div>
      </div>
      <div class="result card">
        <div class="result-head"><div><p class="section-kicker">AI description</p><h2>How does the model describe it?</h2></div><span id="runtime-badge" class="badge">Waiting</span></div>
        <div id="preview-wrap" class="preview-wrap empty"><img id="preview-image" alt="Selected image"><p id="preview-placeholder">Choose an image first. It will appear here before captioning.</p></div>
        <p id="image-source" class="helper" hidden></p>
        <div id="summary" class="summary caption-output" aria-live="polite">No caption yet.</div>
        <div id="run-meta" class="run-meta" hidden>
          <span><b>Model</b><span id="meta-model">—</span></span>
          <span><b>Image</b><span id="meta-image">—</span></span>
          <span><b>Generation time</b><span id="meta-runtime">—</span></span>
        </div>
        <div class="caption-actions"><button id="copy-caption" class="secondary-button" disabled>Copy caption</button><button id="download-caption" class="secondary-button" disabled>Save caption</button></div>
        <div class="table-wrap"><table><thead><tr><th>Check the description</th><th>Look for visual evidence</th></tr></thead><tbody>
          <tr><td>Objects and attributes</td><td>Are the named objects and their details visible?</td></tr>
          <tr><td>Actions and relationships</td><td>Does the sentence explain what is actually happening?</td></tr>
          <tr><td>Missing or added details</td><td>What is omitted? What has the model added without evidence?</td></tr>
        </tbody></table></div>
      </div>
    </section>
    <section class="explain card">
      <p class="section-kicker">What you are doing</p>
      <h2 class="explain-title">Use a learned AI capability instead of rebuilding the traditional task from scratch.</h2>
      <p class="explain-copy">A visual encoder represents the image. A language decoder generates a description. Different models may describe different details, and a fluent sentence can still be wrong.</p>
      <div class="flow" aria-label="Image captioning flow"><span>Example or your image</span><span class="arrow">→</span><span>Selected pretrained captioner</span><span class="arrow">→</span><span>A description in words</span></div>
      <p class="extension-note"><strong>Compare models:</strong> keep the image fixed, switch captioner, and check the objects, actions, and relationships in each sentence.</p>
    </section>
    <section class="history card" aria-labelledby="history-title">
      <div class="history-head"><div><p class="section-kicker">Comparison log</p><h2 id="history-title" class="explain-title">Keep one image fixed and compare descriptions.</h2><p class="history-copy">The latest 12 successful runs stay here until you clear the log or reload. Generation time excludes model loading; download the log to keep the full settings.</p></div><div class="history-actions"><button id="download-history" class="secondary-button" disabled>Download log</button><button id="clear-history" class="secondary-button" disabled>Clear log</button></div></div>
      <div class="table-wrap"><table><thead><tr><th>Run</th><th>Image</th><th>Model</th><th>Caption</th><th>Style</th><th>Time</th></tr></thead><tbody id="history-body"><tr class="empty-row"><td colspan="6">Run two models on the same image to start a comparison.</td></tr></tbody></table></div>
    </section>
    <footer>Hosted as a Hugging Face Static Space · Powered by Transformers.js</footer>
  </main>
  <script type="module" src="./app.js"></script>
</body>
</html>