P05 commited on
Commit
8dc674a
·
verified ·
1 Parent(s): 5781b3a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +39 -19
index.html CHANGED
@@ -1,19 +1,39 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>