File size: 3,044 Bytes
f4c1325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8"/>
  <title>Hermes-3 Ultra-Fast Interface</title>
  <meta name="viewport" content="width=device-width,initial-scale=1"/>
  <style>
    body{margin:0;font-family:"Google Sans",Roboto,Arial,sans-serif;background:#f6f8fa;color:#111;min-height:100vh;display:flex;flex-direction:column}
    header{background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.08);padding:.75rem 1.5rem;display:flex;align-items:center}
    header img{height:32px;margin-right:.5rem}
    header span{font-weight:700;font-size:1.25rem}
    main{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:1rem}
    #prompt{width:min(600px,90vw);border:1px solid #d0d7de;border-radius:8px;padding:.75rem 1rem;font-size:1rem;resize:none}
    #prompt:focus{outline:none;border-color:#0969da}
    #generate{background:#0969da;color:#fff;border:none;border-radius:8px;padding:.75rem 1.5rem;font-size:1rem;margin-top:1rem;cursor:pointer}
    #generate:disabled{background:#b6c2d1;cursor:not-allowed}
    #output{white-space:pre-wrap;background:#fff;border:1px solid #d0d7de;border-radius:8px;padding:1rem;margin-top:1rem;max-width:min(600px,90vw);max-height:50vh;overflow:auto}
    #loading{display:none;margin-top:1rem}
  </style>
</head>
<body>
<header>
  <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAYCAMAAAAiV0Z6AAAAPFBMVEVLoEN0wU6CzFKCzFKCzFKCzFKCzFJSo0MSczNDmkCCzFJPoUMTczNdr0gmgziCzFITczMTczMTczMTczPh00jOAAAAFHRSTlPF/+bIsms8Ad///hX+//5/tXw7aMEAx10AAACaSURBVHgBbc4HDoRQCATQ33tbvf9dF9QxaCT9UQaltLHOh/golXKhMs5Xqa0xU1lyoa2fXFyQOsDG38qsLy4TaV+sFislovyhPzLJJrBu6eQOtpW0LjbJkzTuTDLRVNKa3uxJI+VdiRqXSeu6GW+Qxi29eLIi8H7EsYrT42BD+mQtNO5JMjRuC4lSY8V4hsLX0egGijvUSEP9AbylEsOkeCgWAAAAAElFTkSuQmCC"/>
  <span>Hermes-3 Ultra-Fast</span>
</header>

<main>
  <textarea id="prompt" placeholder="Enter your prompt here…" rows="4"></textarea>
  <button id="generate">Generate</button>
  <div id="loading">Loading model…</div>
  <pre id="output"></pre>
</main>

<!-- transformers.js from CDN -->
<script type="module">
import { pipeline } from 'https://cdn.jsdelivr.net/npm/@xenova/[email protected]';

let pipe;

async function init() {
  document.getElementById('loading').style.display='block';
  pipe = await pipeline('text-generation', 'Xenova/Llama-2-7b-chat-hf', {
    dtype: 'q4',
    device: 'auto',
  });
  document.getElementById('loading').style.display='none';
}
init();

document.getElementById('generate').addEventListener('click', async () => {
  const prompt = document.getElementById('prompt').value.trim();
  const outEl = document.getElementById('output');
  const btn = document.getElementById('generate');
  if (!prompt || !pipe) return;
  btn.disabled = true;
  outEl.textContent = '';
  const res = await pipe(prompt, {
    max_new_tokens: 256,
    temperature: .7,
    top_p: .9,
    repetition_penalty: 1.1,
    do_sample: true,
  });
  outEl.textContent = res[0].generated_text.slice(prompt.length);
  btn.disabled = false;
});
</script>
</body>
</html>