Spaces:
Running
Running
Upload 7 files
Browse files- build/m.d.ts +4 -4
- build/m.js +37 -37
- build/m_bg.wasm +2 -2
- index.html +12 -4
- moondreamWorker.js +5 -5
build/m.d.ts
CHANGED
|
@@ -22,13 +22,13 @@ export class Model {
|
|
| 22 |
* @param {number} repeat_penalty
|
| 23 |
* @param {number} repeat_last_n
|
| 24 |
* @param {boolean} verbose_prompt
|
| 25 |
-
* @returns {
|
| 26 |
*/
|
| 27 |
-
init_with_image_prompt(prompt: string, seed: bigint, temp: number, top_p: number, repeat_penalty: number, repeat_last_n: number, verbose_prompt: boolean):
|
| 28 |
/**
|
| 29 |
-
* @returns {
|
| 30 |
*/
|
| 31 |
-
next_token():
|
| 32 |
}
|
| 33 |
|
| 34 |
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
|
|
| 22 |
* @param {number} repeat_penalty
|
| 23 |
* @param {number} repeat_last_n
|
| 24 |
* @param {boolean} verbose_prompt
|
| 25 |
+
* @returns {any}
|
| 26 |
*/
|
| 27 |
+
init_with_image_prompt(prompt: string, seed: bigint, temp: number, top_p: number, repeat_penalty: number, repeat_last_n: number, verbose_prompt: boolean): any;
|
| 28 |
/**
|
| 29 |
+
* @returns {any}
|
| 30 |
*/
|
| 31 |
+
next_token(): any;
|
| 32 |
}
|
| 33 |
|
| 34 |
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
build/m.js
CHANGED
|
@@ -196,11 +196,9 @@ export class Model {
|
|
| 196 |
* @param {number} repeat_penalty
|
| 197 |
* @param {number} repeat_last_n
|
| 198 |
* @param {boolean} verbose_prompt
|
| 199 |
-
* @returns {
|
| 200 |
*/
|
| 201 |
init_with_image_prompt(prompt, seed, temp, top_p, repeat_penalty, repeat_last_n, verbose_prompt) {
|
| 202 |
-
let deferred3_0;
|
| 203 |
-
let deferred3_1;
|
| 204 |
try {
|
| 205 |
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
| 206 |
const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -209,46 +207,30 @@ export class Model {
|
|
| 209 |
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
| 210 |
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
| 211 |
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
var len2 = r1;
|
| 215 |
-
if (r3) {
|
| 216 |
-
ptr2 = 0; len2 = 0;
|
| 217 |
-
throw takeObject(r2);
|
| 218 |
}
|
| 219 |
-
|
| 220 |
-
deferred3_1 = len2;
|
| 221 |
-
return getStringFromWasm0(ptr2, len2);
|
| 222 |
} finally {
|
| 223 |
wasm.__wbindgen_add_to_stack_pointer(16);
|
| 224 |
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
| 225 |
}
|
| 226 |
}
|
| 227 |
/**
|
| 228 |
-
* @returns {
|
| 229 |
*/
|
| 230 |
next_token() {
|
| 231 |
-
let deferred2_0;
|
| 232 |
-
let deferred2_1;
|
| 233 |
try {
|
| 234 |
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
| 235 |
wasm.model_next_token(retptr, this.__wbg_ptr);
|
| 236 |
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
| 237 |
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
| 238 |
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
var len1 = r1;
|
| 242 |
-
if (r3) {
|
| 243 |
-
ptr1 = 0; len1 = 0;
|
| 244 |
-
throw takeObject(r2);
|
| 245 |
}
|
| 246 |
-
|
| 247 |
-
deferred2_1 = len1;
|
| 248 |
-
return getStringFromWasm0(ptr1, len1);
|
| 249 |
} finally {
|
| 250 |
wasm.__wbindgen_add_to_stack_pointer(16);
|
| 251 |
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
| 252 |
}
|
| 253 |
}
|
| 254 |
}
|
|
@@ -294,6 +276,33 @@ function __wbg_get_imports() {
|
|
| 294 |
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
| 295 |
takeObject(arg0);
|
| 296 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
| 298 |
const ret = new Error();
|
| 299 |
return addHeapObject(ret);
|
|
@@ -323,11 +332,6 @@ function __wbg_get_imports() {
|
|
| 323 |
const ret = getObject(arg0).crypto;
|
| 324 |
return addHeapObject(ret);
|
| 325 |
};
|
| 326 |
-
imports.wbg.__wbindgen_is_object = function(arg0) {
|
| 327 |
-
const val = getObject(arg0);
|
| 328 |
-
const ret = typeof(val) === 'object' && val !== null;
|
| 329 |
-
return ret;
|
| 330 |
-
};
|
| 331 |
imports.wbg.__wbg_process_298734cf255a885d = function(arg0) {
|
| 332 |
const ret = getObject(arg0).process;
|
| 333 |
return addHeapObject(ret);
|
|
@@ -356,10 +360,6 @@ function __wbg_get_imports() {
|
|
| 356 |
const ret = typeof(getObject(arg0)) === 'function';
|
| 357 |
return ret;
|
| 358 |
};
|
| 359 |
-
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
| 360 |
-
const ret = getStringFromWasm0(arg0, arg1);
|
| 361 |
-
return addHeapObject(ret);
|
| 362 |
-
};
|
| 363 |
imports.wbg.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) {
|
| 364 |
getObject(arg0).getRandomValues(getObject(arg1));
|
| 365 |
}, arguments) };
|
|
@@ -374,8 +374,8 @@ function __wbg_get_imports() {
|
|
| 374 |
const ret = getObject(arg0).call(getObject(arg1));
|
| 375 |
return addHeapObject(ret);
|
| 376 |
}, arguments) };
|
| 377 |
-
imports.wbg.
|
| 378 |
-
const ret =
|
| 379 |
return addHeapObject(ret);
|
| 380 |
};
|
| 381 |
imports.wbg.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () {
|
|
|
|
| 196 |
* @param {number} repeat_penalty
|
| 197 |
* @param {number} repeat_last_n
|
| 198 |
* @param {boolean} verbose_prompt
|
| 199 |
+
* @returns {any}
|
| 200 |
*/
|
| 201 |
init_with_image_prompt(prompt, seed, temp, top_p, repeat_penalty, repeat_last_n, verbose_prompt) {
|
|
|
|
|
|
|
| 202 |
try {
|
| 203 |
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
| 204 |
const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
|
|
| 207 |
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
| 208 |
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
| 209 |
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
| 210 |
+
if (r2) {
|
| 211 |
+
throw takeObject(r1);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
}
|
| 213 |
+
return takeObject(r0);
|
|
|
|
|
|
|
| 214 |
} finally {
|
| 215 |
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
|
|
| 216 |
}
|
| 217 |
}
|
| 218 |
/**
|
| 219 |
+
* @returns {any}
|
| 220 |
*/
|
| 221 |
next_token() {
|
|
|
|
|
|
|
| 222 |
try {
|
| 223 |
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
| 224 |
wasm.model_next_token(retptr, this.__wbg_ptr);
|
| 225 |
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
| 226 |
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
| 227 |
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
| 228 |
+
if (r2) {
|
| 229 |
+
throw takeObject(r1);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
}
|
| 231 |
+
return takeObject(r0);
|
|
|
|
|
|
|
| 232 |
} finally {
|
| 233 |
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
|
|
| 234 |
}
|
| 235 |
}
|
| 236 |
}
|
|
|
|
| 276 |
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
| 277 |
takeObject(arg0);
|
| 278 |
};
|
| 279 |
+
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
| 280 |
+
const ret = getObject(arg0);
|
| 281 |
+
return addHeapObject(ret);
|
| 282 |
+
};
|
| 283 |
+
imports.wbg.__wbindgen_is_object = function(arg0) {
|
| 284 |
+
const val = getObject(arg0);
|
| 285 |
+
const ret = typeof(val) === 'object' && val !== null;
|
| 286 |
+
return ret;
|
| 287 |
+
};
|
| 288 |
+
imports.wbg.__wbg_String_b9412f8799faab3e = function(arg0, arg1) {
|
| 289 |
+
const ret = String(getObject(arg1));
|
| 290 |
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
| 291 |
+
const len1 = WASM_VECTOR_LEN;
|
| 292 |
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
| 293 |
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
| 294 |
+
};
|
| 295 |
+
imports.wbg.__wbindgen_number_new = function(arg0) {
|
| 296 |
+
const ret = arg0;
|
| 297 |
+
return addHeapObject(ret);
|
| 298 |
+
};
|
| 299 |
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
| 300 |
+
const ret = getStringFromWasm0(arg0, arg1);
|
| 301 |
+
return addHeapObject(ret);
|
| 302 |
+
};
|
| 303 |
+
imports.wbg.__wbg_set_f975102236d3c502 = function(arg0, arg1, arg2) {
|
| 304 |
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
| 305 |
+
};
|
| 306 |
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
| 307 |
const ret = new Error();
|
| 308 |
return addHeapObject(ret);
|
|
|
|
| 332 |
const ret = getObject(arg0).crypto;
|
| 333 |
return addHeapObject(ret);
|
| 334 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
imports.wbg.__wbg_process_298734cf255a885d = function(arg0) {
|
| 336 |
const ret = getObject(arg0).process;
|
| 337 |
return addHeapObject(ret);
|
|
|
|
| 360 |
const ret = typeof(getObject(arg0)) === 'function';
|
| 361 |
return ret;
|
| 362 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
imports.wbg.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) {
|
| 364 |
getObject(arg0).getRandomValues(getObject(arg1));
|
| 365 |
}, arguments) };
|
|
|
|
| 374 |
const ret = getObject(arg0).call(getObject(arg1));
|
| 375 |
return addHeapObject(ret);
|
| 376 |
}, arguments) };
|
| 377 |
+
imports.wbg.__wbg_new_b51585de1b234aff = function() {
|
| 378 |
+
const ret = new Object();
|
| 379 |
return addHeapObject(ret);
|
| 380 |
};
|
| 381 |
imports.wbg.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () {
|
build/m_bg.wasm
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:acf86f8bfa250372f6e1707f527191c963fb9887c059b4865b483e26a5f84742
|
| 3 |
+
size 5357870
|
index.html
CHANGED
|
@@ -50,9 +50,17 @@
|
|
| 50 |
>Moondream 2</a
|
| 51 |
>
|
| 52 |
by
|
| 53 |
-
<a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
and model implementation on Candle by
|
| 55 |
-
<a
|
|
|
|
|
|
|
|
|
|
| 56 |
>Santiago Medina
|
| 57 |
</a>
|
| 58 |
</p>
|
|
@@ -106,13 +114,13 @@
|
|
| 106 |
min="1"
|
| 107 |
max="2048"
|
| 108 |
step="1"
|
| 109 |
-
value="
|
| 110 |
oninput="this.nextElementSibling.value = Number(this.value)"
|
| 111 |
/>
|
| 112 |
<output
|
| 113 |
class="text-xs w-[50px] text-center font-light px-1 py-1 border border-gray-700 rounded-md"
|
| 114 |
>
|
| 115 |
-
|
| 116 |
>
|
| 117 |
<label class="text-sm font-medium" for="temperature"
|
| 118 |
>Temperature</label
|
|
|
|
| 50 |
>Moondream 2</a
|
| 51 |
>
|
| 52 |
by
|
| 53 |
+
<a
|
| 54 |
+
href=" https://huggingface.co/vikhyatk"
|
| 55 |
+
class="link"
|
| 56 |
+
target="_blank"
|
| 57 |
+
>Vik</a
|
| 58 |
+
>
|
| 59 |
and model implementation on Candle by
|
| 60 |
+
<a
|
| 61 |
+
href="https://huggingface.co/santiagomed"
|
| 62 |
+
class="link"
|
| 63 |
+
target="_blank"
|
| 64 |
>Santiago Medina
|
| 65 |
</a>
|
| 66 |
</p>
|
|
|
|
| 114 |
min="1"
|
| 115 |
max="2048"
|
| 116 |
step="1"
|
| 117 |
+
value="500"
|
| 118 |
oninput="this.nextElementSibling.value = Number(this.value)"
|
| 119 |
/>
|
| 120 |
<output
|
| 121 |
class="text-xs w-[50px] text-center font-light px-1 py-1 border border-gray-700 rounded-md"
|
| 122 |
>
|
| 123 |
+
500</output
|
| 124 |
>
|
| 125 |
<label class="text-sm font-medium" for="temperature"
|
| 126 |
>Temperature</label
|
moondreamWorker.js
CHANGED
|
@@ -136,7 +136,7 @@ async function generate(data) {
|
|
| 136 |
status: "complete-embedding",
|
| 137 |
message: "Embeddings Complete",
|
| 138 |
});
|
| 139 |
-
const
|
| 140 |
prompt,
|
| 141 |
BigInt(seed),
|
| 142 |
temp,
|
|
@@ -147,7 +147,7 @@ async function generate(data) {
|
|
| 147 |
);
|
| 148 |
const seq_len = 2048;
|
| 149 |
|
| 150 |
-
let sentence =
|
| 151 |
let maxTokens = maxSeqLen ? maxSeqLen : seq_len - prompt.length - 1;
|
| 152 |
let startTime = performance.now();
|
| 153 |
let tokensCount = 0;
|
|
@@ -162,9 +162,9 @@ async function generate(data) {
|
|
| 162 |
});
|
| 163 |
return;
|
| 164 |
}
|
| 165 |
-
const token = await model.next_token();
|
| 166 |
-
|
| 167 |
-
|
| 168 |
self.postMessage({
|
| 169 |
status: "complete",
|
| 170 |
message: "complete",
|
|
|
|
| 136 |
status: "complete-embedding",
|
| 137 |
message: "Embeddings Complete",
|
| 138 |
});
|
| 139 |
+
const { token, token_id } = model.init_with_image_prompt(
|
| 140 |
prompt,
|
| 141 |
BigInt(seed),
|
| 142 |
temp,
|
|
|
|
| 147 |
);
|
| 148 |
const seq_len = 2048;
|
| 149 |
|
| 150 |
+
let sentence = token;
|
| 151 |
let maxTokens = maxSeqLen ? maxSeqLen : seq_len - prompt.length - 1;
|
| 152 |
let startTime = performance.now();
|
| 153 |
let tokensCount = 0;
|
|
|
|
| 162 |
});
|
| 163 |
return;
|
| 164 |
}
|
| 165 |
+
const { token, token_id } = await model.next_token();
|
| 166 |
+
if (token_id === 50256) {
|
| 167 |
+
// <|endoftext|>
|
| 168 |
self.postMessage({
|
| 169 |
status: "complete",
|
| 170 |
message: "complete",
|