coyotte508 HF staff commited on
Commit
d2576ab
1 Parent(s): a66507e

♻️ Convert to image to text

Browse files
Files changed (2) hide show
  1. README.md +3 -4
  2. index.html +14 -26
README.md CHANGED
@@ -1,15 +1,14 @@
1
  ---
2
- title: Streaming Text Generation
3
  emoji: 📚
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: static
7
  pinned: false
8
  license: mit
9
- description: Showcase streaming text generation using huggingface.js
10
- duplicated_from: huggingfacejs/streaming-text-generation
11
  ---
12
 
13
  Showcase streaming text generation using the `@huggingface/inference` JS lib.
14
 
15
- Default model for inference: https://huggingface.co/google/flan-t5-xxl
 
1
  ---
2
+ title: Image to text
3
  emoji: 📚
4
  colorFrom: pink
5
  colorTo: indigo
6
  sdk: static
7
  pinned: false
8
  license: mit
9
+ description: Showcase image captioning using huggingface.js
 
10
  ---
11
 
12
  Showcase streaming text generation using the `@huggingface/inference` JS lib.
13
 
14
+ Default model for inference: https://huggingface.co/nlpconnect/vit-gpt2-image-captioning
index.html CHANGED
@@ -9,7 +9,7 @@
9
  <script type="importmap">
10
  {
11
  "imports": {
12
- "@huggingface/inference": "https://cdn.jsdelivr.net/npm/@huggingface/inference@1.7.1/+esm"
13
  }
14
  }
15
  </script>
@@ -20,7 +20,7 @@
20
  <span
21
  class="bg-clip-text text-transparent bg-gradient-to-r from-pink-500 to-violet-500"
22
  >
23
- Streaming text generation demo with
24
  <a href="https://github.com/huggingface/huggingface.js">
25
  <kbd>@huggingface/inference</kbd>
26
  </a>
@@ -46,10 +46,9 @@
46
  />
47
 
48
  <p class="mt-8">
49
- Pick the model you want to run. Check out over 10k models for text to
50
- text generation
51
  <a
52
- href="https://huggingface.co/models?pipeline_tag=text2text-generation&sort=likes"
53
  class="underline text-blue-500"
54
  target="_blank"
55
  >
@@ -57,27 +56,22 @@
57
  >
58
  </p>
59
 
60
- <!-- Default model: https://huggingface.co/google/flan-t5-xxl -->
61
  <input
62
  type="text"
63
  id="model"
64
  class="rounded border-2 border-blue-500 shadow-md px-3 py-2 w-96 mt-6"
65
- value="google/flan-t5-xxl"
66
  required
67
  />
68
 
69
- <p class="mt-8">Finally the prompt</p>
70
 
71
- <textarea
72
  class="rounded border-blue-500 shadow-md px-3 py-2 w-96 mt-6 block"
73
  rows="5"
74
  id="prompt"
75
- >
76
- Q: How is butter made?
77
-
78
- Describe the process from the beginning
79
- </textarea
80
- >
81
 
82
  <button
83
  id="submit"
@@ -91,7 +85,7 @@ Describe the process from the beginning
91
  Output will be here
92
  </div>
93
 
94
- <p>Check out the <a class="underline text-blue-500" href="https://huggingface.co/spaces/huggingfacejs/streaming-text-generation/blob/main/index.html" target="_blank">source code</a></p>
95
  </form>
96
 
97
  <script type="module">
@@ -108,18 +102,12 @@ Describe the process from the beginning
108
  document.getElementById("token").value.trim() || undefined
109
  );
110
  const model = document.getElementById("model").value.trim();
111
- const prompt = document.getElementById("prompt").value.trim();
112
  document.getElementById("logs").textContent = "";
113
 
114
- for await (const output of hf.textGenerationStream({
115
- model,
116
- inputs: prompt,
117
- parameters: { max_new_tokens: 250 }
118
- }, {
119
- use_cache: false
120
- })) {
121
- document.getElementById("logs").textContent += output.token.text;
122
- }
123
  } catch (err) {
124
  alert("Error: " + err.message);
125
  } finally {
 
9
  <script type="importmap">
10
  {
11
  "imports": {
12
+ "@huggingface/inference": "https://cdn.jsdelivr.net/npm/@huggingface/inference@1.8.0/+esm"
13
  }
14
  }
15
  </script>
 
20
  <span
21
  class="bg-clip-text text-transparent bg-gradient-to-r from-pink-500 to-violet-500"
22
  >
23
+ Image to text demo with
24
  <a href="https://github.com/huggingface/huggingface.js">
25
  <kbd>@huggingface/inference</kbd>
26
  </a>
 
46
  />
47
 
48
  <p class="mt-8">
49
+ Pick the model you want to run. Check out over 100 models for image to text
 
50
  <a
51
+ href="https://huggingface.co/tasks/image-to-text"
52
  class="underline text-blue-500"
53
  target="_blank"
54
  >
 
56
  >
57
  </p>
58
 
59
+ <!-- Default model: https://huggingface.co/nlpconnect/vit-gpt2-image-captioning -->
60
  <input
61
  type="text"
62
  id="model"
63
  class="rounded border-2 border-blue-500 shadow-md px-3 py-2 w-96 mt-6"
64
+ value="nlpconnect/vit-gpt2-image-captioning"
65
  required
66
  />
67
 
68
+ <p class="mt-8">Finally the input image</p>
69
 
70
+ <input type="file" required accept="image/*"
71
  class="rounded border-blue-500 shadow-md px-3 py-2 w-96 mt-6 block"
72
  rows="5"
73
  id="prompt"
74
+ />
 
 
 
 
 
75
 
76
  <button
77
  id="submit"
 
85
  Output will be here
86
  </div>
87
 
88
+ <p>Check out the <a class="underline text-blue-500" href="https://huggingface.co/spaces/huggingfacejs/image-to-text/blob/main/index.html" target="_blank">source code</a></p>
89
  </form>
90
 
91
  <script type="module">
 
102
  document.getElementById("token").value.trim() || undefined
103
  );
104
  const model = document.getElementById("model").value.trim();
105
+ const prompt = document.getElementById("prompt").files[0];
106
  document.getElementById("logs").textContent = "";
107
 
108
+ const {generated_text} = await hf.imageToText({model, data: prompt});
109
+
110
+ document.getElementById("logs").textContent = generated_text;
 
 
 
 
 
 
111
  } catch (err) {
112
  alert("Error: " + err.message);
113
  } finally {