Update index.html
Browse files- index.html +36 -17
index.html
CHANGED
|
@@ -2,37 +2,56 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<
|
|
|
|
| 6 |
<style>
|
| 7 |
-
body { font-family: sans-serif; max-width:
|
| 8 |
-
textarea { width: 100%; height:
|
| 9 |
-
button { padding:
|
| 10 |
-
#output { margin-top: 20px; padding: 15px; background: #
|
|
|
|
| 11 |
</style>
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
-
<h2>GPT-2
|
| 15 |
-
<
|
| 16 |
-
|
| 17 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
<script type="module">
|
| 20 |
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.0.0';
|
| 21 |
|
| 22 |
-
const btn = document.getElementById('
|
| 23 |
const output = document.getElementById('output');
|
| 24 |
let generator = null;
|
| 25 |
|
| 26 |
btn.addEventListener('click', async () => {
|
| 27 |
-
const
|
| 28 |
-
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
}
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
});
|
| 37 |
</script>
|
| 38 |
</body>
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>GPT-2 Text Predictor</title>
|
| 7 |
<style>
|
| 8 |
+
body { font-family: system-ui, sans-serif; max-width: 650px; margin: 40px auto; padding: 0 20px; }
|
| 9 |
+
textarea { width: 100%; height: 120px; font-size: 16px; padding: 10px; box-sizing: border-box; }
|
| 10 |
+
button { padding: 12px 24px; font-size: 16px; margin-top: 10px; cursor: pointer; }
|
| 11 |
+
#output { margin-top: 20px; padding: 15px; background: #f0f0f0; border-radius: 6px; white-space: pre-wrap; font-size: 16px; }
|
| 12 |
+
.status { color: #666; font-style: italic; }
|
| 13 |
</style>
|
| 14 |
</head>
|
| 15 |
<body>
|
| 16 |
+
<h2>GPT-2 Text Prediction (Static SDK)</h2>
|
| 17 |
+
<p>Enter a prompt below to generate predictions client-side:</p>
|
| 18 |
+
|
| 19 |
+
<textarea id="prompt" placeholder="Type starting text here...">The future of artificial intelligence is</textarea>
|
| 20 |
+
<br>
|
| 21 |
+
<button id="predict-btn">Predict Next Words</button>
|
| 22 |
+
|
| 23 |
+
<div id="output">
|
| 24 |
+
<span class="status">Click "Predict Next Words" to run the model directly in your browser.</span>
|
| 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>
|