Commit
·
f5623e6
0
Parent(s):
Super-squash branch 'main' using huggingface_hub
Browse files- .gitattributes +35 -0
- README.md +12 -0
- index.html +446 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Falcon-H1-Tiny-90M WebGPU
|
| 3 |
+
emoji: 🦅
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: static
|
| 7 |
+
pinned: false
|
| 8 |
+
license: apache-2.0
|
| 9 |
+
short_description: A showcase of the Falcon-H1 architecture (Mamba + Attention)
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 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>Falcon-H1-Tiny-90M WebGPU</title>
|
| 7 |
+
<link
|
| 8 |
+
rel="icon"
|
| 9 |
+
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🦅</text></svg>"
|
| 10 |
+
/>
|
| 11 |
+
<style>
|
| 12 |
+
:root {
|
| 13 |
+
--bg: #0a0e27;
|
| 14 |
+
--text: #ffffffe6;
|
| 15 |
+
--text-muted: #71717a;
|
| 16 |
+
--accent: #3b82f6;
|
| 17 |
+
--border: rgba(255, 255, 255, 0.1);
|
| 18 |
+
--border-light: rgba(255, 255, 255, 0.2);
|
| 19 |
+
--surface: rgba(255, 255, 255, 0.05);
|
| 20 |
+
--surface-active: rgba(255, 255, 255, 0.1);
|
| 21 |
+
--radius-sm: 0.25rem;
|
| 22 |
+
--radius-md: 0.75rem;
|
| 23 |
+
--radius-lg: 1rem;
|
| 24 |
+
--max-width: 700px;
|
| 25 |
+
--input-height: 52px;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
* {
|
| 29 |
+
box-sizing: border-box;
|
| 30 |
+
margin: 0;
|
| 31 |
+
padding: 0;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
body {
|
| 35 |
+
font-family:
|
| 36 |
+
system-ui,
|
| 37 |
+
-apple-system,
|
| 38 |
+
sans-serif;
|
| 39 |
+
background: var(--bg);
|
| 40 |
+
color: var(--text);
|
| 41 |
+
height: 100vh;
|
| 42 |
+
overflow: hidden;
|
| 43 |
+
display: flex;
|
| 44 |
+
flex-direction: column;
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
.loader-overlay {
|
| 48 |
+
position: fixed;
|
| 49 |
+
inset: 0;
|
| 50 |
+
background: rgba(10, 14, 39, 0.95);
|
| 51 |
+
backdrop-filter: blur(10px);
|
| 52 |
+
display: flex;
|
| 53 |
+
flex-direction: column;
|
| 54 |
+
align-items: center;
|
| 55 |
+
justify-content: center;
|
| 56 |
+
z-index: 1000;
|
| 57 |
+
gap: 1rem;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
.loader {
|
| 61 |
+
width: 48px;
|
| 62 |
+
height: 48px;
|
| 63 |
+
border: 3px solid var(--accent);
|
| 64 |
+
border-bottom-color: transparent;
|
| 65 |
+
border-radius: 50%;
|
| 66 |
+
animation: spin 1s linear infinite;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
@keyframes spin {
|
| 70 |
+
to {
|
| 71 |
+
transform: rotate(360deg);
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
.loader-text {
|
| 76 |
+
font-size: 0.9rem;
|
| 77 |
+
color: #a1a1aa;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.header {
|
| 81 |
+
padding: 1.5rem 1.5rem 1rem;
|
| 82 |
+
text-align: center;
|
| 83 |
+
border-bottom: 1px solid var(--border);
|
| 84 |
+
position: relative;
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
.header h1 {
|
| 88 |
+
font-size: 1.75rem;
|
| 89 |
+
font-weight: 700;
|
| 90 |
+
background: linear-gradient(135deg, #60a5fa, #a78bfa);
|
| 91 |
+
-webkit-background-clip: text;
|
| 92 |
+
-webkit-text-fill-color: transparent;
|
| 93 |
+
background-clip: text;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.header p {
|
| 97 |
+
font-size: 0.85rem;
|
| 98 |
+
color: var(--text-muted);
|
| 99 |
+
margin: 0.5rem auto 0;
|
| 100 |
+
max-width: 500px;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
.header .powered {
|
| 104 |
+
font-size: 0.75rem;
|
| 105 |
+
color: #52525b;
|
| 106 |
+
margin-top: 0.75rem;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
.clear-btn,
|
| 110 |
+
.send-btn {
|
| 111 |
+
border-radius: var(--radius-md);
|
| 112 |
+
cursor: pointer;
|
| 113 |
+
display: flex;
|
| 114 |
+
align-items: center;
|
| 115 |
+
justify-content: center;
|
| 116 |
+
transition: all 0.2s;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.clear-btn {
|
| 120 |
+
position: absolute;
|
| 121 |
+
left: 1.5rem;
|
| 122 |
+
top: 50%;
|
| 123 |
+
transform: translateY(-50%);
|
| 124 |
+
width: 36px;
|
| 125 |
+
height: 36px;
|
| 126 |
+
border: 1px solid var(--border-light);
|
| 127 |
+
border-radius: 0.5rem;
|
| 128 |
+
background: transparent;
|
| 129 |
+
color: var(--text);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.clear-btn:hover {
|
| 133 |
+
background: var(--surface-active);
|
| 134 |
+
border-color: rgba(255, 255, 255, 0.3);
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.chat-container {
|
| 138 |
+
flex: 1;
|
| 139 |
+
overflow-y: auto;
|
| 140 |
+
padding: 1.5rem;
|
| 141 |
+
min-height: 0;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
.chat-wrapper,
|
| 145 |
+
.input-wrapper {
|
| 146 |
+
max-width: var(--max-width);
|
| 147 |
+
margin: 0 auto;
|
| 148 |
+
display: flex;
|
| 149 |
+
gap: 0.75rem;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
.chat-wrapper {
|
| 153 |
+
flex-direction: column;
|
| 154 |
+
gap: 1rem;
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
.message {
|
| 158 |
+
display: flex;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
.message.user {
|
| 162 |
+
justify-content: flex-end;
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
.message-content {
|
| 166 |
+
max-width: 80%;
|
| 167 |
+
padding: 0.75rem 1rem;
|
| 168 |
+
border-radius: var(--radius-lg);
|
| 169 |
+
line-height: 1.6;
|
| 170 |
+
white-space: pre-wrap;
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
.message.user .message-content {
|
| 174 |
+
background: var(--accent);
|
| 175 |
+
color: white;
|
| 176 |
+
border-bottom-right-radius: var(--radius-sm);
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
.message.assistant .message-content {
|
| 180 |
+
background: var(--surface-active);
|
| 181 |
+
border-bottom-left-radius: var(--radius-sm);
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
.input-container {
|
| 185 |
+
padding: 1rem 1.5rem 1.5rem;
|
| 186 |
+
border-top: 1px solid var(--border);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
.chat-input {
|
| 190 |
+
flex: 1;
|
| 191 |
+
padding: 0.875rem 1rem;
|
| 192 |
+
border: 1px solid var(--border-light);
|
| 193 |
+
border-radius: var(--radius-md);
|
| 194 |
+
background: var(--surface);
|
| 195 |
+
color: var(--text);
|
| 196 |
+
font: inherit;
|
| 197 |
+
font-size: 1rem;
|
| 198 |
+
resize: none;
|
| 199 |
+
outline: none;
|
| 200 |
+
min-height: var(--input-height);
|
| 201 |
+
max-height: 150px;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
.chat-input::placeholder {
|
| 205 |
+
color: var(--text-muted);
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.chat-input:focus {
|
| 209 |
+
border-color: var(--accent);
|
| 210 |
+
background: rgba(255, 255, 255, 0.08);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.send-btn {
|
| 214 |
+
width: var(--input-height);
|
| 215 |
+
height: var(--input-height);
|
| 216 |
+
border: none;
|
| 217 |
+
background: var(--accent);
|
| 218 |
+
color: white;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
.send-btn:hover:not(:disabled) {
|
| 222 |
+
background: #2563eb;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
.send-btn:disabled {
|
| 226 |
+
background: #1e293b;
|
| 227 |
+
color: #475569;
|
| 228 |
+
cursor: not-allowed;
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.send-btn .stop-icon,
|
| 232 |
+
.send-btn.generating .send-icon {
|
| 233 |
+
display: none;
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
.send-btn.generating .stop-icon {
|
| 237 |
+
display: block;
|
| 238 |
+
}
|
| 239 |
+
</style>
|
| 240 |
+
</head>
|
| 241 |
+
|
| 242 |
+
<body>
|
| 243 |
+
<div id="loader" class="loader-overlay">
|
| 244 |
+
<div class="loader"></div>
|
| 245 |
+
<div class="loader-text">
|
| 246 |
+
Loading Falcon-H1-Tiny-90M-Instruct (<span id="progress">0%</span>)
|
| 247 |
+
</div>
|
| 248 |
+
</div>
|
| 249 |
+
|
| 250 |
+
<div class="header">
|
| 251 |
+
<button id="clear" class="clear-btn" title="New conversation">
|
| 252 |
+
<svg
|
| 253 |
+
width="18"
|
| 254 |
+
height="18"
|
| 255 |
+
viewBox="0 0 24 24"
|
| 256 |
+
fill="none"
|
| 257 |
+
stroke="currentColor"
|
| 258 |
+
stroke-width="2"
|
| 259 |
+
>
|
| 260 |
+
<path d="M12 5v14M5 12h14" />
|
| 261 |
+
</svg>
|
| 262 |
+
</button>
|
| 263 |
+
<h1>🦅 Falcon-H1-Tiny-90M WebGPU</h1>
|
| 264 |
+
<p>
|
| 265 |
+
A showcase of the Falcon-H1 architecture, which combines<br />
|
| 266 |
+
parallel Mamba and Attention heads in the mixer block.
|
| 267 |
+
</p>
|
| 268 |
+
<p class="powered">Powered by Transformers.js v4 (preview)</p>
|
| 269 |
+
</div>
|
| 270 |
+
|
| 271 |
+
<div class="chat-container">
|
| 272 |
+
<div class="chat-wrapper" id="chat"></div>
|
| 273 |
+
</div>
|
| 274 |
+
|
| 275 |
+
<div class="input-container">
|
| 276 |
+
<div class="input-wrapper">
|
| 277 |
+
<textarea
|
| 278 |
+
id="input"
|
| 279 |
+
class="chat-input"
|
| 280 |
+
placeholder="Type a message..."
|
| 281 |
+
rows="1"
|
| 282 |
+
disabled
|
| 283 |
+
></textarea>
|
| 284 |
+
<button id="send" class="send-btn" disabled>
|
| 285 |
+
<svg
|
| 286 |
+
class="send-icon"
|
| 287 |
+
width="20"
|
| 288 |
+
height="20"
|
| 289 |
+
viewBox="0 0 24 24"
|
| 290 |
+
fill="none"
|
| 291 |
+
stroke="currentColor"
|
| 292 |
+
stroke-width="2"
|
| 293 |
+
>
|
| 294 |
+
<path d="M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z" />
|
| 295 |
+
</svg>
|
| 296 |
+
<svg
|
| 297 |
+
class="stop-icon"
|
| 298 |
+
width="16"
|
| 299 |
+
height="16"
|
| 300 |
+
viewBox="0 0 24 24"
|
| 301 |
+
fill="currentColor"
|
| 302 |
+
>
|
| 303 |
+
<rect x="4" y="4" width="16" height="16" rx="2" />
|
| 304 |
+
</svg>
|
| 305 |
+
</button>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
|
| 309 |
+
<script type="module">
|
| 310 |
+
import {
|
| 311 |
+
pipeline,
|
| 312 |
+
TextStreamer,
|
| 313 |
+
InterruptableStoppingCriteria,
|
| 314 |
+
} from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@next";
|
| 315 |
+
|
| 316 |
+
const $ = (id) => document.getElementById(id);
|
| 317 |
+
const chat = $("chat");
|
| 318 |
+
const input = $("input");
|
| 319 |
+
const sendBtn = $("send");
|
| 320 |
+
const loader = $("loader");
|
| 321 |
+
const progress = $("progress");
|
| 322 |
+
const chatContainer = document.querySelector(".chat-container");
|
| 323 |
+
|
| 324 |
+
const SYSTEM_MESSAGE = {
|
| 325 |
+
role: "system",
|
| 326 |
+
content: "You are a helpful assistant.",
|
| 327 |
+
};
|
| 328 |
+
const stoppingCriteria = new InterruptableStoppingCriteria();
|
| 329 |
+
|
| 330 |
+
let generator,
|
| 331 |
+
isGenerating = false,
|
| 332 |
+
messages = [SYSTEM_MESSAGE];
|
| 333 |
+
const fileProgress = new Map();
|
| 334 |
+
|
| 335 |
+
const updateBtn = () =>
|
| 336 |
+
(sendBtn.disabled = !input.value.trim() && !isGenerating);
|
| 337 |
+
|
| 338 |
+
const scrollToBottom = () => {
|
| 339 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 340 |
+
};
|
| 341 |
+
|
| 342 |
+
async function init() {
|
| 343 |
+
try {
|
| 344 |
+
generator = await pipeline(
|
| 345 |
+
"text-generation",
|
| 346 |
+
"onnx-community/Falcon-H1-Tiny-90M-Instruct-ONNX",
|
| 347 |
+
{
|
| 348 |
+
dtype: "fp16",
|
| 349 |
+
device: "webgpu",
|
| 350 |
+
progress_callback: ({ status, file, loaded, total }) => {
|
| 351 |
+
if (
|
| 352 |
+
status !== "progress" ||
|
| 353 |
+
fileProgress.set(file, { loaded, total }).size < 6
|
| 354 |
+
)
|
| 355 |
+
return;
|
| 356 |
+
const { loaded: l, total: t } = [
|
| 357 |
+
...fileProgress.values(),
|
| 358 |
+
].reduce((a, b) => ({
|
| 359 |
+
loaded: a.loaded + b.loaded,
|
| 360 |
+
total: a.total + b.total,
|
| 361 |
+
}));
|
| 362 |
+
progress.textContent = `${((l / t) * 100).toFixed(0)}%`;
|
| 363 |
+
},
|
| 364 |
+
},
|
| 365 |
+
);
|
| 366 |
+
loader.style.display = "none";
|
| 367 |
+
input.disabled = false;
|
| 368 |
+
input.focus();
|
| 369 |
+
} catch (e) {
|
| 370 |
+
progress.textContent = `Error: ${e.message}`;
|
| 371 |
+
}
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
function addMessage(role, content = "") {
|
| 375 |
+
chat.insertAdjacentHTML(
|
| 376 |
+
"beforeend",
|
| 377 |
+
`<div class="message ${role}"><div class="message-content">${content || " "}</div></div>`,
|
| 378 |
+
);
|
| 379 |
+
scrollToBottom();
|
| 380 |
+
return chat.lastElementChild.querySelector(".message-content");
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
async function generate() {
|
| 384 |
+
if (isGenerating) return stoppingCriteria.interrupt();
|
| 385 |
+
|
| 386 |
+
const userMsg = input.value.trim();
|
| 387 |
+
if (!userMsg) return;
|
| 388 |
+
|
| 389 |
+
input.value = "";
|
| 390 |
+
input.style.height = "auto";
|
| 391 |
+
messages.push({ role: "user", content: userMsg });
|
| 392 |
+
addMessage("user", userMsg);
|
| 393 |
+
|
| 394 |
+
isGenerating = true;
|
| 395 |
+
sendBtn.classList.add("generating");
|
| 396 |
+
sendBtn.disabled = false;
|
| 397 |
+
stoppingCriteria.reset();
|
| 398 |
+
|
| 399 |
+
const contentEl = addMessage("assistant");
|
| 400 |
+
let response = "";
|
| 401 |
+
|
| 402 |
+
await generator(messages, {
|
| 403 |
+
max_new_tokens: 512,
|
| 404 |
+
do_sample: false,
|
| 405 |
+
stopping_criteria: stoppingCriteria,
|
| 406 |
+
streamer: new TextStreamer(generator.tokenizer, {
|
| 407 |
+
skip_prompt: true,
|
| 408 |
+
skip_special_tokens: true,
|
| 409 |
+
callback_function: (token) => {
|
| 410 |
+
response += token;
|
| 411 |
+
contentEl.textContent = response || " ";
|
| 412 |
+
scrollToBottom();
|
| 413 |
+
},
|
| 414 |
+
}),
|
| 415 |
+
});
|
| 416 |
+
|
| 417 |
+
messages.push({ role: "assistant", content: response });
|
| 418 |
+
isGenerating = false;
|
| 419 |
+
sendBtn.classList.remove("generating");
|
| 420 |
+
updateBtn();
|
| 421 |
+
input.focus();
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
sendBtn.addEventListener("click", generate);
|
| 425 |
+
$("clear").addEventListener("click", () => {
|
| 426 |
+
if (isGenerating) return;
|
| 427 |
+
messages = [SYSTEM_MESSAGE];
|
| 428 |
+
chat.innerHTML = "";
|
| 429 |
+
input.focus();
|
| 430 |
+
});
|
| 431 |
+
input.addEventListener("keydown", (e) => {
|
| 432 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
| 433 |
+
e.preventDefault();
|
| 434 |
+
generate();
|
| 435 |
+
}
|
| 436 |
+
});
|
| 437 |
+
input.addEventListener("input", () => {
|
| 438 |
+
input.style.height = "auto";
|
| 439 |
+
input.style.height = Math.min(input.scrollHeight, 150) + "px";
|
| 440 |
+
updateBtn();
|
| 441 |
+
});
|
| 442 |
+
|
| 443 |
+
init();
|
| 444 |
+
</script>
|
| 445 |
+
</body>
|
| 446 |
+
</html>
|