P05 commited on
Commit
0a68cc2
·
verified ·
1 Parent(s): 45a38ee

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +26 -31
index.html CHANGED
@@ -25,39 +25,34 @@
25
  </div>
26
 
27
  <script type="module">
28
-
29
-
30
  import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0';
31
- // Example for Transformers.js / HF JS SDK
32
- const tokenizer = await AutoTokenizer.from_pretrained('onnx-community/gpt2', {
33
- token: 'hf_YOUR_USER_ACCESS_TOKEN'
34
- const btn = document.getElementById('predict-btn');
35
- const output = document.getElementById('output');
36
- let generator = null;
37
-
38
- btn.addEventListener('click', async () => {
39
- const text = document.getElementById('prompt').value.trim();
40
- if (!text) return;
41
-
42
- btn.disabled = true;
43
- output.innerHTML = '<span class="status">Loading ONNX model into browser memory... (takes a few seconds on first run)</span>';
44
-
45
- try {
46
- if (!generator) {
47
- generator = await pipeline('text-generation', 'onnx-community/gpt2');
48
- }
49
-
50
- output.innerHTML = '<span class="status">Generating prediction...</span>';
51
- const result = await generator(text, { max_new_tokens: 25, temperature: 0.7 });
52
-
53
- output.innerText = result[0].generated_text;
54
- } catch (err) {
55
- output.innerText = 'Error: ' + err.message;
56
- } finally {
57
- btn.disabled = false;
58
  }
59
 
60
- });
61
- </script>
 
 
 
 
 
 
 
 
 
62
  </body>
63
  </html>
 
25
  </div>
26
 
27
  <script type="module">
 
 
28
  import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0';
29
+
30
+ const btn = document.getElementById('predict-btn');
31
+ const output = document.getElementById('output');
32
+ let generator = null;
33
+
34
+ btn.addEventListener('click', async () => {
35
+ const text = document.getElementById('prompt').value.trim();
36
+ if (!text) return;
37
+
38
+ btn.disabled = true;
39
+ output.innerHTML = '<span class="status">Loading ONNX model into browser memory... (takes a few seconds on first run)</span>';
40
+
41
+ try {
42
+ if (!generator) {
43
+ generator = await pipeline('text-generation', 'onnx-community/gpt2');
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
 
46
+ output.innerHTML = '<span class="status">Generating prediction...</span>';
47
+ const result = await generator(text, { max_new_tokens: 25, temperature: 0.7 });
48
+
49
+ output.innerText = result[0].generated_text;
50
+ } catch (err) {
51
+ output.innerText = 'Error: ' + err.message;
52
+ } finally {
53
+ btn.disabled = false;
54
+ }
55
+ });
56
+ </script>
57
  </body>
58
  </html>