-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgemma.html
380 lines (366 loc) · 20.3 KB
/
gemma.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<!--
* Copyright (C) 2024 Intel Corporation. All rights reserved.
* Licensed under the Apache License 2.0. See LICENSE in the project root for license information.
* SPDX-License-Identifier: Apache-2.0
-->
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="../../style/tailwind.css" rel="stylesheet" />
<link href="../../style/general.css" rel="stylesheet" />
<title>LLM Inference on Web</title>
<link
rel="stylesheet"
href="../../style/highlight.js/11.9.0/styles/github-dark-dimmed.min.css"
/>
<style>
textarea:focus {
outline: none;
border: 1px solid #000;
}
section#promptInputSection.running-mode {
& textarea,
& button {
cursor: not-allowed;
opacity: 0.6;
}
}
</style>
</head>
<body>
<div id="naviBar" class="sticky top-0 z-50"></div>
<div class="main-content container mx-auto my-8 w-full px-8 lg:px-20">
<div>
<h1 class="text-shadow-sm">
<span
class="font-sans block text-4xl font-extrabold 2xl:text-5xl text-stone-50 text-center"
>LLM Inference on Web</span
>
</h1>
<h3>
<span
class="font-sans block text-xl font-semibold 2xl:text-2xl text-stone-50 text-center"
>(powered by Gemma-2B)
</span>
</h3>
</div>
<div>
<section id="modelStatusPanel" class="grid grid-rows 2xl:gap-2 gap-0.5">
<div
class="text-nowrap justify-self-center flex items-center text-stone-100 max-w-100 rounded-2xl backdrop-blur-xl px-2 font-mono gap-2 2xl:gap-4"
>
<div class="text-sm 2xl:text-md text-stone-50 font-semibold">
Models Status
</div>
<div class="flex flex-wrap items-center gap-2 2xl:gap-4">
<div
class="flex items-center justify-between imageDisplayEle text-xs 2xl:text-sm"
>
<span
class="rounded-l-md bg-stone-600 px-2 py-1 text-stone-50 ring-1 ring-inset ring-stone-500/10"
>
gemma-2b-it-gpu-int4</span
>
<span
id="gemmaStatusBar"
class="rounded-r-md bg-neutral-400 2xl:min-h-[28px] 2xl:min-w-[68px] px-1 2xl:px-2 py-1 text-stone-50 ring-1 ring-inset ring-stone-500/10"
>unload
</span>
</div>
</div>
</div>
<div
id="loadModelPromptContent"
class="justify-self-center italic text-stone-200/80 2xl:text-sm font-semibold text-xs"
>
[ Model should be loaded before the inference.
<a
href="https://www.kaggle.com/models/google/gemma/frameworks/tfLite/"
class="text-amber-300"
target="_blank"
>Download model</a
>
]
</div>
</section>
</div>
<div class="flex flex-col items-center 2xl:mt-8 mt-4">
<div class="2xl:w-full w-4/5">
<section id="modelUpload" class="place-self-start">
<div class="w-full flex gap-6 items-center">
<div
class="flex gap-2 items-center rounded-md text-base font-semibold text-stone-900"
>
<label
id="upload-button"
for="upload"
class="w-[120px] grid justify-center cursor-pointer control-entry transition ease-in-out bg-blue-500 hover:bg-indigo-500 hover:-translate-y-1 hover:translate-x-0 duration-200 text-stone-50 font-semibold p-2 rounded-md text-xs 2xl:text-base"
>
<input
style="display: none"
type="file"
id="upload"
accept=".bin"
/>Open Model
</label>
</div>
<div
id="progressBar"
class="hidden relative rounded-2xl w-full min-h-[30px] bg-stone-200/40 flex items-center justify-between font-mono"
></div>
</div>
</section>
<section
class="relative 2xl:h-[512px] h-[245px] w-full flex bg-stone-900/40 backdrop-blur-md font-mono text-stone-50 2xl:rounded-3xl rounded-xl p-4 2xl:mt-8 mt-4"
>
<span
id="output"
class="w-full text-sm 2xl:text-lg overflow-auto"
style="white-space: pre-wrap"
>
</span>
</section>
</div>
<div class="2xl:w-full w-4/5">
<section
id="promptInputSection"
class="2xl:h-[100px] h-[64px] relative running-mode flex bg-stone-900/40 backdrop-blur-md font-mono text-stone-50 2xl:rounded-3xl rounded-xl p-4 2xl:mt-8 mt-4"
>
<textarea
readonly
class="w-full text-sm 2xl:text-lg font-sans"
rows="3"
id="input"
style="
resize: none;
border-width: 0px;
background-color: transparent;
"
></textarea>
<div class="flex flex-row-reverse items-center gap-x-4">
<div class="absolute_center hidden" id="loadingIcon">
<svg
class="2xl:w-[30px] 2xl:h-[30px] w-[24px] h-[24px] animate-spin"
fill="#5693f5"
version="1.1"
class=""
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 330 330"
xml:space="preserve"
stroke="#5693f5"
>
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g
id="SVGRepo_tracerCarrier"
stroke-linecap="round"
stroke-linejoin="round"
></g>
<g id="SVGRepo_iconCarrier">
<g id="XMLID_2_">
<path
id="XMLID_4_"
d="M97.5,165c0-8.284-6.716-15-15-15h-60c-8.284,0-15,6.716-15,15s6.716,15,15,15h60 C90.784,180,97.5,173.284,97.5,165z"
></path>
<path
id="XMLID_5_"
d="M307.5,150h-30c-8.284,0-15,6.716-15,15s6.716,15,15,15h30c8.284,0,15-6.716,15-15S315.784,150,307.5,150z"
></path>
<path
id="XMLID_6_"
d="M172.5,90c8.284,0,15-6.716,15-15V15c0-8.284-6.716-15-15-15s-15,6.716-15,15v60 C157.5,83.284,164.216,90,172.5,90z"
></path>
<path
id="XMLID_7_"
d="M172.501,240c-8.284,0-15,6.716-15,15v60c0,8.284,6.716,15,15,15c8.284,0,15-6.716,15-15v-60 C187.501,246.716,180.785,240,172.501,240z"
></path>
<path
id="XMLID_8_"
d="M77.04,48.327c-5.856-5.858-15.354-5.857-21.213,0c-5.858,5.858-5.858,15.355,0,21.213l42.427,42.428 c2.929,2.929,6.768,4.394,10.606,4.394c3.838,0,7.678-1.465,10.606-4.393c5.858-5.858,5.858-15.355,0-21.213L77.04,48.327z"
></path>
<path
id="XMLID_9_"
d="M246.746,218.034c-5.857-5.857-15.355-5.857-21.213,0c-5.858,5.858-5.857,15.355,0,21.213l42.428,42.426 c2.929,2.929,6.768,4.393,10.607,4.393c3.839,0,7.678-1.465,10.606-4.393c5.858-5.858,5.858-15.355,0-21.213L246.746,218.034z"
></path>
<path
id="XMLID_10_"
d="M98.254,218.034L55.828,260.46c-5.858,5.858-5.858,15.355,0,21.213c2.929,2.929,6.768,4.393,10.607,4.393 c3.839,0,7.678-1.464,10.606-4.393l42.426-42.426c5.858-5.858,5.858-15.355,0-21.213 C113.609,212.176,104.111,212.176,98.254,218.034z"
></path>
</g>
</g>
</svg>
</div>
<button
id="submit"
class="transition ease-in-out hover:-translate-y-1 duration-200 text-stone-50 font-semibold p-2 rounded-md"
disabled
>
<svg
class="2xl:w-[36px] 2xl:h-[36px] w-[24px] h-[24px]"
viewBox="0 0 32 32"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sketch="http://www.bohemiancoding.com/sketch/ns"
fill="#000000"
>
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g
id="SVGRepo_tracerCarrier"
stroke-linecap="round"
stroke-linejoin="round"
></g>
<g id="SVGRepo_iconCarrier">
<title>arrow-up-square</title>
<desc>Created with Sketch Beta.</desc>
<defs></defs>
<g
id="Page-1"
stroke="none"
stroke-width="1"
fill="none"
fill-rule="evenodd"
sketch:type="MSPage"
>
<g
opacity="0.6"
id="Icon-Set-Filled"
sketch:type="MSLayerGroup"
transform="translate(-518.000000, -985.000000)"
fill="#f8fafc"
>
<path
d="M540.535,1000.535 C540.145,1000.926 539.512,1000.926 539.121,1000.535 L535,996.414 L535,1007 C535,1007.55 534.552,1008 534,1008 C533.447,1008 533,1007.55 533,1007 L533,996.414 L528.879,1000.535 C528.488,1000.926 527.854,1000.926 527.465,1000.535 C527.074,1000.146 527.074,999.512 527.465,999.121 L533.121,993.465 C533.361,993.225 533.689,993.15 534,993.205 C534.311,993.15 534.639,993.225 534.879,993.465 L540.535,999.121 C540.926,999.512 540.926,1000.146 540.535,1000.535 L540.535,1000.535 Z M546,985 L522,985 C519.791,985 518,986.791 518,989 L518,1013 C518,1015.21 519.791,1017 522,1017 L546,1017 C548.209,1017 550,1015.21 550,1013 L550,989 C550,986.791 548.209,985 546,985 L546,985 Z"
id="arrow-up-square"
sketch:type="MSShapeGroup"
></path>
</g>
</g>
</g>
</svg>
</button>
<button
id="promptInspireBtn"
title="Give me one prompt"
class="pl-2"
disabled
>
<svg
class="2xl:w-[36px] 2xl:h-[36px] w-[24px] h-[24px] transition ease-in-out hover:-translate-y-1 duration-200 brightness-125"
version="1.1"
id="Layer_1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 511.999 511.999"
xml:space="preserve"
fill="#000000"
>
<g id="SVGRepo_bgCarrier" stroke-width="0"></g>
<g
id="SVGRepo_tracerCarrier"
stroke-linecap="round"
stroke-linejoin="round"
></g>
<g id="SVGRepo_iconCarrier">
<path
style="fill: #999999"
d="M279.883,474.891v11.037c0,9.32-7.554,16.875-16.875,16.875h-14.005 c-9.32,0-16.875-7.554-16.875-16.875v-11.037c4.317,1.006,8.817,1.545,13.453,1.545h20.836 C271.053,476.436,275.554,475.896,279.883,474.891z"
></path>
<g>
<path
style="fill: #b3b3b3"
d="M187.76,428.608h136.492c-4.329,22.847-21.866,41.021-44.369,46.282 c-4.329,1.006-8.83,1.545-13.465,1.545h-20.836c-4.636,0-9.136-0.54-13.453-1.545C209.626,469.63,192.089,451.455,187.76,428.608z"
></path>
<path
style="fill: #b3b3b3"
d="M325.295,396.503v21.056c0,3.777-0.356,7.468-1.042,11.049H187.76 c-0.687-3.581-1.042-7.272-1.042-11.049v-21.056h33.111h36.177h36.177H325.295z"
></path>
</g>
<path
style="fill: #f95428"
d="M256.006,155.133l19.205,28.647c-5.482,3.691-12.092,5.85-19.205,5.85s-13.711-2.146-19.205-5.85 L256.006,155.133z"
></path>
<path
style="fill: #cccccc"
d="M275.211,183.78l16.973,25.312h-0.012c-11.54,4.991-23.852,7.481-36.165,7.481 c-12.325,0-24.637-2.489-36.177-7.481l16.973-25.312c5.494,3.704,12.092,5.85,19.205,5.85 C263.119,189.63,269.729,187.472,275.211,183.78z"
></path>
<g>
<path
style="fill: #8684f5"
d="M292.183,209.092v187.41h-36.177V216.585v-0.012c12.313,0,24.625-2.489,36.165-7.481H292.183z"
></path>
<path
style="fill: #8684f5"
d="M256.006,216.585v179.917h-36.177v-187.41c11.54,4.991,23.852,7.481,36.177,7.481V216.585z"
></path>
</g>
<path
style="fill: #f7b239"
d="M402.837,206.554c0,39.77-15.82,75.837-41.487,102.277c-22.871,23.546-36.055,54.842-36.055,87.672 h-33.111v-187.41l-16.973-25.312l-19.205-28.647l-19.205,28.647l-16.973,25.312v187.41h-33.111 c0-32.891-13.281-64.163-36.165-87.782c-25.189-25.986-40.862-61.256-41.377-100.18c-1.067-80.657,64.064-147.664,144.709-148.805 C335.952,58.583,402.837,124.756,402.837,206.554z"
></path>
<g>
<path
style="fill: #ffffff"
d="M372.178,215.751c-5.08,0-9.198-4.118-9.198-9.198c0-47.507-31.917-89.812-77.618-102.877 c-4.883-1.397-7.711-6.487-6.314-11.372c1.397-4.885,6.489-7.71,11.371-6.316c53.553,15.311,90.956,64.888,90.956,120.563 C381.376,211.633,377.258,215.751,372.178,215.751z"
></path>
<path
style="fill: #ffffff"
d="M262.39,99.751c-0.162,0-0.325-0.004-0.488-0.012c-2.081-0.109-4.124-0.157-6.075-0.159 c-0.438,0-0.876,0-1.313,0.01c-5.065,0.114-9.285-3.917-9.395-8.995c-0.11-5.078,3.917-9.285,8.995-9.395 c2.846-0.061,5.749,0.012,8.75,0.17c5.073,0.266,8.97,4.594,8.705,9.666C271.311,95.943,267.25,99.751,262.39,99.751z"
></path>
</g>
<g>
<path
style="fill: #f7b239"
d="M455.337,217.738h-16.053c-5.08,0-9.198-4.118-9.198-9.198s4.118-9.198,9.198-9.198h16.053 c5.08,0,9.198,4.118,9.198,9.198S460.416,217.738,455.337,217.738z"
></path>
<path
style="fill: #f7b239"
d="M72.703,217.738H56.662c-5.08,0-9.198-4.118-9.198-9.198s4.118-9.198,9.198-9.198h16.041 c5.08,0,9.198,4.118,9.198,9.198S77.784,217.738,72.703,217.738z"
></path>
<path
style="fill: #f7b239"
d="M414.727,126.094c-3.181,0-6.275-1.652-7.977-4.607c-2.536-4.401-1.024-10.025,3.377-12.561 l13.919-8.02c4.401-2.535,10.025-1.024,12.561,3.377c2.536,4.401,1.024,10.025-3.377,12.561l-13.919,8.02 C417.866,125.698,416.286,126.094,414.727,126.094z"
></path>
<path
style="fill: #f7b239"
d="M83.381,317.404c-3.179,0-6.27-1.649-7.974-4.601c-2.54-4.399-1.031-10.024,3.368-12.564 l13.895-8.02c4.4-2.54,10.024-1.031,12.564,3.368c2.54,4.399,1.031,10.024-3.368,12.564l-13.895,8.02 C86.522,317.007,84.94,317.404,83.381,317.404z"
></path>
<path
style="fill: #f7b239"
d="M347.63,59.013c-1.561,0-3.143-0.397-4.591-1.235c-4.399-2.541-5.905-8.166-3.365-12.565 l8.033-13.907c2.541-4.399,8.167-5.905,12.565-3.364c4.399,2.541,5.905,8.166,3.365,12.565l-8.033,13.907 C353.899,57.365,350.808,59.013,347.63,59.013z"
></path>
<path
style="fill: #f7b239"
d="M256.006,34.46c-5.08,0-9.198-4.118-9.198-9.198V9.198c0-5.08,4.118-9.198,9.198-9.198 s9.198,4.118,9.198,9.198v16.065C265.204,30.342,261.086,34.46,256.006,34.46z"
></path>
<path
style="fill: #f7b239"
d="M164.369,59.013c-3.177,0-6.269-1.648-7.972-4.599l-8.033-13.907 c-2.541-4.399-1.034-10.024,3.365-12.565c4.398-2.54,10.023-1.035,12.565,3.364l8.033,13.907 c2.541,4.399,1.034,10.024-3.365,12.565C167.512,58.616,165.93,59.013,164.369,59.013z"
></path>
<path
style="fill: #f7b239"
d="M97.271,126.094c-1.559,0-3.139-0.396-4.587-1.231l-13.907-8.02c-4.4-2.537-5.91-8.163-3.372-12.563 c2.537-4.401,8.161-5.911,12.563-3.372l13.907,8.02c4.4,2.537,5.91,8.163,3.372,12.563 C103.544,124.444,100.45,126.094,97.271,126.094z"
></path>
<path
style="fill: #f7b239"
d="M428.63,317.404c-1.56,0-3.142-0.397-4.59-1.234l-13.895-8.02c-4.399-2.54-5.907-8.165-3.368-12.564 c2.54-4.4,8.165-5.906,12.564-3.368l13.895,8.02c4.399,2.54,5.907,8.165,3.368,12.564 C434.901,315.755,431.809,317.404,428.63,317.404z"
></path>
</g>
<path
style="fill: #333333"
d="M365.546,95.448c-29.969-29.55-69.665-45.5-111.789-44.906 c-85.928,1.207-154.91,72.139-153.773,158.117c0.529,39.95,16.14,77.759,43.958,106.463c21.649,22.338,33.571,51.24,33.571,81.384 v21.058c0,29.592,18.988,54.821,45.414,64.178v4.186c0,14.376,11.696,26.072,26.072,26.072h14.004 c14.376,0,26.072-11.696,26.072-26.072v-4.187c26.424-9.358,45.409-34.587,45.409-64.177v-21.058 c0-30.189,11.882-59.051,33.46-81.269c28.428-29.273,44.083-67.87,44.083-108.681C412.029,164.462,395.522,125.004,365.546,95.448z M195.909,417.561v-11.86h120.182v11.86c0,0.619-0.025,1.234-0.047,1.848H195.956C195.934,418.796,195.909,418.182,195.909,417.561z M265.198,225.308c5.997-0.548,11.948-1.643,17.782-3.267v165.265h-17.782V225.308z M239.855,195.729 c5.098,2.033,10.558,3.098,16.146,3.098c5.586,0,11.043-1.066,16.142-3.098l5.787,8.632c-14.326,3.966-29.539,3.966-43.864,0 L239.855,195.729z M250.513,179.832l5.487-8.183l5.487,8.183c-1.787,0.395-3.623,0.6-5.484,0.6 C254.138,180.432,252.3,180.228,250.513,179.832z M229.02,222.042c5.834,1.624,11.784,2.718,17.782,3.267v161.998H229.02V222.042z M270.681,485.927c0,4.233-3.444,7.677-7.677,7.677H249c-4.233,0-7.677-3.444-7.677-7.677v-0.441 c1.412,0.087,2.829,0.147,4.263,0.147h20.831c1.434,0,2.854-0.06,4.266-0.147v0.441H270.681z M266.415,467.238h-20.831 c-20.183,0-37.581-12.107-45.347-29.432h111.524C303.996,455.132,286.599,467.238,266.415,467.238z M354.749,302.42 c-22.735,23.412-36.15,53.264-38.336,84.888h-15.039V209.092c0-1.824-0.542-3.607-1.559-5.122l-36.177-53.959 c-1.708-2.547-4.573-4.075-7.639-4.075c-3.066,0-5.932,1.528-7.639,4.075l-36.177,53.959c-1.015,1.515-1.559,3.298-1.559,5.122 v178.215h-15.041c-2.194-31.586-15.641-61.473-38.432-84.988c-24.538-25.319-38.307-58.668-38.773-93.904 c-0.484-36.559,13.405-71.25,39.107-97.685c25.705-26.439,59.988-41.281,96.532-41.795c0.666-0.01,1.331-0.013,1.997-0.013 c36.413,0,70.657,14.027,96.618,39.626c26.441,26.072,41.003,60.878,41.003,98.008C393.634,242.553,379.824,276.599,354.749,302.42z "
></path>
</g>
</svg>
</button>
</div>
</section>
</div>
</div>
</div>
<footer id="footer"></footer>
</body>
<script type="module" src="gemma.js"></script>
</html>