Update index.html
Browse files- index.html +39 -19
index.html
CHANGED
|
@@ -1,19 +1,39 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>GPT-2 Static Demo</title>
|
| 6 |
+
<style>
|
| 7 |
+
body { font-family: sans-serif; max-width: 600px; margin: 40px auto; padding: 0 20px; }
|
| 8 |
+
textarea { width: 100%; height: 100px; margin-bottom: 10px; }
|
| 9 |
+
button { padding: 10px 20px; cursor: pointer; }
|
| 10 |
+
#output { margin-top: 20px; padding: 15px; background: #f4f4f4; border-radius: 5px; white-space: pre-wrap; }
|
| 11 |
+
</style>
|
| 12 |
+
</head>
|
| 13 |
+
<body>
|
| 14 |
+
<h2>GPT-2 Browser Demo (Static SDK)</h2>
|
| 15 |
+
<textarea id="prompt" placeholder="Enter prompt...">Once upon a time,</textarea>
|
| 16 |
+
<button id="generate-btn">Generate Text</button>
|
| 17 |
+
<div id="output">Output will appear here...</div>
|
| 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('generate-btn');
|
| 23 |
+
const output = document.getElementById('output');
|
| 24 |
+
let generator = null;
|
| 25 |
+
|
| 26 |
+
btn.addEventListener('click', async () => {
|
| 27 |
+
const prompt = document.getElementById('prompt').value;
|
| 28 |
+
output.innerText = 'Loading model and generating text...';
|
| 29 |
+
|
| 30 |
+
if (!generator) {
|
| 31 |
+
generator = await pipeline('text-generation', 'onnx-community/gpt2');
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
const result = await generator(prompt, { max_new_tokens: 30 });
|
| 35 |
+
output.innerText = result[0].generated_text;
|
| 36 |
+
});
|
| 37 |
+
</script>
|
| 38 |
+
</body>
|
| 39 |
+
</html>
|