@hackbuild/ai-views 0.1.2 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/chat.d.ts +35 -2
- package/dist/chat.js +47 -3
- package/dist/elements.d.ts +3 -1
- package/dist/elements.js +2 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -1
- package/dist/loaders.js +40 -7
- package/dist/mount-mask.d.ts +56 -6
- package/dist/mount-mask.js +334 -36
- package/dist/mount-talk.d.ts +92 -0
- package/dist/mount-talk.js +502 -0
- package/dist/mount-transcribe.d.ts +22 -0
- package/dist/mount-transcribe.js +90 -4
- package/dist/pick.d.ts +23 -0
- package/dist/pick.js +51 -0
- package/dist/single/elements.iife.js +1784 -627
- package/dist/single/elements.js +1774 -628
- package/dist/single/index.iife.js +1478 -56
- package/dist/single/index.js +1473 -57
- package/dist/single/vue.iife.js +1720 -622
- package/dist/single/vue.js +1714 -623
- package/dist/speaker.d.ts +55 -0
- package/dist/speaker.js +109 -0
- package/dist/talk.d.ts +89 -0
- package/dist/talk.js +121 -0
- package/dist/transcribe.d.ts +36 -1
- package/dist/transcribe.js +19 -3
- package/dist/vue.d.ts +137 -5
- package/dist/vue.js +80 -9
- package/llms.md +376 -14
- package/package.json +5 -5
|
@@ -2986,6 +2986,36 @@ var HackbuildAiViews = (function(exports) {
|
|
|
2986
2986
|
527503840,
|
|
2987
2987
|
"vendor"
|
|
2988
2988
|
] }
|
|
2989
|
+
},
|
|
2990
|
+
"Felladrin/gguf-sharded-UD-Q4_K_XL-Phi-4-mini-reasoning": {
|
|
2991
|
+
"revision": "bc6bac3a27893ab006486992e46a7662ef4790a9",
|
|
2992
|
+
"files": {
|
|
2993
|
+
"model.shard-00001-of-00005.gguf": [
|
|
2994
|
+
"e730254967e049ab3bd5e2311cedd200155b9d0835fb05a9218de82b324cac3f",
|
|
2995
|
+
512426912,
|
|
2996
|
+
"vendor"
|
|
2997
|
+
],
|
|
2998
|
+
"model.shard-00002-of-00005.gguf": [
|
|
2999
|
+
"812f190b06a786ec7ed22378bb5a136476f5c040a434140916cceb5563ab7f4d",
|
|
3000
|
+
481483520,
|
|
3001
|
+
"vendor"
|
|
3002
|
+
],
|
|
3003
|
+
"model.shard-00003-of-00005.gguf": [
|
|
3004
|
+
"f5b575dc8a4fd7d75dc4616261a050a224a2e81783e5616e74d2cd022b89d658",
|
|
3005
|
+
499301472,
|
|
3006
|
+
"vendor"
|
|
3007
|
+
],
|
|
3008
|
+
"model.shard-00004-of-00005.gguf": [
|
|
3009
|
+
"edba060f8bf871dc4953ff633a0b1e0de7d312cd05ef3a5a449b69c9d2e53765",
|
|
3010
|
+
495664224,
|
|
3011
|
+
"vendor"
|
|
3012
|
+
],
|
|
3013
|
+
"model.shard-00005-of-00005.gguf": [
|
|
3014
|
+
"da2110debf2334e102413017e3ad9285f6a5475aeb5a2d3b85b03e5865df5cab",
|
|
3015
|
+
473803392,
|
|
3016
|
+
"vendor"
|
|
3017
|
+
]
|
|
3018
|
+
}
|
|
2989
3019
|
}
|
|
2990
3020
|
};
|
|
2991
3021
|
}));
|
|
@@ -4061,6 +4091,42 @@ var HackbuildAiViews = (function(exports) {
|
|
|
4061
4091
|
commercial: true,
|
|
4062
4092
|
runtime: "@mlc-ai/web-llm@0.2.84"
|
|
4063
4093
|
},
|
|
4094
|
+
{
|
|
4095
|
+
id: "phi-4-mini-reasoning-gguf",
|
|
4096
|
+
label: "Phi-4 mini reasoning",
|
|
4097
|
+
params: "3.8B",
|
|
4098
|
+
quant: "Q4_K_XL",
|
|
4099
|
+
censorship: "stock",
|
|
4100
|
+
tier: "medium",
|
|
4101
|
+
family: "phi",
|
|
4102
|
+
tags: ["think", "reasoning"],
|
|
4103
|
+
note: "phi-4 mini tuned for maths with a think trace, unsloth dynamic q4. five 500 MB shards, so it loads past the 2 GB file cap.",
|
|
4104
|
+
group: "reasoning",
|
|
4105
|
+
badge: "maths, thinks first",
|
|
4106
|
+
speed: "slow",
|
|
4107
|
+
verdict: "maths, thinks first",
|
|
4108
|
+
provides: ["chat"],
|
|
4109
|
+
provider: "wllama",
|
|
4110
|
+
source: {
|
|
4111
|
+
repo: "Felladrin/gguf-sharded-UD-Q4_K_XL-Phi-4-mini-reasoning",
|
|
4112
|
+
file: "model.shard-00001-of-00005.gguf"
|
|
4113
|
+
},
|
|
4114
|
+
sizeMB: 2349,
|
|
4115
|
+
sizeSource: "vendor",
|
|
4116
|
+
ctx: 4096,
|
|
4117
|
+
ladder: [{
|
|
4118
|
+
device: "webgpu",
|
|
4119
|
+
dtype: "q4_k_m"
|
|
4120
|
+
}, {
|
|
4121
|
+
device: "wasm",
|
|
4122
|
+
dtype: "q4_k_m"
|
|
4123
|
+
}],
|
|
4124
|
+
quirks: { think: "tags" },
|
|
4125
|
+
licence: "MIT (the base model card microsoft/Phi-4-mini-reasoning; the shard repo has no licence field)",
|
|
4126
|
+
commercial: true,
|
|
4127
|
+
runtime: "@wllama/wllama@3.8.1",
|
|
4128
|
+
notes: ["no webllm or transformers.js build on the hub as of 2026-11-25: the microsoft onnx export is an onnxruntime-genai layout, so the gguf shards are the browser path"]
|
|
4129
|
+
},
|
|
4064
4130
|
{
|
|
4065
4131
|
id: "smollm2-1.7b-instruct-mlc",
|
|
4066
4132
|
label: "SmolLM2 1.7B",
|
|
@@ -7452,9 +7518,47 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7452
7518
|
var init_embed = __esmMin((() => {
|
|
7453
7519
|
words = (t) => t.toLowerCase().match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
7454
7520
|
}));
|
|
7521
|
+
// packages/memory/src/assemble.ts
|
|
7522
|
+
/**
|
|
7523
|
+
* Fixed lines always go in; ranked sections join highest priority first
|
|
7524
|
+
* while they fit the budget (equal priorities keep their given order). A
|
|
7525
|
+
* section that does not fit is skipped and smaller ones below it may still
|
|
7526
|
+
* join.
|
|
7527
|
+
*/
|
|
7528
|
+
function budget(opts) {
|
|
7529
|
+
const est = opts.estimate ?? estimateTokens;
|
|
7530
|
+
const fixed = (opts.fixed ?? []).filter((s) => s.length > 0);
|
|
7531
|
+
let used = fixed.reduce((n, s) => n + est(s), 0);
|
|
7532
|
+
const kept = [];
|
|
7533
|
+
const dropped = [];
|
|
7534
|
+
const ranked = opts.sections.map((s, i) => ({
|
|
7535
|
+
s,
|
|
7536
|
+
i
|
|
7537
|
+
})).filter((x) => x.s.text.length > 0).sort((a, b) => b.s.priority - a.s.priority || a.i - b.i);
|
|
7538
|
+
for (const { s } of ranked) {
|
|
7539
|
+
const t = est(s.text);
|
|
7540
|
+
if (used + t <= opts.budgetTokens) {
|
|
7541
|
+
used += t;
|
|
7542
|
+
kept.push(s);
|
|
7543
|
+
} else dropped.push(s.name);
|
|
7544
|
+
}
|
|
7545
|
+
return {
|
|
7546
|
+
text: [...fixed, ...kept.map((s) => s.text)].join(opts.joiner ?? "\n\n"),
|
|
7547
|
+
kept: kept.map((s) => s.name),
|
|
7548
|
+
dropped,
|
|
7549
|
+
usedTokens: used,
|
|
7550
|
+
budgetTokens: opts.budgetTokens
|
|
7551
|
+
};
|
|
7552
|
+
}
|
|
7553
|
+
var CHARS_PER_TOKEN, estimateTokens;
|
|
7554
|
+
var init_assemble = __esmMin((() => {
|
|
7555
|
+
CHARS_PER_TOKEN = 3.6;
|
|
7556
|
+
estimateTokens = (s) => Math.ceil(s.length / CHARS_PER_TOKEN);
|
|
7557
|
+
}));
|
|
7455
7558
|
// packages/memory/src/index.ts
|
|
7456
7559
|
var init_src$8 = __esmMin((() => {
|
|
7457
7560
|
init_embed();
|
|
7561
|
+
init_assemble();
|
|
7458
7562
|
}));
|
|
7459
7563
|
// packages/embed/src/index.ts
|
|
7460
7564
|
var src_exports$6 = /* @__PURE__ */ __exportAll({
|
|
@@ -7820,17 +7924,17 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7820
7924
|
label: "sdxl-turbo 512",
|
|
7821
7925
|
speed: "steady",
|
|
7822
7926
|
verdict: "not run yet",
|
|
7823
|
-
unrunnable: "not run yet. sdxl
|
|
7927
|
+
unrunnable: "not run yet. the sdxl pipeline is written; the export's graph names and fp16 io are inferred and unchecked.",
|
|
7824
7928
|
group: "good",
|
|
7825
7929
|
provides: ["imagegen"],
|
|
7826
7930
|
provider: "ort",
|
|
7827
7931
|
source: {
|
|
7828
7932
|
repo: "webnn/sdxl-turbo",
|
|
7829
7933
|
files: [
|
|
7830
|
-
{ path: "
|
|
7831
|
-
{ path: "
|
|
7832
|
-
{ path: "
|
|
7833
|
-
{ path: "
|
|
7934
|
+
{ path: "onnx/text_encoder_model_q4f16.onnx" },
|
|
7935
|
+
{ path: "onnx/text_encoder_2_model_q4f16.onnx" },
|
|
7936
|
+
{ path: "onnx/unet_model_q4f16.onnx" },
|
|
7937
|
+
{ path: "onnx/vae_decoder_model_q4f16.onnx" }
|
|
7834
7938
|
]
|
|
7835
7939
|
},
|
|
7836
7940
|
sizeMB: 2548,
|
|
@@ -7844,7 +7948,11 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7844
7948
|
commercial: "unknown",
|
|
7845
7949
|
place: "gpu",
|
|
7846
7950
|
runtime: "onnxruntime-web@1.27.0",
|
|
7847
|
-
notes: [
|
|
7951
|
+
notes: [
|
|
7952
|
+
"two text encoders, pooled embeddings and time ids, on generateXl",
|
|
7953
|
+
"fp16 inputs and outputs per the export's README (--force_fp16_inputs); timestep dtype and hidden state names inferred",
|
|
7954
|
+
"the highest quality of the three image models"
|
|
7955
|
+
],
|
|
7848
7956
|
form: {
|
|
7849
7957
|
steps: {
|
|
7850
7958
|
min: 1,
|
|
@@ -7857,27 +7965,256 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7857
7965
|
spacing: "trailing",
|
|
7858
7966
|
note: "distilled from sdxl. 1 to 4 steps, no negative prompt. the best looking of the three.",
|
|
7859
7967
|
tokenizer: "Xenova/clip-vit-base-patch16",
|
|
7860
|
-
graphs
|
|
7968
|
+
graphs: {
|
|
7969
|
+
textEncoder: "text_encoder_model_q4f16",
|
|
7970
|
+
textEncoder2: "text_encoder_2_model_q4f16",
|
|
7971
|
+
unet: "unet_model_q4f16",
|
|
7972
|
+
vaeDecoder: "vae_decoder_model_q4f16"
|
|
7973
|
+
},
|
|
7974
|
+
pipeline: "sdxl",
|
|
7975
|
+
xl: {
|
|
7976
|
+
io: "float16",
|
|
7977
|
+
timestep: "float16"
|
|
7978
|
+
}
|
|
7861
7979
|
}
|
|
7862
7980
|
}];
|
|
7863
7981
|
}));
|
|
7982
|
+
// packages/imagegen/src/xl.ts
|
|
7983
|
+
/** Float32 to IEEE 754 half bits, round to nearest even. */
|
|
7984
|
+
function toHalf(f) {
|
|
7985
|
+
const out = new Uint16Array(f.length);
|
|
7986
|
+
const b = /* @__PURE__ */ new Float32Array(1);
|
|
7987
|
+
const u = new Uint32Array(b.buffer);
|
|
7988
|
+
for (let i = 0; i < f.length; i++) {
|
|
7989
|
+
b[0] = f[i];
|
|
7990
|
+
const x = u[0];
|
|
7991
|
+
const sign = x >>> 16 & 32768;
|
|
7992
|
+
const exp = x >>> 23 & 255;
|
|
7993
|
+
let mant = x & 8388607;
|
|
7994
|
+
if (exp === 255) {
|
|
7995
|
+
out[i] = sign | 31744 | (mant ? 512 : 0);
|
|
7996
|
+
continue;
|
|
7997
|
+
}
|
|
7998
|
+
const e = exp - 127 + 15;
|
|
7999
|
+
if (e >= 31) {
|
|
8000
|
+
out[i] = sign | 31744;
|
|
8001
|
+
continue;
|
|
8002
|
+
}
|
|
8003
|
+
if (e <= 0) {
|
|
8004
|
+
if (e < -10) {
|
|
8005
|
+
out[i] = sign;
|
|
8006
|
+
continue;
|
|
8007
|
+
}
|
|
8008
|
+
mant |= 8388608;
|
|
8009
|
+
const shift = 14 - e;
|
|
8010
|
+
let h = mant >>> shift;
|
|
8011
|
+
const rem = mant & (1 << shift) - 1;
|
|
8012
|
+
const half = 1 << shift - 1;
|
|
8013
|
+
if (rem > half || rem === half && h & 1) h++;
|
|
8014
|
+
out[i] = sign | h;
|
|
8015
|
+
continue;
|
|
8016
|
+
}
|
|
8017
|
+
let h = e << 10 | mant >>> 13;
|
|
8018
|
+
const rem = mant & 8191;
|
|
8019
|
+
if (rem > 4096 || rem === 4096 && h & 1) h++;
|
|
8020
|
+
out[i] = sign | h;
|
|
8021
|
+
}
|
|
8022
|
+
return out;
|
|
8023
|
+
}
|
|
8024
|
+
/** IEEE 754 half bits to float32. */
|
|
8025
|
+
function fromHalf(h) {
|
|
8026
|
+
const out = new Float32Array(h.length);
|
|
8027
|
+
for (let i = 0; i < h.length; i++) {
|
|
8028
|
+
const v = h[i];
|
|
8029
|
+
const s = v & 32768 ? -1 : 1;
|
|
8030
|
+
const e = v >>> 10 & 31;
|
|
8031
|
+
const m = v & 1023;
|
|
8032
|
+
out[i] = e === 0 ? s * m * 2 ** -24 : e === 31 ? m ? NaN : s * Infinity : s * (1 + m / 1024) * 2 ** (e - 15);
|
|
8033
|
+
}
|
|
8034
|
+
return out;
|
|
8035
|
+
}
|
|
8036
|
+
/** An output's floats; fp16 outputs (type "float16" or Uint16Array data) are decoded. */
|
|
8037
|
+
function floatsOf(t) {
|
|
8038
|
+
if (t.type === "float16" || t.data instanceof Uint16Array) return fromHalf(t.data);
|
|
8039
|
+
return Float32Array.from(t.data);
|
|
8040
|
+
}
|
|
8041
|
+
/** CLIP ids for the second encoder: up to the first end token, then `pad` to 77. */
|
|
8042
|
+
function padIds2(ids, pad = 0) {
|
|
8043
|
+
const list = Array.from(ids);
|
|
8044
|
+
const end = list.indexOf(EOT);
|
|
8045
|
+
return padIds(end >= 0 ? list.slice(0, end + 1) : list, 77, pad);
|
|
8046
|
+
}
|
|
8047
|
+
function pick(outs, name, fallback, what) {
|
|
8048
|
+
for (const n of [name, ...fallback]) if (outs[n]) return outs[n];
|
|
8049
|
+
throw new Error(`${what}: no ${name} output; the graph gives ${Object.keys(outs).join(", ") || "none"}`);
|
|
8050
|
+
}
|
|
8051
|
+
/**
|
|
8052
|
+
* SDXL-Turbo text to image: both encoders, the joined hidden states and
|
|
8053
|
+
* pooled embedding, the seeded Euler loop with `text_embeds` and
|
|
8054
|
+
* `time_ids` on every UNet call, then the VAE. Guidance above 1 runs the
|
|
8055
|
+
* UNet on the negative too. Throws when `size` is not a multiple of 8.
|
|
8056
|
+
*/
|
|
8057
|
+
async function generateXl(ort, s, tokenize, o) {
|
|
8058
|
+
const io = {
|
|
8059
|
+
...XL_IO,
|
|
8060
|
+
...o.xl ?? {}
|
|
8061
|
+
};
|
|
8062
|
+
const now = o.now ?? (() => globalThis.performance ? performance.now() : Date.now());
|
|
8063
|
+
const run = o.run ?? ((fn) => fn());
|
|
8064
|
+
const steps = Math.max(1, Math.min(50, o.steps ?? 1));
|
|
8065
|
+
const guidance = o.guidance ?? 1;
|
|
8066
|
+
const seed = (o.seed ?? 0) >>> 0;
|
|
8067
|
+
const size = o.size ?? 512;
|
|
8068
|
+
if (size % 8) throw new Error("size must be a multiple of 8");
|
|
8069
|
+
const lw = size / 8;
|
|
8070
|
+
const n = 4 * lw * lw;
|
|
8071
|
+
const ms = {
|
|
8072
|
+
text: 0,
|
|
8073
|
+
unet: 0,
|
|
8074
|
+
vae: 0
|
|
8075
|
+
};
|
|
8076
|
+
const T = ort.Tensor;
|
|
8077
|
+
const float = (data, dims) => io.io === "float16" ? new T("float16", toHalf(data), dims) : new T("float32", data, dims);
|
|
8078
|
+
let t = now();
|
|
8079
|
+
const encode = async (text) => {
|
|
8080
|
+
const ids = await tokenize(text.length ? text : " ");
|
|
8081
|
+
const a = await run(() => s.textEncoder.run({ input_ids: new ort.Tensor("int32", padIds(ids), [1, 77]) }));
|
|
8082
|
+
const b = await run(() => s.textEncoder2.run({ input_ids: new ort.Tensor("int32", padIds2(ids, io.pad2), [1, 77]) }));
|
|
8083
|
+
const h1 = floatsOf(pick(a, io.hidden1, ["last_hidden_state"], "text encoder"));
|
|
8084
|
+
const h2 = floatsOf(pick(b, io.hidden2, ["last_hidden_state"], "text encoder 2"));
|
|
8085
|
+
const pooled = floatsOf(pick(b, io.pooled, ["pooler_output"], "text encoder 2"));
|
|
8086
|
+
const w1 = h1.length / 77;
|
|
8087
|
+
const w2 = h2.length / 77;
|
|
8088
|
+
const joined = new Float32Array(77 * (w1 + w2));
|
|
8089
|
+
for (let i = 0; i < 77; i++) {
|
|
8090
|
+
joined.set(h1.subarray(i * w1, (i + 1) * w1), i * (w1 + w2));
|
|
8091
|
+
joined.set(h2.subarray(i * w2, (i + 1) * w2), i * (w1 + w2) + w1);
|
|
8092
|
+
}
|
|
8093
|
+
return {
|
|
8094
|
+
hidden: float(joined, [
|
|
8095
|
+
1,
|
|
8096
|
+
77,
|
|
8097
|
+
w1 + w2
|
|
8098
|
+
]),
|
|
8099
|
+
pooled: float(pooled, [1, pooled.length])
|
|
8100
|
+
};
|
|
8101
|
+
};
|
|
8102
|
+
const cond = await encode(o.prompt);
|
|
8103
|
+
const uncond = guidance > 1 ? await encode(o.negative ?? "") : null;
|
|
8104
|
+
ms.text = now() - t;
|
|
8105
|
+
o.onStep?.({
|
|
8106
|
+
stage: "text",
|
|
8107
|
+
step: 0,
|
|
8108
|
+
steps,
|
|
8109
|
+
ms: ms.text
|
|
8110
|
+
});
|
|
8111
|
+
const timeIds = float(Float32Array.from([
|
|
8112
|
+
size,
|
|
8113
|
+
size,
|
|
8114
|
+
0,
|
|
8115
|
+
0,
|
|
8116
|
+
size,
|
|
8117
|
+
size
|
|
8118
|
+
]), [1, 6]);
|
|
8119
|
+
const stepTensor = (ts) => io.timestep === "int64" ? new ort.Tensor("int64", BigInt64Array.from([BigInt(ts)]), [1]) : float(Float32Array.from([ts]), [1]);
|
|
8120
|
+
const plan = eulerPlan(steps, o.spacing ?? "trailing");
|
|
8121
|
+
const randn = gaussian(o.rng ?? mulberry32(seed));
|
|
8122
|
+
const latent = new Float32Array(n);
|
|
8123
|
+
const s0 = plan.sigmas[0];
|
|
8124
|
+
const init = o.spacing === "leading" ? Math.sqrt(s0 * s0 + 1) : s0;
|
|
8125
|
+
for (let i = 0; i < n; i++) latent[i] = randn() * init;
|
|
8126
|
+
const final = await euler(latent, plan, async (scaled, timestep, step) => {
|
|
8127
|
+
const t0 = now();
|
|
8128
|
+
const unet = async (c) => {
|
|
8129
|
+
const u = await run(() => s.unet.run({
|
|
8130
|
+
sample: float(scaled, [
|
|
8131
|
+
1,
|
|
8132
|
+
4,
|
|
8133
|
+
lw,
|
|
8134
|
+
lw
|
|
8135
|
+
]),
|
|
8136
|
+
timestep: stepTensor(timestep),
|
|
8137
|
+
encoder_hidden_states: c.hidden,
|
|
8138
|
+
text_embeds: c.pooled,
|
|
8139
|
+
time_ids: timeIds
|
|
8140
|
+
}));
|
|
8141
|
+
return floatsOf(u.out_sample ?? Object.values(u)[0]);
|
|
8142
|
+
};
|
|
8143
|
+
const c = await unet(cond);
|
|
8144
|
+
let e = c;
|
|
8145
|
+
if (uncond) {
|
|
8146
|
+
const u = await unet(uncond);
|
|
8147
|
+
e = new Float32Array(c.length);
|
|
8148
|
+
for (let i = 0; i < e.length; i++) e[i] = u[i] + guidance * (c[i] - u[i]);
|
|
8149
|
+
}
|
|
8150
|
+
const d = now() - t0;
|
|
8151
|
+
ms.unet += d;
|
|
8152
|
+
o.onStep?.({
|
|
8153
|
+
stage: "denoise",
|
|
8154
|
+
step: step + 1,
|
|
8155
|
+
steps,
|
|
8156
|
+
ms: d
|
|
8157
|
+
});
|
|
8158
|
+
return e;
|
|
8159
|
+
}, o.signal);
|
|
8160
|
+
t = now();
|
|
8161
|
+
const vin = new Float32Array(n);
|
|
8162
|
+
for (let i = 0; i < n; i++) vin[i] = final[i] / io.vaeScale;
|
|
8163
|
+
const v = await run(() => s.vaeDecoder.run({ latent_sample: float(vin, [
|
|
8164
|
+
1,
|
|
8165
|
+
4,
|
|
8166
|
+
lw,
|
|
8167
|
+
lw
|
|
8168
|
+
]) }));
|
|
8169
|
+
ms.vae = now() - t;
|
|
8170
|
+
o.onStep?.({
|
|
8171
|
+
stage: "decode",
|
|
8172
|
+
step: steps,
|
|
8173
|
+
steps,
|
|
8174
|
+
ms: ms.vae
|
|
8175
|
+
});
|
|
8176
|
+
return {
|
|
8177
|
+
width: size,
|
|
8178
|
+
height: size,
|
|
8179
|
+
rgba: toRgba(floatsOf(v.sample ?? Object.values(v)[0]), size, size),
|
|
8180
|
+
seed,
|
|
8181
|
+
ms
|
|
8182
|
+
};
|
|
8183
|
+
}
|
|
8184
|
+
var XL_IO, EOT;
|
|
8185
|
+
var init_xl = __esmMin((() => {
|
|
8186
|
+
init_pipeline();
|
|
8187
|
+
init_schedule();
|
|
8188
|
+
XL_IO = {
|
|
8189
|
+
io: "float32",
|
|
8190
|
+
timestep: "int64",
|
|
8191
|
+
hidden1: "hidden_states.11",
|
|
8192
|
+
hidden2: "hidden_states.31",
|
|
8193
|
+
pooled: "text_embeds",
|
|
8194
|
+
pad2: 0,
|
|
8195
|
+
vaeScale: .13025
|
|
8196
|
+
};
|
|
8197
|
+
EOT = 49407;
|
|
8198
|
+
}));
|
|
7864
8199
|
// packages/imagegen/src/hub.ts
|
|
7865
8200
|
/** Add the image records to the hub's registry. */
|
|
7866
8201
|
function attachImagegen(hub) {
|
|
7867
8202
|
hub.registry.add(...IMAGEGEN_RECORDS);
|
|
7868
8203
|
}
|
|
7869
|
-
/** The
|
|
8204
|
+
/** The sessions of a loaded model, by the form's graph names: three, or four with SDXL's second text encoder. */
|
|
7870
8205
|
function sessionsOf(m, form) {
|
|
7871
8206
|
const pick = (k) => {
|
|
7872
8207
|
const s = m.sessions[k];
|
|
7873
8208
|
if (!s) throw new Error(`the loaded model has no ${k} graph; it has ${Object.keys(m.sessions).join(", ") || "none"}`);
|
|
7874
8209
|
return s;
|
|
7875
8210
|
};
|
|
7876
|
-
|
|
8211
|
+
const out = {
|
|
7877
8212
|
textEncoder: pick(form.graphs.textEncoder),
|
|
7878
8213
|
unet: pick(form.graphs.unet),
|
|
7879
8214
|
vaeDecoder: pick(form.graphs.vaeDecoder)
|
|
7880
8215
|
};
|
|
8216
|
+
if (form.pipeline === "sdxl") out.textEncoder2 = pick(form.graphs.textEncoder2 ?? "text_encoder_2");
|
|
8217
|
+
return out;
|
|
7881
8218
|
}
|
|
7882
8219
|
/** Clamp a request to what the form allows, with the form's defaults. */
|
|
7883
8220
|
function applyForm(form, o) {
|
|
@@ -7898,9 +8235,15 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7898
8235
|
/**
|
|
7899
8236
|
* Load an image model through the hub: a record id (`{ id: "sd-1.5" }`)
|
|
7900
8237
|
* or the capability ("imagegen", which the hub routes, or sends to the
|
|
7901
|
-
* stub in stub mode). A record
|
|
8238
|
+
* stub in stub mode). A picker record named by id (`sdxl-turbo`) is added
|
|
8239
|
+
* to the registry first. A record without a form (the stub) gets
|
|
8240
|
+
* SD-Turbo's. An SDXL form runs `generateXl` behind the same interface.
|
|
7902
8241
|
*/
|
|
7903
8242
|
async function loadImagegen(hub, what = "imagegen", o = {}) {
|
|
8243
|
+
if (typeof what === "object" && !hub.registry.get(what.id)) {
|
|
8244
|
+
const listed = IMAGEGEN_PICKER_RECORDS.find((r) => r.id === what.id);
|
|
8245
|
+
if (listed) hub.registry.add(listed);
|
|
8246
|
+
}
|
|
7904
8247
|
const loaded = await hub.use(what, o);
|
|
7905
8248
|
const form = formOf(loaded.record) ?? IMAGEGEN_RECORDS[0].form;
|
|
7906
8249
|
let sessions;
|
|
@@ -7915,16 +8258,21 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7915
8258
|
record: loaded.record,
|
|
7916
8259
|
form,
|
|
7917
8260
|
sessions,
|
|
7918
|
-
generate(tokenize, req) {
|
|
8261
|
+
async generate(tokenize, req) {
|
|
7919
8262
|
const { runOptions, ...rest } = req;
|
|
7920
8263
|
const run = (fn) => hub.run(loaded, () => fn(), {
|
|
7921
8264
|
...runOptions ?? {},
|
|
7922
8265
|
...rest.signal ? { signal: rest.signal } : {}
|
|
7923
8266
|
});
|
|
7924
|
-
|
|
8267
|
+
const opts = {
|
|
7925
8268
|
...applyForm(form, rest),
|
|
7926
8269
|
run
|
|
7927
|
-
}
|
|
8270
|
+
};
|
|
8271
|
+
if (form.pipeline === "sdxl") return generateXl(loaded.value.ort, sessions, tokenize, form.xl ? {
|
|
8272
|
+
...opts,
|
|
8273
|
+
xl: form.xl
|
|
8274
|
+
} : opts);
|
|
8275
|
+
return generate(loaded.value.ort, sessions, tokenize, opts);
|
|
7928
8276
|
},
|
|
7929
8277
|
release() {
|
|
7930
8278
|
hub.release(loaded);
|
|
@@ -7971,6 +8319,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7971
8319
|
var init_hub = __esmMin((() => {
|
|
7972
8320
|
init_pipeline();
|
|
7973
8321
|
init_records$3();
|
|
8322
|
+
init_xl();
|
|
7974
8323
|
FormError = class extends Error {
|
|
7975
8324
|
name = "FormError";
|
|
7976
8325
|
};
|
|
@@ -7981,21 +8330,27 @@ var HackbuildAiViews = (function(exports) {
|
|
|
7981
8330
|
IMAGEGEN_PICKER_RECORDS: () => IMAGEGEN_PICKER_RECORDS,
|
|
7982
8331
|
IMAGEGEN_RECORDS: () => IMAGEGEN_RECORDS,
|
|
7983
8332
|
VAE_SCALE: () => VAE_SCALE,
|
|
8333
|
+
XL_IO: () => XL_IO,
|
|
7984
8334
|
applyForm: () => applyForm,
|
|
7985
8335
|
attachImagegen: () => attachImagegen,
|
|
7986
8336
|
euler: () => euler,
|
|
7987
8337
|
eulerPlan: () => eulerPlan,
|
|
8338
|
+
floatsOf: () => floatsOf,
|
|
7988
8339
|
formOf: () => formOf,
|
|
8340
|
+
fromHalf: () => fromHalf,
|
|
7989
8341
|
gaussian: () => gaussian,
|
|
7990
8342
|
generate: () => generate,
|
|
8343
|
+
generateXl: () => generateXl,
|
|
7991
8344
|
leadingTimesteps: () => leadingTimesteps,
|
|
7992
8345
|
loadImagegen: () => loadImagegen,
|
|
7993
8346
|
loadLabel: () => loadLabel,
|
|
7994
8347
|
mulberry32: () => mulberry32,
|
|
7995
8348
|
padIds: () => padIds,
|
|
8349
|
+
padIds2: () => padIds2,
|
|
7996
8350
|
sessionsOf: () => sessionsOf,
|
|
7997
8351
|
sigmas: () => sigmas,
|
|
7998
8352
|
stubImagegenModel: () => stubImagegenModel,
|
|
8353
|
+
toHalf: () => toHalf,
|
|
7999
8354
|
toRgba: () => toRgba,
|
|
8000
8355
|
trailingTimesteps: () => trailingTimesteps
|
|
8001
8356
|
});
|
|
@@ -8004,6 +8359,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
8004
8359
|
init_pipeline();
|
|
8005
8360
|
init_records$3();
|
|
8006
8361
|
init_hub();
|
|
8362
|
+
init_xl();
|
|
8007
8363
|
}));
|
|
8008
8364
|
// packages/speak/src/text.ts
|
|
8009
8365
|
/**
|
|
@@ -12333,7 +12689,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
12333
12689
|
licence: "AGPL-3.0 upstream (Ultralytics FastSAM); the export's card says apache-2.0",
|
|
12334
12690
|
commercial: false,
|
|
12335
12691
|
place: "cpu-worker",
|
|
12336
|
-
notes: ["finds every mask in one pass on onnxruntime-web
|
|
12692
|
+
notes: ["finds every mask in one pass on onnxruntime-web; the original page loaded a 93 MB build (vendor, its review)", "segment everything: prototype masks, nms, then a pick by click (segmentEverything, instanceAt)"]
|
|
12337
12693
|
},
|
|
12338
12694
|
{
|
|
12339
12695
|
id: "scrfd-10g",
|
|
@@ -12719,7 +13075,47 @@ var HackbuildAiViews = (function(exports) {
|
|
|
12719
13075
|
}
|
|
12720
13076
|
return nms(dets, o.iou ?? .45, o.max ?? 13);
|
|
12721
13077
|
}
|
|
12722
|
-
/**
|
|
13078
|
+
/**
|
|
13079
|
+
* Decode an end to end output, [1, boxes, 6] as x1, y1, x2, y2, score and
|
|
13080
|
+
* class in letterbox pixels (the YOLOv10 export layout, after the
|
|
13081
|
+
* model's own one to one selection), into boxes in source pixels. The
|
|
13082
|
+
* per class NMS pass still runs, so an export that leaves near duplicates
|
|
13083
|
+
* gives one box per object.
|
|
13084
|
+
*/
|
|
13085
|
+
function decodeYoloEnd2End(out, dims, lb, src, o = {}) {
|
|
13086
|
+
const n = dims[dims.length - 2];
|
|
13087
|
+
const stride = dims[dims.length - 1];
|
|
13088
|
+
const thr = o.scoreThreshold ?? .25;
|
|
13089
|
+
const labels = o.labels ?? COCO_LABELS;
|
|
13090
|
+
const dets = [];
|
|
13091
|
+
for (let a = 0; a < n; a++) {
|
|
13092
|
+
const r = a * stride;
|
|
13093
|
+
const score = out[r + 4];
|
|
13094
|
+
if (!(score > thr)) continue;
|
|
13095
|
+
const c = Math.round(out[r + 5]);
|
|
13096
|
+
const x0 = Math.max(0, (out[r] - lb.padX) / lb.scale);
|
|
13097
|
+
const y0 = Math.max(0, (out[r + 1] - lb.padY) / lb.scale);
|
|
13098
|
+
const x1 = Math.min(src.width, (out[r + 2] - lb.padX) / lb.scale);
|
|
13099
|
+
const y1 = Math.min(src.height, (out[r + 3] - lb.padY) / lb.scale);
|
|
13100
|
+
if (x1 <= x0 || y1 <= y0) continue;
|
|
13101
|
+
dets.push({
|
|
13102
|
+
label: labels[c] ?? String(c),
|
|
13103
|
+
score,
|
|
13104
|
+
box: {
|
|
13105
|
+
x: x0,
|
|
13106
|
+
y: y0,
|
|
13107
|
+
w: x1 - x0,
|
|
13108
|
+
h: y1 - y0
|
|
13109
|
+
}
|
|
13110
|
+
});
|
|
13111
|
+
}
|
|
13112
|
+
return nms(dets, o.iou ?? .45, o.max ?? 13);
|
|
13113
|
+
}
|
|
13114
|
+
/** True when an output is the end to end layout (last axis 6, boxes on the axis before it), false for the [4 + classes, anchors] layout. */
|
|
13115
|
+
function isEnd2End(dims) {
|
|
13116
|
+
return dims[dims.length - 1] === 6 && dims[dims.length - 2] > 6;
|
|
13117
|
+
}
|
|
13118
|
+
/** Wrap an ort model as a Detector; the output layout (YOLOv8 anchors or YOLOv10 end to end) is read from its dims. Images must be Pixels, or `toPixels` must turn them into Pixels. */
|
|
12723
13119
|
function yoloDetector(m, o = {}) {
|
|
12724
13120
|
const size = o.size ?? 640;
|
|
12725
13121
|
return {
|
|
@@ -12733,11 +13129,13 @@ var HackbuildAiViews = (function(exports) {
|
|
|
12733
13129
|
size
|
|
12734
13130
|
]) };
|
|
12735
13131
|
const t = (await m.session.run(feeds))[m.session.outputNames[0]];
|
|
12736
|
-
|
|
13132
|
+
const d = {
|
|
12737
13133
|
...opts.scoreThreshold !== void 0 ? { scoreThreshold: opts.scoreThreshold } : {},
|
|
12738
13134
|
...opts.maxResults !== void 0 ? { max: opts.maxResults } : {},
|
|
12739
13135
|
...o.labels ? { labels: o.labels } : {}
|
|
12740
|
-
}
|
|
13136
|
+
};
|
|
13137
|
+
const out = t.data;
|
|
13138
|
+
return isEnd2End(t.dims) ? decodeYoloEnd2End(out, t.dims, lb, px, d) : decodeYolo(out, t.dims, lb, px, d);
|
|
12741
13139
|
},
|
|
12742
13140
|
dispose: () => m.dispose()
|
|
12743
13141
|
};
|
|
@@ -12746,9 +13144,165 @@ var HackbuildAiViews = (function(exports) {
|
|
|
12746
13144
|
function detectCadenceMs(lastLatencyMs) {
|
|
12747
13145
|
return Math.max(450, 4 * lastLatencyMs);
|
|
12748
13146
|
}
|
|
12749
|
-
var COCO_LABELS;
|
|
13147
|
+
var COCO_LABELS, DETECT_SIZES;
|
|
12750
13148
|
var init_yolo = __esmMin((() => {
|
|
12751
13149
|
COCO_LABELS = "person,bicycle,car,motorcycle,airplane,bus,train,truck,boat,traffic light,fire hydrant,stop sign,parking meter,bench,bird,cat,dog,horse,sheep,cow,elephant,bear,zebra,giraffe,backpack,umbrella,handbag,tie,suitcase,frisbee,skis,snowboard,sports ball,kite,baseball bat,baseball glove,skateboard,surfboard,tennis racket,bottle,wine glass,cup,fork,knife,spoon,bowl,banana,apple,sandwich,orange,broccoli,carrot,hot dog,pizza,donut,cake,chair,couch,potted plant,bed,dining table,toilet,tv,laptop,mouse,remote,keyboard,cell phone,microwave,oven,toaster,sink,refrigerator,book,clock,vase,scissors,teddy bear,hair drier,toothbrush".split(",");
|
|
13150
|
+
DETECT_SIZES = {
|
|
13151
|
+
n: "yolov10n",
|
|
13152
|
+
s: "yolov10s",
|
|
13153
|
+
m: "yolov10m"
|
|
13154
|
+
};
|
|
13155
|
+
}));
|
|
13156
|
+
// packages/vision/src/fastsam.ts
|
|
13157
|
+
function agnosticNms(items, thr, max) {
|
|
13158
|
+
const sorted = [...items].sort((a, b) => b.score - a.score);
|
|
13159
|
+
const keep = [];
|
|
13160
|
+
for (const d of sorted) {
|
|
13161
|
+
if (keep.some((k) => iou(k.box, d.box) > thr)) continue;
|
|
13162
|
+
keep.push(d);
|
|
13163
|
+
if (keep.length >= max) break;
|
|
13164
|
+
}
|
|
13165
|
+
return keep;
|
|
13166
|
+
}
|
|
13167
|
+
/**
|
|
13168
|
+
* Decode the two FastSAM outputs into instances in source pixels, best
|
|
13169
|
+
* first: boxes, scores, areas and one mask each (255 inside, `score` on
|
|
13170
|
+
* the mask too).
|
|
13171
|
+
*/
|
|
13172
|
+
function decodeFastSam(out, dims, protos, protoDims, lb, src, o = {}) {
|
|
13173
|
+
const rows = dims[dims.length - 2];
|
|
13174
|
+
const n = dims[dims.length - 1];
|
|
13175
|
+
const k = protoDims[protoDims.length - 3];
|
|
13176
|
+
const ph = protoDims[protoDims.length - 2];
|
|
13177
|
+
const pw = protoDims[protoDims.length - 1];
|
|
13178
|
+
const classes = rows - 4 - k;
|
|
13179
|
+
if (classes < 1) throw new RangeError(`decodeFastSam: ${rows} rows leave no class score beside ${k} mask coefficients`);
|
|
13180
|
+
const conf = o.confidence ?? .4;
|
|
13181
|
+
const cands = [];
|
|
13182
|
+
for (let a = 0; a < n; a++) {
|
|
13183
|
+
let score = 0;
|
|
13184
|
+
for (let c = 0; c < classes; c++) score = Math.max(score, out[(4 + c) * n + a]);
|
|
13185
|
+
if (!(score > conf)) continue;
|
|
13186
|
+
const cx = out[a];
|
|
13187
|
+
const cy = out[n + a];
|
|
13188
|
+
const w = out[2 * n + a];
|
|
13189
|
+
const h = out[3 * n + a];
|
|
13190
|
+
const x0 = Math.max(0, (cx - w / 2 - lb.padX) / lb.scale);
|
|
13191
|
+
const y0 = Math.max(0, (cy - h / 2 - lb.padY) / lb.scale);
|
|
13192
|
+
const x1 = Math.min(src.width, (cx + w / 2 - lb.padX) / lb.scale);
|
|
13193
|
+
const y1 = Math.min(src.height, (cy + h / 2 - lb.padY) / lb.scale);
|
|
13194
|
+
if (x1 <= x0 || y1 <= y0) continue;
|
|
13195
|
+
cands.push({
|
|
13196
|
+
box: {
|
|
13197
|
+
x: x0,
|
|
13198
|
+
y: y0,
|
|
13199
|
+
w: x1 - x0,
|
|
13200
|
+
h: y1 - y0
|
|
13201
|
+
},
|
|
13202
|
+
score,
|
|
13203
|
+
a,
|
|
13204
|
+
lx: cx,
|
|
13205
|
+
ly: cy,
|
|
13206
|
+
lw: w,
|
|
13207
|
+
lh: h
|
|
13208
|
+
});
|
|
13209
|
+
}
|
|
13210
|
+
const kept = agnosticNms(cands, o.iou ?? .9, o.max ?? 100);
|
|
13211
|
+
const sig = o.sigmoid ?? true;
|
|
13212
|
+
const cut = o.maskThreshold ?? .5;
|
|
13213
|
+
const minArea = o.minArea ?? 64;
|
|
13214
|
+
const plane = ph * pw;
|
|
13215
|
+
const toProto = pw / lb.size;
|
|
13216
|
+
const out_ = [];
|
|
13217
|
+
const coef = new Float32Array(k);
|
|
13218
|
+
const low = new Float32Array(plane);
|
|
13219
|
+
for (const d of kept) {
|
|
13220
|
+
for (let j = 0; j < k; j++) coef[j] = out[(4 + classes + j) * n + d.a];
|
|
13221
|
+
const px0 = Math.max(0, Math.floor((d.lx - d.lw / 2) * toProto) - 1);
|
|
13222
|
+
const py0 = Math.max(0, Math.floor((d.ly - d.lh / 2) * toProto) - 1);
|
|
13223
|
+
const px1 = Math.min(pw - 1, Math.ceil((d.lx + d.lw / 2) * toProto) + 1);
|
|
13224
|
+
const py1 = Math.min(ph - 1, Math.ceil((d.ly + d.lh / 2) * toProto) + 1);
|
|
13225
|
+
for (let y = py0; y <= py1; y++) for (let x = px0; x <= px1; x++) {
|
|
13226
|
+
let v = 0;
|
|
13227
|
+
const i = y * pw + x;
|
|
13228
|
+
for (let j = 0; j < k; j++) v += coef[j] * protos[j * plane + i];
|
|
13229
|
+
low[i] = sig ? 1 / (1 + Math.exp(-v)) : v;
|
|
13230
|
+
}
|
|
13231
|
+
const data = new Uint8Array(src.width * src.height);
|
|
13232
|
+
const bx0 = Math.floor(d.box.x);
|
|
13233
|
+
const by0 = Math.floor(d.box.y);
|
|
13234
|
+
const bx1 = Math.min(src.width, Math.ceil(d.box.x + d.box.w));
|
|
13235
|
+
const by1 = Math.min(src.height, Math.ceil(d.box.y + d.box.h));
|
|
13236
|
+
let area = 0;
|
|
13237
|
+
for (let y = by0; y < by1; y++) {
|
|
13238
|
+
const fy = Math.min(py1, Math.max(py0, ((y + .5) * lb.scale + lb.padY) * toProto - .5));
|
|
13239
|
+
const y0 = Math.floor(fy);
|
|
13240
|
+
const y1 = Math.min(py1, y0 + 1);
|
|
13241
|
+
const ty = fy - y0;
|
|
13242
|
+
for (let x = bx0; x < bx1; x++) {
|
|
13243
|
+
const fx = Math.min(px1, Math.max(px0, ((x + .5) * lb.scale + lb.padX) * toProto - .5));
|
|
13244
|
+
const x0 = Math.floor(fx);
|
|
13245
|
+
const x1 = Math.min(px1, x0 + 1);
|
|
13246
|
+
const tx = fx - x0;
|
|
13247
|
+
const top = low[y0 * pw + x0] * (1 - tx) + low[y0 * pw + x1] * tx;
|
|
13248
|
+
const bot = low[y1 * pw + x0] * (1 - tx) + low[y1 * pw + x1] * tx;
|
|
13249
|
+
if (top * (1 - ty) + bot * ty > cut) {
|
|
13250
|
+
data[y * src.width + x] = 255;
|
|
13251
|
+
area++;
|
|
13252
|
+
}
|
|
13253
|
+
}
|
|
13254
|
+
}
|
|
13255
|
+
if (area < minArea) continue;
|
|
13256
|
+
out_.push({
|
|
13257
|
+
box: d.box,
|
|
13258
|
+
score: d.score,
|
|
13259
|
+
area,
|
|
13260
|
+
mask: {
|
|
13261
|
+
width: src.width,
|
|
13262
|
+
height: src.height,
|
|
13263
|
+
data,
|
|
13264
|
+
score: d.score
|
|
13265
|
+
}
|
|
13266
|
+
});
|
|
13267
|
+
}
|
|
13268
|
+
return out_;
|
|
13269
|
+
}
|
|
13270
|
+
/** Wrap a FastSAM ort model as an {@link EverythingSegmenter}. Outputs are told apart by rank: the 4D one holds the prototypes. Images must be Pixels, or `toPixels` must turn them into Pixels. */
|
|
13271
|
+
function fastSamSegmenter(m, o = {}) {
|
|
13272
|
+
const size = o.size ?? 640;
|
|
13273
|
+
return {
|
|
13274
|
+
async segmentAll(image, opts = {}) {
|
|
13275
|
+
const px = o.toPixels ? o.toPixels(image) : image;
|
|
13276
|
+
const { data, lb } = letterboxTensor(px, size);
|
|
13277
|
+
const res = await m.session.run({ [m.session.inputNames[0]]: new m.ort.Tensor("float32", data, [
|
|
13278
|
+
1,
|
|
13279
|
+
3,
|
|
13280
|
+
size,
|
|
13281
|
+
size
|
|
13282
|
+
]) });
|
|
13283
|
+
const outs = m.session.outputNames.map((nm) => res[nm]);
|
|
13284
|
+
const proto = outs.find((t) => t.dims.length === 4);
|
|
13285
|
+
const det = outs.find((t) => t.dims.length === 3);
|
|
13286
|
+
if (!proto || !det) throw new Error(`fastsam: expected a 3D box output and a 4D prototype output, got ${outs.map((t) => `[${t.dims.join(", ")}]`).join(" and ")}`);
|
|
13287
|
+
return decodeFastSam(det.data, det.dims, proto.data, proto.dims, lb, px, opts);
|
|
13288
|
+
},
|
|
13289
|
+
dispose: () => m.dispose()
|
|
13290
|
+
};
|
|
13291
|
+
}
|
|
13292
|
+
/** The smallest instance whose mask holds the pixel at x, y, for hover and click picks; undefined off every mask. */
|
|
13293
|
+
function instanceAt(instances, x, y) {
|
|
13294
|
+
let best;
|
|
13295
|
+
for (const inst of instances) {
|
|
13296
|
+
const m = inst.mask;
|
|
13297
|
+
const xi = Math.floor(x);
|
|
13298
|
+
const yi = Math.floor(y);
|
|
13299
|
+
if (xi < 0 || yi < 0 || xi >= m.width || yi >= m.height || m.data[yi * m.width + xi] < 128) continue;
|
|
13300
|
+
if (!best || inst.area < best.area) best = inst;
|
|
13301
|
+
}
|
|
13302
|
+
return best;
|
|
13303
|
+
}
|
|
13304
|
+
var init_fastsam = __esmMin((() => {
|
|
13305
|
+
init_yolo();
|
|
12752
13306
|
}));
|
|
12753
13307
|
// packages/vision/src/api.ts
|
|
12754
13308
|
/** Add the vision records and register the transformers.js loaders. MediaPipe and ort factories are provided by the app. */
|
|
@@ -12791,6 +13345,51 @@ var HackbuildAiViews = (function(exports) {
|
|
|
12791
13345
|
if (o.timestamp !== void 0) opts.timestamp = o.timestamp;
|
|
12792
13346
|
return withModel(hub, target("detect", o), (v) => asDetector(v, o.toPixels).detect(image, opts), o);
|
|
12793
13347
|
}
|
|
13348
|
+
/** Add a picker record to the hub's registry when it is missing, so a call that names it by id can load it. */
|
|
13349
|
+
function ensureRecord(hub, id) {
|
|
13350
|
+
const have = hub.registry.get(id);
|
|
13351
|
+
if (have) return have;
|
|
13352
|
+
const rec = PICKER_RECORDS.find((r) => r.id === id);
|
|
13353
|
+
if (!rec) throw new Error(`${id} is neither registered nor a picker record`);
|
|
13354
|
+
hub.registry.add(rec);
|
|
13355
|
+
return rec;
|
|
13356
|
+
}
|
|
13357
|
+
/**
|
|
13358
|
+
* Objects at a chosen detector size: YOLOv10 nano, small or medium
|
|
13359
|
+
* ({@link DETECT_SIZES}). Picking a size is the opt in to the AGPL-3.0
|
|
13360
|
+
* Ultralytics weights: the record is added to the registry on first use.
|
|
13361
|
+
* Boxes pass a per class NMS.
|
|
13362
|
+
*/
|
|
13363
|
+
function detectAt(hub, image, size, o = {}) {
|
|
13364
|
+
const id = Object.hasOwn(DETECT_SIZES, size) ? DETECT_SIZES[size] : void 0;
|
|
13365
|
+
if (!id) return Promise.reject(/* @__PURE__ */ new RangeError(`detector size ${String(size)}: pick n, s or m`));
|
|
13366
|
+
ensureRecord(hub, id);
|
|
13367
|
+
return detect(hub, image, {
|
|
13368
|
+
...o,
|
|
13369
|
+
model: id
|
|
13370
|
+
});
|
|
13371
|
+
}
|
|
13372
|
+
function asEverything(v, toPixels) {
|
|
13373
|
+
if (v && typeof v === "object" && "sessions" in v) return fastSamSegmenter(v, toPixels ? { toPixels } : {});
|
|
13374
|
+
return v;
|
|
13375
|
+
}
|
|
13376
|
+
/**
|
|
13377
|
+
* Every object in one pass (FastSAM-S by default): instances with a box,
|
|
13378
|
+
* score, area and mask, best first, after a class agnostic NMS. The
|
|
13379
|
+
* FastSAM record (AGPL-3.0 upstream) is added on first use unless `model`
|
|
13380
|
+
* names another record that provides "segment.everything".
|
|
13381
|
+
*/
|
|
13382
|
+
function segmentEverything(hub, image, o = {}) {
|
|
13383
|
+
const { model, size, maxMB, signal, schedule, toPixels, ...eo } = o;
|
|
13384
|
+
const id = model ?? "fastsam-s";
|
|
13385
|
+
ensureRecord(hub, id);
|
|
13386
|
+
const co = { model: id };
|
|
13387
|
+
if (size) co.size = size;
|
|
13388
|
+
if (maxMB !== void 0) co.maxMB = maxMB;
|
|
13389
|
+
if (signal) co.signal = signal;
|
|
13390
|
+
if (schedule) co.schedule = schedule;
|
|
13391
|
+
return withModel(hub, { id }, (v) => asEverything(v, toPixels).segmentAll(image, eo), co);
|
|
13392
|
+
}
|
|
12794
13393
|
/**
|
|
12795
13394
|
* Point, negative point and box prompted masks (SlimSAM), or a person mask
|
|
12796
13395
|
* without a prompt (selfie segmenter). Best first. The image is encoded
|
|
@@ -12848,6 +13447,7 @@ var HackbuildAiViews = (function(exports) {
|
|
|
12848
13447
|
var target;
|
|
12849
13448
|
var init_api = __esmMin((() => {
|
|
12850
13449
|
init_loaders();
|
|
13450
|
+
init_fastsam();
|
|
12851
13451
|
init_records();
|
|
12852
13452
|
init_segment();
|
|
12853
13453
|
init_yolo();
|
|
@@ -13762,6 +14362,38 @@ self.onmessage = async (ev) => {
|
|
|
13762
14362
|
data
|
|
13763
14363
|
};
|
|
13764
14364
|
}
|
|
14365
|
+
/** A selection as 1 in a byte a pixel (the hackbuild-ui mask tools' shape) to a {@link Mask}, 255 inside. */
|
|
14366
|
+
function selectionToMask(sel, width, height) {
|
|
14367
|
+
if (sel.length !== width * height) throw new RangeError(`selectionToMask: ${sel.length} values for a ${width} x ${height} mask`);
|
|
14368
|
+
return {
|
|
14369
|
+
width,
|
|
14370
|
+
height,
|
|
14371
|
+
data: Uint8Array.from(sel, (v) => v ? 255 : 0)
|
|
14372
|
+
};
|
|
14373
|
+
}
|
|
14374
|
+
/** A {@link Mask} to 1 in a byte a pixel (128 and up is inside), the shape the hackbuild-ui mask tools edit. */
|
|
14375
|
+
function maskToSelection(m) {
|
|
14376
|
+
return Uint8Array.from(m.data, (v) => v >= ON ? 1 : 0);
|
|
14377
|
+
}
|
|
14378
|
+
/** The tight box of the inside pixels in whole pixels, or null for an empty mask. */
|
|
14379
|
+
function maskBox(m) {
|
|
14380
|
+
let x0 = m.width;
|
|
14381
|
+
let y0 = m.height;
|
|
14382
|
+
let x1 = -1;
|
|
14383
|
+
let y1 = -1;
|
|
14384
|
+
for (let y = 0; y < m.height; y++) for (let x = 0; x < m.width; x++) if (m.data[y * m.width + x] >= ON) {
|
|
14385
|
+
if (x < x0) x0 = x;
|
|
14386
|
+
if (x > x1) x1 = x;
|
|
14387
|
+
if (y < y0) y0 = y;
|
|
14388
|
+
if (y > y1) y1 = y;
|
|
14389
|
+
}
|
|
14390
|
+
return x1 < 0 ? null : {
|
|
14391
|
+
x: x0,
|
|
14392
|
+
y: y0,
|
|
14393
|
+
w: x1 - x0 + 1,
|
|
14394
|
+
h: y1 - y0 + 1
|
|
14395
|
+
};
|
|
14396
|
+
}
|
|
13765
14397
|
var ON, make, INF, CRC;
|
|
13766
14398
|
var init_masks = __esmMin((() => {
|
|
13767
14399
|
ON = 128;
|
|
@@ -13781,6 +14413,257 @@ self.onmessage = async (ev) => {
|
|
|
13781
14413
|
return t;
|
|
13782
14414
|
})();
|
|
13783
14415
|
}));
|
|
14416
|
+
// packages/vision/src/auto.ts
|
|
14417
|
+
/** Rec. 601 luma per pixel, 0 to 255. */
|
|
14418
|
+
function luma(px) {
|
|
14419
|
+
const n = px.width * px.height;
|
|
14420
|
+
const out = new Float32Array(n);
|
|
14421
|
+
for (let i = 0; i < n; i++) out[i] = .299 * px.data[i * 4] + .587 * px.data[i * 4 + 1] + .114 * px.data[i * 4 + 2];
|
|
14422
|
+
return out;
|
|
14423
|
+
}
|
|
14424
|
+
/** Edge pixels: the 3 by 3 Sobel gradient magnitude of luma above `threshold` (default 50). The one pixel border stays out. */
|
|
14425
|
+
function edgeMask(px, threshold = 50) {
|
|
14426
|
+
const { width: w, height: h } = px;
|
|
14427
|
+
const g = luma(px);
|
|
14428
|
+
const data = new Uint8Array(w * h);
|
|
14429
|
+
for (let y = 1; y < h - 1; y++) for (let x = 1; x < w - 1; x++) {
|
|
14430
|
+
const i = y * w + x;
|
|
14431
|
+
const a = g[i - w - 1], b = g[i - w], c = g[i - w + 1], d = g[i - 1], f = g[i + 1], p = g[i + w - 1], q = g[i + w], r = g[i + w + 1];
|
|
14432
|
+
const gx = c + 2 * f + r - a - 2 * d - p;
|
|
14433
|
+
const gy = p + 2 * q + r - a - 2 * b - c;
|
|
14434
|
+
if (Math.sqrt(gx * gx + gy * gy) > threshold) data[i] = 255;
|
|
14435
|
+
}
|
|
14436
|
+
return {
|
|
14437
|
+
width: w,
|
|
14438
|
+
height: h,
|
|
14439
|
+
data
|
|
14440
|
+
};
|
|
14441
|
+
}
|
|
14442
|
+
/** Pixels brighter than `threshold` (0 to 255, default 128); `invert` keeps the darker ones. */
|
|
14443
|
+
function thresholdMask(px, threshold = 128, invert = false) {
|
|
14444
|
+
const g = luma(px);
|
|
14445
|
+
return {
|
|
14446
|
+
width: px.width,
|
|
14447
|
+
height: px.height,
|
|
14448
|
+
data: Uint8Array.from(g, (v) => v > threshold !== invert ? 255 : 0)
|
|
14449
|
+
};
|
|
14450
|
+
}
|
|
14451
|
+
/** Otsu's threshold over the luma histogram: the cut that maximizes the between class variance, 0 to 255. */
|
|
14452
|
+
function otsuThreshold(px) {
|
|
14453
|
+
const hist = /* @__PURE__ */ new Float64Array(256);
|
|
14454
|
+
for (const v of luma(px)) hist[Math.round(v)]++;
|
|
14455
|
+
const total = px.width * px.height;
|
|
14456
|
+
let sum = 0;
|
|
14457
|
+
for (let i = 0; i < 256; i++) sum += i * hist[i];
|
|
14458
|
+
let sumB = 0;
|
|
14459
|
+
let wB = 0;
|
|
14460
|
+
let best = 0;
|
|
14461
|
+
let th = 0;
|
|
14462
|
+
for (let t = 0; t < 256; t++) {
|
|
14463
|
+
wB += hist[t];
|
|
14464
|
+
if (!wB) continue;
|
|
14465
|
+
const wF = total - wB;
|
|
14466
|
+
if (!wF) break;
|
|
14467
|
+
sumB += t * hist[t];
|
|
14468
|
+
const d = sumB / wB - (sum - sumB) / wF;
|
|
14469
|
+
const v = wB * wF * d * d;
|
|
14470
|
+
if (v > best) {
|
|
14471
|
+
best = v;
|
|
14472
|
+
th = t;
|
|
14473
|
+
}
|
|
14474
|
+
}
|
|
14475
|
+
return th;
|
|
14476
|
+
}
|
|
14477
|
+
/** The threshold mask at Otsu's cut, with the cut it chose. */
|
|
14478
|
+
function autoThresholdMask(px, invert = false) {
|
|
14479
|
+
const threshold = otsuThreshold(px);
|
|
14480
|
+
return {
|
|
14481
|
+
mask: thresholdMask(px, threshold, invert),
|
|
14482
|
+
threshold
|
|
14483
|
+
};
|
|
14484
|
+
}
|
|
14485
|
+
/** K-means on RGB: `k` clusters (2 to 16, default 4), `iterations` passes (default 8), centres seeded from pixels picked by `rng`. */
|
|
14486
|
+
function colourClusters(px, o = {}) {
|
|
14487
|
+
const k = Math.max(2, Math.min(16, Math.round(o.k ?? 4)));
|
|
14488
|
+
const rng = o.rng ?? seeded$1(1);
|
|
14489
|
+
const n = px.width * px.height;
|
|
14490
|
+
const d = px.data;
|
|
14491
|
+
const centres = [];
|
|
14492
|
+
for (let c = 0; c < k; c++) {
|
|
14493
|
+
const i = Math.min(n - 1, Math.floor(rng() * n)) * 4;
|
|
14494
|
+
centres.push([
|
|
14495
|
+
d[i],
|
|
14496
|
+
d[i + 1],
|
|
14497
|
+
d[i + 2]
|
|
14498
|
+
]);
|
|
14499
|
+
}
|
|
14500
|
+
const labels = new Uint8Array(n);
|
|
14501
|
+
const assign = () => {
|
|
14502
|
+
for (let i = 0; i < n; i++) {
|
|
14503
|
+
let best = Infinity;
|
|
14504
|
+
let l = 0;
|
|
14505
|
+
for (let c = 0; c < k; c++) {
|
|
14506
|
+
const e = centres[c];
|
|
14507
|
+
const dd = (d[i * 4] - e[0]) ** 2 + (d[i * 4 + 1] - e[1]) ** 2 + (d[i * 4 + 2] - e[2]) ** 2;
|
|
14508
|
+
if (dd < best) {
|
|
14509
|
+
best = dd;
|
|
14510
|
+
l = c;
|
|
14511
|
+
}
|
|
14512
|
+
}
|
|
14513
|
+
labels[i] = l;
|
|
14514
|
+
}
|
|
14515
|
+
};
|
|
14516
|
+
for (let it = 0; it < (o.iterations ?? 8); it++) {
|
|
14517
|
+
assign();
|
|
14518
|
+
const s = Array.from({ length: k }, () => [
|
|
14519
|
+
0,
|
|
14520
|
+
0,
|
|
14521
|
+
0,
|
|
14522
|
+
0
|
|
14523
|
+
]);
|
|
14524
|
+
for (let i = 0; i < n; i++) {
|
|
14525
|
+
const t = s[labels[i]];
|
|
14526
|
+
t[0] += d[i * 4];
|
|
14527
|
+
t[1] += d[i * 4 + 1];
|
|
14528
|
+
t[2] += d[i * 4 + 2];
|
|
14529
|
+
t[3]++;
|
|
14530
|
+
}
|
|
14531
|
+
s.forEach((t, c) => {
|
|
14532
|
+
if (t[3]) centres[c] = [
|
|
14533
|
+
t[0] / t[3],
|
|
14534
|
+
t[1] / t[3],
|
|
14535
|
+
t[2] / t[3]
|
|
14536
|
+
];
|
|
14537
|
+
});
|
|
14538
|
+
}
|
|
14539
|
+
assign();
|
|
14540
|
+
const counts = new Array(k).fill(0);
|
|
14541
|
+
for (const l of labels) counts[l]++;
|
|
14542
|
+
return {
|
|
14543
|
+
width: px.width,
|
|
14544
|
+
height: px.height,
|
|
14545
|
+
labels,
|
|
14546
|
+
centres,
|
|
14547
|
+
counts,
|
|
14548
|
+
background: counts.indexOf(Math.max(...counts))
|
|
14549
|
+
};
|
|
14550
|
+
}
|
|
14551
|
+
/** Everything but the largest colour cluster, as the mask studio's cluster button: `colourClusters` then a mask. */
|
|
14552
|
+
function clusterMask(px, o = {}) {
|
|
14553
|
+
const c = colourClusters(px, o);
|
|
14554
|
+
return {
|
|
14555
|
+
width: c.width,
|
|
14556
|
+
height: c.height,
|
|
14557
|
+
data: Uint8Array.from(c.labels, (l) => l !== c.background ? 255 : 0)
|
|
14558
|
+
};
|
|
14559
|
+
}
|
|
14560
|
+
/** One mask per cluster, largest first. */
|
|
14561
|
+
function clusterMasks(c) {
|
|
14562
|
+
return c.counts.map((count, i) => ({
|
|
14563
|
+
count,
|
|
14564
|
+
i
|
|
14565
|
+
})).filter((e) => e.count > 0).sort((a, b) => b.count - a.count).map(({ i }) => ({
|
|
14566
|
+
width: c.width,
|
|
14567
|
+
height: c.height,
|
|
14568
|
+
data: Uint8Array.from(c.labels, (l) => l === i ? 255 : 0)
|
|
14569
|
+
}));
|
|
14570
|
+
}
|
|
14571
|
+
function seeded$1(seed) {
|
|
14572
|
+
let a = seed >>> 0;
|
|
14573
|
+
return () => {
|
|
14574
|
+
a = a + 1831565813 >>> 0;
|
|
14575
|
+
let t = a;
|
|
14576
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
14577
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
14578
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
14579
|
+
};
|
|
14580
|
+
}
|
|
14581
|
+
var init_auto = __esmMin((() => {}));
|
|
14582
|
+
// packages/vision/src/instances.ts
|
|
14583
|
+
function cropPixels(px, b) {
|
|
14584
|
+
const data = new Uint8ClampedArray(b.w * b.h * 4);
|
|
14585
|
+
for (let y = 0; y < b.h; y++) data.set(px.data.subarray(((b.y + y) * px.width + b.x) * 4, ((b.y + y) * px.width + b.x + b.w) * 4), y * b.w * 4);
|
|
14586
|
+
return {
|
|
14587
|
+
width: b.w,
|
|
14588
|
+
height: b.h,
|
|
14589
|
+
data
|
|
14590
|
+
};
|
|
14591
|
+
}
|
|
14592
|
+
function cropMask(m, b) {
|
|
14593
|
+
const data = new Uint8Array(b.w * b.h);
|
|
14594
|
+
for (let y = 0; y < b.h; y++) data.set(m.data.subarray((b.y + y) * m.width + b.x, (b.y + y) * m.width + b.x + b.w), y * b.w);
|
|
14595
|
+
return {
|
|
14596
|
+
width: b.w,
|
|
14597
|
+
height: b.h,
|
|
14598
|
+
data
|
|
14599
|
+
};
|
|
14600
|
+
}
|
|
14601
|
+
/** The files for a set of instances: `<prefix>_<n>_cutout.png` and `<prefix>_<n>_mask.png` per non empty instance, then `instances.json`. */
|
|
14602
|
+
async function exportInstances(image, instances, o = {}) {
|
|
14603
|
+
const prefix = o.prefix ?? "instance";
|
|
14604
|
+
const crop = o.crop ?? true;
|
|
14605
|
+
const files = [];
|
|
14606
|
+
const rows = [];
|
|
14607
|
+
const po = o.compress === void 0 ? {} : { compress: o.compress };
|
|
14608
|
+
for (let i = 0; i < instances.length; i++) {
|
|
14609
|
+
const inst = instances[i];
|
|
14610
|
+
if (inst.mask.width !== image.width || inst.mask.height !== image.height) throw new RangeError(`exportInstances: instance ${i + 1} mask is ${inst.mask.width} x ${inst.mask.height}, image ${image.width} x ${image.height}`);
|
|
14611
|
+
const full = {
|
|
14612
|
+
x: 0,
|
|
14613
|
+
y: 0,
|
|
14614
|
+
w: image.width,
|
|
14615
|
+
h: image.height
|
|
14616
|
+
};
|
|
14617
|
+
const b = crop ? maskBox(inst.mask) : full;
|
|
14618
|
+
if (!b) continue;
|
|
14619
|
+
const n = i + 1;
|
|
14620
|
+
const cut = `${prefix}_${n}_cutout.png`;
|
|
14621
|
+
const mk = `${prefix}_${n}_mask.png`;
|
|
14622
|
+
const m = crop ? cropMask(inst.mask, b) : inst.mask;
|
|
14623
|
+
files.push({
|
|
14624
|
+
name: cut,
|
|
14625
|
+
data: await cutoutPng(crop ? cropPixels(image, b) : image, m, po),
|
|
14626
|
+
type: "image/png"
|
|
14627
|
+
});
|
|
14628
|
+
files.push({
|
|
14629
|
+
name: mk,
|
|
14630
|
+
data: await maskToPng(m, po),
|
|
14631
|
+
type: "image/png"
|
|
14632
|
+
});
|
|
14633
|
+
const row = {
|
|
14634
|
+
index: n,
|
|
14635
|
+
score: r2(inst.score),
|
|
14636
|
+
area: inst.area,
|
|
14637
|
+
box: {
|
|
14638
|
+
x: r2(inst.box.x),
|
|
14639
|
+
y: r2(inst.box.y),
|
|
14640
|
+
w: r2(inst.box.w),
|
|
14641
|
+
h: r2(inst.box.h)
|
|
14642
|
+
},
|
|
14643
|
+
crop: b,
|
|
14644
|
+
cutout: cut,
|
|
14645
|
+
mask: mk
|
|
14646
|
+
};
|
|
14647
|
+
if (inst.label !== void 0) row.label = inst.label;
|
|
14648
|
+
rows.push(row);
|
|
14649
|
+
}
|
|
14650
|
+
const json = JSON.stringify({
|
|
14651
|
+
width: image.width,
|
|
14652
|
+
height: image.height,
|
|
14653
|
+
instances: rows
|
|
14654
|
+
}, null, 2);
|
|
14655
|
+
files.push({
|
|
14656
|
+
name: `${prefix}s.json`,
|
|
14657
|
+
data: new TextEncoder().encode(json),
|
|
14658
|
+
type: "application/json"
|
|
14659
|
+
});
|
|
14660
|
+
return files;
|
|
14661
|
+
}
|
|
14662
|
+
var r2;
|
|
14663
|
+
var init_instances = __esmMin((() => {
|
|
14664
|
+
init_masks();
|
|
14665
|
+
r2 = (v) => Math.round(v * 100) / 100;
|
|
14666
|
+
}));
|
|
13784
14667
|
// packages/vision/src/signals.ts
|
|
13785
14668
|
/** One raw face from a face landmark result, or null. Expressions read 0 without blendshapes. */
|
|
13786
14669
|
function rawFace(lm, index = 0) {
|
|
@@ -14140,6 +15023,7 @@ self.onmessage = async (ev) => {
|
|
|
14140
15023
|
COCO_LABELS: () => COCO_LABELS,
|
|
14141
15024
|
DEFAULT_REACTIONS: () => DEFAULT_REACTIONS,
|
|
14142
15025
|
DEPTH_WORKER_SOURCE: () => DEPTH_WORKER_SOURCE,
|
|
15026
|
+
DETECT_SIZES: () => DETECT_SIZES,
|
|
14143
15027
|
EmbeddingCache: () => EmbeddingCache,
|
|
14144
15028
|
LOOK_PATTERN: () => LOOK_PATTERN,
|
|
14145
15029
|
MP_MODELS: () => MP_MODELS,
|
|
@@ -14151,11 +15035,17 @@ self.onmessage = async (ev) => {
|
|
|
14151
15035
|
VISION_RECORDS: () => VISION_RECORDS,
|
|
14152
15036
|
ask: () => ask,
|
|
14153
15037
|
attachVision: () => attachVision,
|
|
15038
|
+
autoThresholdMask: () => autoThresholdMask,
|
|
14154
15039
|
caption: () => caption,
|
|
14155
15040
|
centreDetector: () => centreDetector,
|
|
15041
|
+
clusterMask: () => clusterMask,
|
|
15042
|
+
clusterMasks: () => clusterMasks,
|
|
15043
|
+
colourClusters: () => colourClusters,
|
|
14156
15044
|
cutoutPng: () => cutoutPng,
|
|
14157
15045
|
cutoutRgba: () => cutoutRgba,
|
|
15046
|
+
decodeFastSam: () => decodeFastSam,
|
|
14158
15047
|
decodeYolo: () => decodeYolo,
|
|
15048
|
+
decodeYoloEnd2End: () => decodeYoloEnd2End,
|
|
14159
15049
|
depth: () => depth,
|
|
14160
15050
|
depthFromOutput: () => depthFromOutput,
|
|
14161
15051
|
depthLoader: () => depthLoader,
|
|
@@ -14163,24 +15053,33 @@ self.onmessage = async (ev) => {
|
|
|
14163
15053
|
depthWorker: () => depthWorker,
|
|
14164
15054
|
describePerception: () => describePerception,
|
|
14165
15055
|
detect: () => detect,
|
|
15056
|
+
detectAt: () => detectAt,
|
|
14166
15057
|
detectCadenceMs: () => detectCadenceMs,
|
|
14167
15058
|
discSegmenter: () => discSegmenter,
|
|
15059
|
+
edgeMask: () => edgeMask,
|
|
14168
15060
|
emptyMask: () => emptyMask,
|
|
14169
15061
|
encodePng: () => encodePng,
|
|
15062
|
+
ensureRecord: () => ensureRecord,
|
|
15063
|
+
exportInstances: () => exportInstances,
|
|
14170
15064
|
faceApiProvider: () => faceApiProvider,
|
|
14171
15065
|
faceApiRecord: () => faceApiRecord,
|
|
15066
|
+
fastSamSegmenter: () => fastSamSegmenter,
|
|
14172
15067
|
fitSize: () => fitSize,
|
|
14173
15068
|
fixedLandmarker: () => fixedLandmarker,
|
|
14174
15069
|
fixedVlm: () => fixedVlm,
|
|
14175
15070
|
gazeTarget: () => gazeTarget,
|
|
14176
15071
|
hasPrompt: () => hasPrompt,
|
|
15072
|
+
instanceAt: () => instanceAt,
|
|
14177
15073
|
iou: () => iou,
|
|
15074
|
+
isEnd2End: () => isEnd2End,
|
|
14178
15075
|
landmarkChain: () => landmarkChain,
|
|
14179
15076
|
landmarks: () => landmarks,
|
|
14180
15077
|
letterboxParams: () => letterboxParams,
|
|
14181
15078
|
letterboxTensor: () => letterboxTensor,
|
|
14182
15079
|
loadTasksVision: () => loadTasksVision,
|
|
15080
|
+
luma: () => luma,
|
|
14183
15081
|
maskArea: () => maskArea,
|
|
15082
|
+
maskBox: () => maskBox,
|
|
14184
15083
|
maskDilate: () => maskDilate,
|
|
14185
15084
|
maskErode: () => maskErode,
|
|
14186
15085
|
maskFeather: () => maskFeather,
|
|
@@ -14194,11 +15093,13 @@ self.onmessage = async (ev) => {
|
|
|
14194
15093
|
maskToPng: () => maskToPng,
|
|
14195
15094
|
maskToRgba: () => maskToRgba,
|
|
14196
15095
|
maskToRle: () => maskToRle,
|
|
15096
|
+
maskToSelection: () => maskToSelection,
|
|
14197
15097
|
maskToSvg: () => maskToSvg,
|
|
14198
15098
|
maskUnion: () => maskUnion,
|
|
14199
15099
|
mediapipeLadder: () => mediapipeLadder,
|
|
14200
15100
|
mediapipeProvider: () => mediapipeProvider,
|
|
14201
15101
|
nms: () => nms,
|
|
15102
|
+
otsuThreshold: () => otsuThreshold,
|
|
14202
15103
|
perceptionLoop: () => perceptionLoop,
|
|
14203
15104
|
promptSegmenter: () => promptSegmenter,
|
|
14204
15105
|
rampDepth: () => rampDepth,
|
|
@@ -14209,8 +15110,11 @@ self.onmessage = async (ev) => {
|
|
|
14209
15110
|
readbackLoop: () => readbackLoop,
|
|
14210
15111
|
samLoader: () => samLoader,
|
|
14211
15112
|
segment: () => segment,
|
|
15113
|
+
segmentEverything: () => segmentEverything,
|
|
15114
|
+
selectionToMask: () => selectionToMask,
|
|
14212
15115
|
tasksVisionUrls: () => tasksVisionUrls,
|
|
14213
15116
|
tasksVisionWasm: () => tasksVisionWasm,
|
|
15117
|
+
thresholdMask: () => thresholdMask,
|
|
14214
15118
|
visionStubs: () => visionStubs,
|
|
14215
15119
|
vlmLoader: () => vlmLoader,
|
|
14216
15120
|
wantsLook: () => wantsLook,
|
|
@@ -14229,6 +15133,9 @@ self.onmessage = async (ev) => {
|
|
|
14229
15133
|
init_stubs();
|
|
14230
15134
|
init_segment();
|
|
14231
15135
|
init_masks();
|
|
15136
|
+
init_fastsam();
|
|
15137
|
+
init_auto();
|
|
15138
|
+
init_instances();
|
|
14232
15139
|
init_signals();
|
|
14233
15140
|
}));
|
|
14234
15141
|
// packages/ai-views/src/jobs.ts
|
|
@@ -14351,22 +15258,22 @@ self.onmessage = async (ev) => {
|
|
|
14351
15258
|
"[tabindex]",
|
|
14352
15259
|
"[contenteditable=\"true\"]"
|
|
14353
15260
|
].join(",");
|
|
14354
|
-
function
|
|
15261
|
+
function _o(e) {
|
|
14355
15262
|
if (!e) return "";
|
|
14356
15263
|
const t = [];
|
|
14357
15264
|
return e.tokPerSec !== null && e.tokPerSec !== void 0 && t.push(`${e.tokPerSec.toFixed(1)} tok/s`), e.firstMs !== null && e.firstMs !== void 0 && t.push(`first word ${(e.firstMs / 1e3).toFixed(2)} s`), e.tokens !== null && e.tokens !== void 0 && t.push(`${e.tokens} tok`), t.length ? `${t.join(", ")} (${e.source ?? "measured"})` : "";
|
|
14358
15265
|
}
|
|
14359
|
-
function
|
|
15266
|
+
function ie(e) {
|
|
14360
15267
|
if (!Number.isFinite(e)) return "--:--";
|
|
14361
15268
|
const t = Math.max(0, Math.floor(e)), r = Math.floor(t / 3600), n = Math.floor(t % 3600 / 60), o = t % 60, i = (s) => String(s).padStart(2, "0");
|
|
14362
15269
|
return r ? `${r}:${i(n)}:${i(o)}` : `${i(n)}:${i(o)}`;
|
|
14363
15270
|
}
|
|
14364
|
-
function
|
|
15271
|
+
function Vn(e) {
|
|
14365
15272
|
return e >= 1e9 ? `${(e / 1e9).toFixed(1)} gb` : e >= 1e6 ? `${Math.round(e / 1e6)} mb` : `${Math.max(1, Math.round(e / 1e3))} kb`;
|
|
14366
15273
|
}
|
|
14367
|
-
function
|
|
15274
|
+
function xi(e) {
|
|
14368
15275
|
const t = [];
|
|
14369
|
-
return e.duration && t.push({ value:
|
|
15276
|
+
return e.duration && t.push({ value: ie(e.duration) }), e.size !== void 0 && t.push({ value: Vn(e.size) }), e.snrDb !== void 0 && t.push({
|
|
14370
15277
|
label: "snr",
|
|
14371
15278
|
value: `${e.snrDb.toFixed(1)} dB`,
|
|
14372
15279
|
tone: e.snrDb < 8 ? "lo" : e.snrDb > 20 ? "hi" : void 0
|
|
@@ -14378,22 +15285,22 @@ self.onmessage = async (ev) => {
|
|
|
14378
15285
|
value: `${Math.round(e.density * 100)}%`
|
|
14379
15286
|
}), e.rtf && t.push({ value: `${e.rtf.toFixed(1)}x rt` }), e.lines !== void 0 && t.push({ value: `${e.lines} ${e.lines === 1 ? "line" : "lines"}` }), t;
|
|
14380
15287
|
}
|
|
14381
|
-
|
|
14382
|
-
function
|
|
15288
|
+
Y("wand", "add"), Y("brush", "add"), Y("eraser", "add"), Y("lasso", "add"), Y("polygon", "add"), Y("rect", "add"), Y("ellipse", "add"), Y("flood", "add"), Y("pan", "add");
|
|
15289
|
+
function Y(e, t) {
|
|
14383
15290
|
const r = t === "add", n = `x swaps to ${r ? "erase" : "add"}`;
|
|
14384
15291
|
return e === "wand" ? `tap a colour to ${r ? "add" : "cut"} it. shift ${r ? "cuts" : "adds"}, ${n}` : e === "brush" ? `paint to ${r ? "add" : "erase"}. [ and ] size, ${n}` : e === "eraser" ? "paint to erase. shift adds, [ and ] size" : e === "polygon" ? `press corner by corner, enter or the first corner ${r ? "fills" : "cuts"}. backspace drops a corner, esc all` : e === "rect" || e === "ellipse" ? `drag a ${e === "rect" ? "box" : "ring"} to ${r ? "add" : "cut"} it. shift ${r ? "cuts" : "adds"}, ${n}` : e === "flood" ? `tap to fill the patch of one colour. shift ${r ? "cuts" : "adds"}, ${n}` : e === "pan" ? "drag to move the picture. space pans from any tool" : `drag around a shape, lift to ${r ? "fill" : "cut"}. esc drops it, ${n}`;
|
|
14385
15292
|
}
|
|
14386
|
-
function
|
|
15293
|
+
function Re(e) {
|
|
14387
15294
|
return !!e && !e.unfit && e.state !== "loaded" && e.state !== "loading";
|
|
14388
15295
|
}
|
|
14389
|
-
function
|
|
15296
|
+
function Dr(e) {
|
|
14390
15297
|
return !Number.isFinite(e) || e <= 0 ? "0 mb" : e >= 1e9 ? `${(e / 1e9).toFixed(1).replace(/\.0$/, "")} gb` : `${Math.max(1, Math.round(e / 1e6))} mb`;
|
|
14391
15298
|
}
|
|
14392
|
-
function
|
|
14393
|
-
const t = e.filter((n) =>
|
|
15299
|
+
function Zs(e) {
|
|
15300
|
+
const t = e.filter((n) => Re(n)), r = t.filter((n) => n.state !== "stored").reduce((n, o) => n + (o.bytes ?? 0), 0);
|
|
14394
15301
|
return {
|
|
14395
15302
|
ids: t.map((n) => n.id),
|
|
14396
|
-
label: r > 0 ? `load all, ${
|
|
15303
|
+
label: r > 0 ? `load all, ${Dr(r)}` : "load all"
|
|
14397
15304
|
};
|
|
14398
15305
|
}
|
|
14399
15306
|
// packages/ai-views/src/rows.ts
|
|
@@ -14440,7 +15347,7 @@ self.onmessage = async (ev) => {
|
|
|
14440
15347
|
/** Download words: "1.7 gb". Null for a record with no download or an unknown size. */
|
|
14441
15348
|
function sizeWords(r) {
|
|
14442
15349
|
if (isNoDownload(r) || r.sizeMB === null) return void 0;
|
|
14443
|
-
return
|
|
15350
|
+
return Dr(r.sizeMB * MIB);
|
|
14444
15351
|
}
|
|
14445
15352
|
/** The record's label, else its id made readable: "hermes 3 llama 3.2 3b". */
|
|
14446
15353
|
const pretty = (r) => r.label ?? r.id.replace(/-(mlc|gguf)$/, "").replace(/-/g, " ");
|
|
@@ -14459,11 +15366,11 @@ self.onmessage = async (ev) => {
|
|
|
14459
15366
|
});
|
|
14460
15367
|
if (r.sizeMB !== null && !isNoDownload(r)) out.push({
|
|
14461
15368
|
label: "size",
|
|
14462
|
-
value: `${
|
|
15369
|
+
value: `${Dr(r.sizeMB * MIB)}, ${r.sizeSource}`
|
|
14463
15370
|
});
|
|
14464
15371
|
if (r.vramMB != null) out.push({
|
|
14465
15372
|
label: "gpu memory",
|
|
14466
|
-
value: `${
|
|
15373
|
+
value: `${Dr(r.vramMB * MIB)}, ${r.vramSource ?? "unknown"}`
|
|
14467
15374
|
});
|
|
14468
15375
|
if (r.ctx) out.push({
|
|
14469
15376
|
label: "context",
|
|
@@ -14559,7 +15466,7 @@ self.onmessage = async (ev) => {
|
|
|
14559
15466
|
state
|
|
14560
15467
|
};
|
|
14561
15468
|
if (size) row.size = size;
|
|
14562
|
-
if (r.vramMB != null) row.memory = `needs ${
|
|
15469
|
+
if (r.vramMB != null) row.memory = `needs ${Dr(r.vramMB * MIB)}`;
|
|
14563
15470
|
if (r.sizeMB !== null && !isNoDownload(r)) row.bytes = r.sizeMB * MIB;
|
|
14564
15471
|
const speed = fit.fit === "fits on cpu, slow" ? "slow" : r.speed;
|
|
14565
15472
|
if (speed) row.speed = speed;
|
|
@@ -14578,6 +15485,73 @@ self.onmessage = async (ev) => {
|
|
|
14578
15485
|
// packages/ai-views/src/pick.ts
|
|
14579
15486
|
init_src$11();
|
|
14580
15487
|
/**
|
|
15488
|
+
* The ids of records whose files are already in a weight store: the cache
|
|
15489
|
+
* badge of a picker. A record counts when every file key it names is kept,
|
|
15490
|
+
* or, for one its runtime fetches by model id, when any kept url sits under
|
|
15491
|
+
* that id on the hub. Records cached elsewhere (WebLLM's own cache) are not seen.
|
|
15492
|
+
*/
|
|
15493
|
+
async function storedIds(store, records) {
|
|
15494
|
+
const keys = await store.keys().catch(() => []);
|
|
15495
|
+
if (!keys.length) return [];
|
|
15496
|
+
const set = new Set(keys);
|
|
15497
|
+
return records.filter((r) => {
|
|
15498
|
+
const ks = weightKeys(r);
|
|
15499
|
+
if (ks.length) return ks.every((k) => set.has(k));
|
|
15500
|
+
const id = r.source.modelId;
|
|
15501
|
+
return !!id && keys.some((k) => k.includes(`/${id}/resolve/`));
|
|
15502
|
+
}).map((r) => r.id);
|
|
15503
|
+
}
|
|
15504
|
+
/**
|
|
15505
|
+
* Checks a hub repo id before it is used as your own model: it exists, it is
|
|
15506
|
+
* public, and it carries onnx files transformers.js can run. One request to
|
|
15507
|
+
* the hub's model api; no weights are fetched.
|
|
15508
|
+
*/
|
|
15509
|
+
async function verifyRepo(repo, o = {}) {
|
|
15510
|
+
const id = repo.trim().replace(/^https?:\/\/huggingface\.co\//, "").replace(/\/+$/, "");
|
|
15511
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(id)) return {
|
|
15512
|
+
ok: false,
|
|
15513
|
+
onnx: 0,
|
|
15514
|
+
note: "write it as owner/name."
|
|
15515
|
+
};
|
|
15516
|
+
const f = o.fetch ?? globalThis.fetch.bind(globalThis);
|
|
15517
|
+
let res;
|
|
15518
|
+
try {
|
|
15519
|
+
res = await f(`${o.host ?? "https://huggingface.co"}/api/models/${id}`);
|
|
15520
|
+
} catch {
|
|
15521
|
+
return {
|
|
15522
|
+
ok: false,
|
|
15523
|
+
onnx: 0,
|
|
15524
|
+
note: "the hub did not answer. check the connection."
|
|
15525
|
+
};
|
|
15526
|
+
}
|
|
15527
|
+
if (res.status === 401 || res.status === 403) return {
|
|
15528
|
+
ok: false,
|
|
15529
|
+
onnx: 0,
|
|
15530
|
+
note: `${id} is gated or private. it cannot load here.`
|
|
15531
|
+
};
|
|
15532
|
+
if (!res.ok) return {
|
|
15533
|
+
ok: false,
|
|
15534
|
+
onnx: 0,
|
|
15535
|
+
note: `${id} was not found on the hub.`
|
|
15536
|
+
};
|
|
15537
|
+
const body = await res.json().catch(() => ({}));
|
|
15538
|
+
if (body.gated) return {
|
|
15539
|
+
ok: false,
|
|
15540
|
+
onnx: 0,
|
|
15541
|
+
note: `${id} is gated. accept its terms on the hub first.`
|
|
15542
|
+
};
|
|
15543
|
+
const onnx = (body.siblings ?? []).filter((x) => x.rfilename.endsWith(".onnx")).length;
|
|
15544
|
+
return onnx ? {
|
|
15545
|
+
ok: true,
|
|
15546
|
+
onnx,
|
|
15547
|
+
note: `${id} found, ${onnx} onnx files.`
|
|
15548
|
+
} : {
|
|
15549
|
+
ok: false,
|
|
15550
|
+
onnx: 0,
|
|
15551
|
+
note: `${id} has no onnx files. pick an onnx export.`
|
|
15552
|
+
};
|
|
15553
|
+
}
|
|
15554
|
+
/**
|
|
14581
15555
|
* A loader over a weight store: a record with a url fetches that file, a
|
|
14582
15556
|
* record with a repo and files fetches each, resuming and checking the
|
|
14583
15557
|
* SHA-256 when the record has one. Records a runtime fetches itself (WebLLM,
|
|
@@ -14766,7 +15740,7 @@ self.onmessage = async (ev) => {
|
|
|
14766
15740
|
estimate,
|
|
14767
15741
|
state: state.get(id)
|
|
14768
15742
|
});
|
|
14769
|
-
if (!rec || !
|
|
15743
|
+
if (!rec || !Re(row)) return;
|
|
14770
15744
|
if (!loader) {
|
|
14771
15745
|
state.set(id, "error");
|
|
14772
15746
|
errors.set(id, "no loader. the page passes one to load a model.");
|
|
@@ -14835,6 +15809,7 @@ self.onmessage = async (ev) => {
|
|
|
14835
15809
|
if (n.records) records = jobRecords(job, n.records);
|
|
14836
15810
|
if (n.loader) loader = n.loader;
|
|
14837
15811
|
if (n.onRemove) onRemove = n.onRemove;
|
|
15812
|
+
for (const id of n.stored ?? []) if (!state.has(id) || state.get(id) === "none") state.set(id, "stored");
|
|
14838
15813
|
emit();
|
|
14839
15814
|
},
|
|
14840
15815
|
result: (id) => results.get(id),
|
|
@@ -14869,7 +15844,7 @@ self.onmessage = async (ev) => {
|
|
|
14869
15844
|
return {
|
|
14870
15845
|
id: pr.id,
|
|
14871
15846
|
label: pr.label,
|
|
14872
|
-
total: bytes > 0 ? `about ${
|
|
15847
|
+
total: bytes > 0 ? `about ${Dr(bytes)}` : "nothing to fetch"
|
|
14873
15848
|
};
|
|
14874
15849
|
}),
|
|
14875
15850
|
applyPreset(id) {
|
|
@@ -14877,7 +15852,7 @@ self.onmessage = async (ev) => {
|
|
|
14877
15852
|
if (!pr) return;
|
|
14878
15853
|
for (const [job, mid] of Object.entries(pr.picks)) picks.get(job)?.choose(mid);
|
|
14879
15854
|
},
|
|
14880
|
-
all: () =>
|
|
15855
|
+
all: () => Zs(chosenRows()),
|
|
14881
15856
|
async loadAll() {
|
|
14882
15857
|
await Promise.all([...picks.values()].map((p) => p.load().catch(() => void 0)));
|
|
14883
15858
|
},
|
|
@@ -14951,25 +15926,30 @@ self.onmessage = async (ev) => {
|
|
|
14951
15926
|
try {
|
|
14952
15927
|
if (o.recall && lastUser) mem = await o.recall(lastUser.text);
|
|
14953
15928
|
if (mem.length) patch(live.id, { mem });
|
|
14954
|
-
const
|
|
15929
|
+
const base = typeof o.system === "function" ? o.system() : o.system;
|
|
15930
|
+
const sys = o.systemFor ? o.systemFor(mem) : [base, mem.length ? `things you remember:\n${mem.map((m) => `- ${m.label}`).join("\n")}` : ""].filter(Boolean).join("\n\n");
|
|
15931
|
+
const past = turns.filter((t) => t.id !== live.id && t.text);
|
|
15932
|
+
const keep = o.history?.();
|
|
15933
|
+
const sent = keep !== void 0 && keep >= 0 ? past.slice(Math.max(0, past.length - 1 - keep)) : past;
|
|
14955
15934
|
const history = [...sys ? [{
|
|
14956
15935
|
role: "system",
|
|
14957
15936
|
content: sys
|
|
14958
|
-
}] : [], ...
|
|
15937
|
+
}] : [], ...sent.map((t) => ({
|
|
14959
15938
|
role: t.role,
|
|
14960
15939
|
content: t.text
|
|
14961
15940
|
}))];
|
|
14962
15941
|
let text = "";
|
|
14963
15942
|
let think = "";
|
|
14964
15943
|
const it = engine.stream(history, {
|
|
14965
|
-
|
|
14966
|
-
...o.
|
|
15944
|
+
...o.maxTokens ? { maxTokens: o.maxTokens } : {},
|
|
15945
|
+
...o.stream?.(),
|
|
15946
|
+
signal
|
|
14967
15947
|
});
|
|
14968
15948
|
for (;;) {
|
|
14969
15949
|
const step = await it.next();
|
|
14970
15950
|
if (step.done) {
|
|
14971
15951
|
const s = step.value?.stats;
|
|
14972
|
-
const stats = s ?
|
|
15952
|
+
const stats = s ? _o({
|
|
14973
15953
|
tokPerSec: s.tokensPerSecond,
|
|
14974
15954
|
firstMs: s.firstTokenMs,
|
|
14975
15955
|
tokens: s.tokens,
|
|
@@ -14979,6 +15959,8 @@ self.onmessage = async (ev) => {
|
|
|
14979
15959
|
done: true,
|
|
14980
15960
|
...stats ? { stats } : {}
|
|
14981
15961
|
});
|
|
15962
|
+
const fin = turns.find((t) => t.id === live.id);
|
|
15963
|
+
if (fin?.text) o.onReply?.(fin, lastUser?.text ?? "");
|
|
14982
15964
|
break;
|
|
14983
15965
|
}
|
|
14984
15966
|
const ev = step.value;
|
|
@@ -15044,6 +16026,15 @@ self.onmessage = async (ev) => {
|
|
|
15044
16026
|
engine = e;
|
|
15045
16027
|
emit();
|
|
15046
16028
|
},
|
|
16029
|
+
load(next) {
|
|
16030
|
+
ac?.abort();
|
|
16031
|
+
turns = next.map((t) => ({
|
|
16032
|
+
...t,
|
|
16033
|
+
id: ++seq,
|
|
16034
|
+
done: true
|
|
16035
|
+
}));
|
|
16036
|
+
emit();
|
|
16037
|
+
},
|
|
15047
16038
|
markdown(title = "chat") {
|
|
15048
16039
|
const lines = [`# ${title}`, ""];
|
|
15049
16040
|
for (const t of turns) lines.push(`## ${t.role === "user" ? "you" : "reply"}`, "", t.text, "");
|
|
@@ -15102,7 +16093,8 @@ self.onmessage = async (ev) => {
|
|
|
15102
16093
|
remove: (id) => chats.get(current).t.remove(id),
|
|
15103
16094
|
clear: () => chats.get(current).t.clear(),
|
|
15104
16095
|
setEngine: (e) => list.setEngine(e),
|
|
15105
|
-
markdown: (title) => chats.get(current).t.markdown(title ?? chats.get(current).title)
|
|
16096
|
+
markdown: (title) => chats.get(current).t.markdown(title ?? chats.get(current).title),
|
|
16097
|
+
load: (t) => chats.get(current).t.load(t)
|
|
15106
16098
|
},
|
|
15107
16099
|
snapshot: snap,
|
|
15108
16100
|
subscribe(fn) {
|
|
@@ -15150,6 +16142,50 @@ self.onmessage = async (ev) => {
|
|
|
15150
16142
|
setEngine(e) {
|
|
15151
16143
|
engine = e;
|
|
15152
16144
|
for (const c of chats.values()) c.t.setEngine(e);
|
|
16145
|
+
},
|
|
16146
|
+
dump() {
|
|
16147
|
+
return {
|
|
16148
|
+
format: "hackbuild-chats",
|
|
16149
|
+
version: 1,
|
|
16150
|
+
current,
|
|
16151
|
+
chats: [...chats].map(([id, c]) => ({
|
|
16152
|
+
id,
|
|
16153
|
+
title: c.title,
|
|
16154
|
+
updated: c.updated,
|
|
16155
|
+
named: c.named,
|
|
16156
|
+
turns: c.t.snapshot().turns.filter((t) => t.done).map((t) => ({ ...t }))
|
|
16157
|
+
}))
|
|
16158
|
+
};
|
|
16159
|
+
},
|
|
16160
|
+
restore(data, ro = {}) {
|
|
16161
|
+
if (data?.format !== "hackbuild-chats" || data.version !== 1 || !Array.isArray(data.chats)) throw new Error("not a hackbuild-chats version 1 file.");
|
|
16162
|
+
const empty = [...chats.values()].every((c) => !c.t.snapshot().turns.length);
|
|
16163
|
+
if (ro.replace || empty) {
|
|
16164
|
+
for (const c of chats.values()) c.t.stop();
|
|
16165
|
+
chats.clear();
|
|
16166
|
+
}
|
|
16167
|
+
let open = "";
|
|
16168
|
+
for (const c of data.chats) {
|
|
16169
|
+
const id = `chat-${++seq}`;
|
|
16170
|
+
const t = chatThread({
|
|
16171
|
+
...o,
|
|
16172
|
+
engine
|
|
16173
|
+
});
|
|
16174
|
+
t.load((c.turns ?? []).filter((x) => (x.role === "user" || x.role === "assistant") && typeof x.text === "string").map((x) => ({
|
|
16175
|
+
...x,
|
|
16176
|
+
think: x.think ?? ""
|
|
16177
|
+
})));
|
|
16178
|
+
chats.set(id, {
|
|
16179
|
+
t,
|
|
16180
|
+
title: String(c.title || "chat"),
|
|
16181
|
+
updated: +c.updated || now(),
|
|
16182
|
+
named: !!c.named
|
|
16183
|
+
});
|
|
16184
|
+
if (c.id === data.current) open = id;
|
|
16185
|
+
}
|
|
16186
|
+
if (!chats.size) return void list.create();
|
|
16187
|
+
current = open || (chats.has(current) ? current : snap().items[0].id);
|
|
16188
|
+
follow();
|
|
15153
16189
|
}
|
|
15154
16190
|
};
|
|
15155
16191
|
list.create();
|
|
@@ -15215,11 +16251,20 @@ self.onmessage = async (ev) => {
|
|
|
15215
16251
|
} : c);
|
|
15216
16252
|
emit();
|
|
15217
16253
|
};
|
|
15218
|
-
const metaOf = (c) =>
|
|
15219
|
-
|
|
15220
|
-
|
|
15221
|
-
|
|
15222
|
-
|
|
16254
|
+
const metaOf = (c) => {
|
|
16255
|
+
const s = c.stats;
|
|
16256
|
+
return xi({
|
|
16257
|
+
size: c.size,
|
|
16258
|
+
...c.duration ? { duration: c.duration } : {},
|
|
16259
|
+
...s ? {
|
|
16260
|
+
snrDb: s.snrDb,
|
|
16261
|
+
gainDb: s.gainDb,
|
|
16262
|
+
density: s.density,
|
|
16263
|
+
rtf: s.rtf
|
|
16264
|
+
} : {},
|
|
16265
|
+
...c.status === "done" ? { lines: c.segments.length } : {}
|
|
16266
|
+
});
|
|
16267
|
+
};
|
|
15223
16268
|
const q = {
|
|
15224
16269
|
snapshot: snap,
|
|
15225
16270
|
subscribe(fn) {
|
|
@@ -15264,7 +16309,8 @@ self.onmessage = async (ev) => {
|
|
|
15264
16309
|
try {
|
|
15265
16310
|
const r = await run(file, {
|
|
15266
16311
|
signal: ac.signal,
|
|
15267
|
-
onProgress: (f) => patch(next.id, { pct: Math.round(Math.min(1, Math.max(0, f)) * 100) })
|
|
16312
|
+
onProgress: (f) => patch(next.id, { pct: Math.round(Math.min(1, Math.max(0, f)) * 100) }),
|
|
16313
|
+
...o.options ? { options: o.options() } : {}
|
|
15268
16314
|
});
|
|
15269
16315
|
const c = channels.find((x) => x.id === next.id);
|
|
15270
16316
|
if (!c) continue;
|
|
@@ -15278,6 +16324,8 @@ self.onmessage = async (ev) => {
|
|
|
15278
16324
|
if (r.duration !== void 0) done.duration = r.duration;
|
|
15279
16325
|
if (r.language) done.language = r.language;
|
|
15280
16326
|
if (r.model) done.model = r.model;
|
|
16327
|
+
if (r.stats) done.stats = r.stats;
|
|
16328
|
+
if (r.rail) done.rail = r.rail;
|
|
15281
16329
|
done.meta = metaOf(done);
|
|
15282
16330
|
patch(next.id, done);
|
|
15283
16331
|
if (selected === null || channels.find((x) => x.id === selected)?.status !== "done") selected = next.id;
|
|
@@ -15380,6 +16428,30 @@ self.onmessage = async (ev) => {
|
|
|
15380
16428
|
type: TYPES[kind]
|
|
15381
16429
|
};
|
|
15382
16430
|
},
|
|
16431
|
+
zip(zo = {}) {
|
|
16432
|
+
const done = channels.filter((c) => c.segments.length);
|
|
16433
|
+
if (!done.length) return null;
|
|
16434
|
+
const docs = done.map((c) => ({
|
|
16435
|
+
source: c.name,
|
|
16436
|
+
segments: c.segments,
|
|
16437
|
+
dropped: c.dropped,
|
|
16438
|
+
model: c.model ?? "unknown",
|
|
16439
|
+
language: c.language ?? "unknown",
|
|
16440
|
+
...c.stats ? { stats: c.stats } : {},
|
|
16441
|
+
...c.duration !== void 0 ? { duration: c.duration } : {}
|
|
16442
|
+
}));
|
|
16443
|
+
const capture = o.options?.() ?? null;
|
|
16444
|
+
const out = bundle(docs, {
|
|
16445
|
+
...zo.tool ? { tool: zo.tool } : {},
|
|
16446
|
+
capture,
|
|
16447
|
+
...zo.date ? { date: zo.date } : {}
|
|
16448
|
+
});
|
|
16449
|
+
return {
|
|
16450
|
+
name: `transcripts-${(zo.date ?? /* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.zip`,
|
|
16451
|
+
data: out.zip,
|
|
16452
|
+
manifest: out.manifest
|
|
16453
|
+
};
|
|
16454
|
+
},
|
|
15383
16455
|
setTranscriber(t) {
|
|
15384
16456
|
run = t;
|
|
15385
16457
|
}
|
|
@@ -17465,16 +18537,35 @@ self.onmessage = async (ev) => {
|
|
|
17465
18537
|
c.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(p.data), p.width, p.height), 0, 0);
|
|
17466
18538
|
return c;
|
|
17467
18539
|
}
|
|
17468
|
-
/** A file as 16 kHz
|
|
18540
|
+
/** A file as 16 kHz samples per channel (at most two), decoded by the browser. */
|
|
17469
18541
|
async function pcm16k(file) {
|
|
17470
18542
|
const bytes = await file.arrayBuffer();
|
|
17471
18543
|
const buf = await new OfflineAudioContext(1, 1, 16e3).decodeAudioData(bytes);
|
|
17472
|
-
const
|
|
18544
|
+
const ch = Math.min(2, buf.numberOfChannels);
|
|
18545
|
+
const off = new OfflineAudioContext(ch, Math.max(1, Math.ceil(buf.duration * 16e3)), 16e3);
|
|
17473
18546
|
const src = off.createBufferSource();
|
|
17474
18547
|
src.buffer = buf;
|
|
17475
18548
|
src.connect(off.destination);
|
|
17476
18549
|
src.start();
|
|
17477
|
-
|
|
18550
|
+
const out = await off.startRendering();
|
|
18551
|
+
return Array.from({ length: ch }, (_, i) => out.getChannelData(i));
|
|
18552
|
+
}
|
|
18553
|
+
/** A level rail folded to at most `bins` bins: loudest frame and whether the gate kept most of it. */
|
|
18554
|
+
function railOf(rail, bins = 400) {
|
|
18555
|
+
const n = Math.max(1, Math.min(bins, rail.db.length));
|
|
18556
|
+
const db = new Array(n).fill(-90);
|
|
18557
|
+
const kept = new Array(n).fill(0);
|
|
18558
|
+
const count = new Array(n).fill(0);
|
|
18559
|
+
for (let i = 0; i < rail.db.length; i++) {
|
|
18560
|
+
const b = Math.min(n - 1, Math.floor(i * n / rail.db.length));
|
|
18561
|
+
db[b] = Math.max(db[b], rail.db[i]);
|
|
18562
|
+
kept[b] += rail.open[i];
|
|
18563
|
+
count[b]++;
|
|
18564
|
+
}
|
|
18565
|
+
return {
|
|
18566
|
+
db: db.map((x) => Math.round(x * 10) / 10),
|
|
18567
|
+
kept: kept.map((k, b) => count[b] && k / count[b] >= .5 ? 1 : 0)
|
|
18568
|
+
};
|
|
17478
18569
|
}
|
|
17479
18570
|
async function dspOf(rt) {
|
|
17480
18571
|
rt.dsp ??= rt.modules.dsp ? rt.modules.dsp() : Promise.all([Promise.resolve().then(() => (init_src$5(), src_exports$4)), Promise.resolve().then(() => (init_inline(), inline_exports))]).then(([a, i]) => a.loadDsp({ base64: i.AUDIO_DSP_WASM_BASE64 }));
|
|
@@ -17517,9 +18608,11 @@ self.onmessage = async (ev) => {
|
|
|
17517
18608
|
case "transcribe": {
|
|
17518
18609
|
const t = await Promise.resolve().then(() => (init_src$3(), src_exports$2));
|
|
17519
18610
|
const run = async (file, c) => {
|
|
17520
|
-
const [dsp,
|
|
17521
|
-
const
|
|
17522
|
-
const
|
|
18611
|
+
const [dsp, chans] = await Promise.all([dspOf(rt), pcm16k(file)]);
|
|
18612
|
+
const { channel, ...run } = c.options ?? {};
|
|
18613
|
+
const lang = run.language ?? ctx.options.language;
|
|
18614
|
+
const out = await t.transcribe(hub, dsp, t.toMono(chans, channel ?? "auto"), {
|
|
18615
|
+
...run,
|
|
17523
18616
|
model: rec.id,
|
|
17524
18617
|
signal: c.signal,
|
|
17525
18618
|
...lang ? { language: lang } : {},
|
|
@@ -17530,7 +18623,9 @@ self.onmessage = async (ev) => {
|
|
|
17530
18623
|
dropped: out.dropped,
|
|
17531
18624
|
duration: out.stats.dur,
|
|
17532
18625
|
language: out.language,
|
|
17533
|
-
model: rec.label ?? rec.id
|
|
18626
|
+
model: rec.label ?? rec.id,
|
|
18627
|
+
stats: out.stats,
|
|
18628
|
+
rail: railOf(out.rail)
|
|
17534
18629
|
};
|
|
17535
18630
|
};
|
|
17536
18631
|
return run;
|
|
@@ -17570,6 +18665,30 @@ self.onmessage = async (ev) => {
|
|
|
17570
18665
|
model: rec.id,
|
|
17571
18666
|
key: keyOf(image)
|
|
17572
18667
|
}))[0];
|
|
18668
|
+
if (rec.provides?.includes("segment.everything")) {
|
|
18669
|
+
let last = null;
|
|
18670
|
+
const all = async (image, o = {}) => {
|
|
18671
|
+
const key = JSON.stringify(o);
|
|
18672
|
+
if (last?.img !== image || last.key !== key) last = {
|
|
18673
|
+
img: image,
|
|
18674
|
+
key,
|
|
18675
|
+
list: await v.segmentEverything(hub, asImage(image), {
|
|
18676
|
+
...o,
|
|
18677
|
+
model: rec.id
|
|
18678
|
+
})
|
|
18679
|
+
};
|
|
18680
|
+
return last.list;
|
|
18681
|
+
};
|
|
18682
|
+
return {
|
|
18683
|
+
segment: async (image, p) => v.instanceAt(await all(image), p.x, p.y)?.mask.data ?? null,
|
|
18684
|
+
everything: async (image, o) => (await all(image, o)).map((i, k) => ({
|
|
18685
|
+
mask: i.mask.data,
|
|
18686
|
+
label: i.label ?? `object ${k + 1}`,
|
|
18687
|
+
score: i.score,
|
|
18688
|
+
box: i.box
|
|
18689
|
+
}))
|
|
18690
|
+
};
|
|
18691
|
+
}
|
|
17573
18692
|
return {
|
|
17574
18693
|
segment: async (image, p) => (await first(image, p.x, p.y))?.data ?? null,
|
|
17575
18694
|
everything: async (image) => {
|
|
@@ -17648,6 +18767,303 @@ self.onmessage = async (ev) => {
|
|
|
17648
18767
|
}
|
|
17649
18768
|
};
|
|
17650
18769
|
}
|
|
18770
|
+
// packages/ai-views/src/speaker.ts
|
|
18771
|
+
init_src$4();
|
|
18772
|
+
/** True when the engine clones a voice from reference audio. */
|
|
18773
|
+
const canClone = (e) => !!e && typeof e.cloneVoice === "function";
|
|
18774
|
+
/** Pocket takes its reference at this rate (vendor). */
|
|
18775
|
+
const RATE = 24e3;
|
|
18776
|
+
/** A speaker over the engine `engine()` returns at each line (null: text only, timed by `play`). */
|
|
18777
|
+
function speaker(engine, o = {}) {
|
|
18778
|
+
let ac = null;
|
|
18779
|
+
let chain = Promise.resolve();
|
|
18780
|
+
let ctl = new AbortController();
|
|
18781
|
+
let ref = null;
|
|
18782
|
+
const subs = /* @__PURE__ */ new Set();
|
|
18783
|
+
const emit = () => subs.forEach((f) => f());
|
|
18784
|
+
const audio = () => ac ??= new AudioContext();
|
|
18785
|
+
const config = () => ref ? { voice: "custom" } : o.config?.() ?? {};
|
|
18786
|
+
const speak = async (text, signal) => {
|
|
18787
|
+
if (signal.aborted) return;
|
|
18788
|
+
o.onLine?.(text);
|
|
18789
|
+
const e = engine();
|
|
18790
|
+
const play = o.play ?? (async () => void 0);
|
|
18791
|
+
if (!e) return void await play({ text });
|
|
18792
|
+
if (e.kind === "native") {
|
|
18793
|
+
e.speak(text, config(), { onBoundary: () => void 0 }, signal);
|
|
18794
|
+
await play({ text });
|
|
18795
|
+
return;
|
|
18796
|
+
}
|
|
18797
|
+
const r = await renderSpeech(e, text, {
|
|
18798
|
+
voice: config(),
|
|
18799
|
+
signal
|
|
18800
|
+
});
|
|
18801
|
+
if (signal.aborted) return;
|
|
18802
|
+
await play({
|
|
18803
|
+
text,
|
|
18804
|
+
audio: renderedBuffer(audio(), r),
|
|
18805
|
+
words: r.words,
|
|
18806
|
+
phonemes: r.phonemes
|
|
18807
|
+
});
|
|
18808
|
+
};
|
|
18809
|
+
const decode = async (blob) => {
|
|
18810
|
+
const buf = await audio().decodeAudioData(await blob.arrayBuffer());
|
|
18811
|
+
return {
|
|
18812
|
+
samples: toMono$1(Array.from({ length: buf.numberOfChannels }, (_, i) => buf.getChannelData(i))),
|
|
18813
|
+
rate: buf.sampleRate
|
|
18814
|
+
};
|
|
18815
|
+
};
|
|
18816
|
+
const clone = async (samples, rate) => {
|
|
18817
|
+
const e = engine();
|
|
18818
|
+
if (!canClone(e)) throw new Error("this voice cannot clone. load pocket in the voice list first.");
|
|
18819
|
+
const next = prepareClone(samples, rate);
|
|
18820
|
+
await e.cloneVoice(next, RATE);
|
|
18821
|
+
ref = next;
|
|
18822
|
+
emit();
|
|
18823
|
+
return ref.length / RATE;
|
|
18824
|
+
};
|
|
18825
|
+
return {
|
|
18826
|
+
get cloned() {
|
|
18827
|
+
return !!ref;
|
|
18828
|
+
},
|
|
18829
|
+
subscribe(fn) {
|
|
18830
|
+
subs.add(fn);
|
|
18831
|
+
return () => subs.delete(fn);
|
|
18832
|
+
},
|
|
18833
|
+
say(text) {
|
|
18834
|
+
const signal = ctl.signal;
|
|
18835
|
+
chain = chain.then(() => speak(text, signal)).catch(() => void 0);
|
|
18836
|
+
return chain;
|
|
18837
|
+
},
|
|
18838
|
+
stop() {
|
|
18839
|
+
ctl.abort();
|
|
18840
|
+
ctl = new AbortController();
|
|
18841
|
+
chain = Promise.resolve();
|
|
18842
|
+
o.halt?.();
|
|
18843
|
+
},
|
|
18844
|
+
async cloneFile(file) {
|
|
18845
|
+
const { samples, rate } = await decode(file);
|
|
18846
|
+
return clone(samples, rate);
|
|
18847
|
+
},
|
|
18848
|
+
async cloneMic(seconds, onTick) {
|
|
18849
|
+
const media = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
18850
|
+
try {
|
|
18851
|
+
const rec = new MediaRecorder(media);
|
|
18852
|
+
const parts = [];
|
|
18853
|
+
rec.ondataavailable = (ev) => parts.push(ev.data);
|
|
18854
|
+
const done = new Promise((ok) => rec.onstop = () => ok());
|
|
18855
|
+
rec.start();
|
|
18856
|
+
for (let left = seconds; left > 0; left--) {
|
|
18857
|
+
onTick?.(left);
|
|
18858
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
18859
|
+
}
|
|
18860
|
+
rec.stop();
|
|
18861
|
+
await done;
|
|
18862
|
+
const { samples, rate } = await decode(new Blob(parts, { type: rec.mimeType }));
|
|
18863
|
+
return await clone(samples, rate);
|
|
18864
|
+
} finally {
|
|
18865
|
+
media.getTracks().forEach((t) => t.stop());
|
|
18866
|
+
}
|
|
18867
|
+
},
|
|
18868
|
+
cloneWav() {
|
|
18869
|
+
if (!ref) return null;
|
|
18870
|
+
return renderedWav({
|
|
18871
|
+
samples: ref,
|
|
18872
|
+
sampleRate: RATE,
|
|
18873
|
+
duration: ref.length / RATE,
|
|
18874
|
+
engine: "clone",
|
|
18875
|
+
words: [],
|
|
18876
|
+
phonemes: []
|
|
18877
|
+
});
|
|
18878
|
+
},
|
|
18879
|
+
clearClone() {
|
|
18880
|
+
ref = null;
|
|
18881
|
+
emit();
|
|
18882
|
+
}
|
|
18883
|
+
};
|
|
18884
|
+
}
|
|
18885
|
+
// packages/ai-views/src/talk.ts
|
|
18886
|
+
init_src$8();
|
|
18887
|
+
const blank = () => ({
|
|
18888
|
+
name: "assistant",
|
|
18889
|
+
profile: "",
|
|
18890
|
+
notes: "",
|
|
18891
|
+
rules: ""
|
|
18892
|
+
});
|
|
18893
|
+
/** Creates a persona rack with built in presets and any saved ones; `onSave` keeps the saved ones. */
|
|
18894
|
+
function personaRack(o = {}) {
|
|
18895
|
+
const builtIn = [...o.presets ?? []];
|
|
18896
|
+
let saved = [...o.saved ?? []];
|
|
18897
|
+
let persona = {
|
|
18898
|
+
...blank(),
|
|
18899
|
+
...o.persona ?? builtIn[0]?.persona ?? {}
|
|
18900
|
+
};
|
|
18901
|
+
let on = o.persona ? -1 : builtIn.length ? 0 : -1;
|
|
18902
|
+
const subs = /* @__PURE__ */ new Set();
|
|
18903
|
+
const all = () => [...builtIn, ...saved];
|
|
18904
|
+
const snap = () => ({
|
|
18905
|
+
persona,
|
|
18906
|
+
presets: all(),
|
|
18907
|
+
on,
|
|
18908
|
+
builtIn: builtIn.length
|
|
18909
|
+
});
|
|
18910
|
+
const emit = () => subs.forEach((f) => f(snap()));
|
|
18911
|
+
return {
|
|
18912
|
+
snapshot: snap,
|
|
18913
|
+
subscribe(fn) {
|
|
18914
|
+
subs.add(fn);
|
|
18915
|
+
fn(snap());
|
|
18916
|
+
return () => subs.delete(fn);
|
|
18917
|
+
},
|
|
18918
|
+
set(p) {
|
|
18919
|
+
persona = {
|
|
18920
|
+
...persona,
|
|
18921
|
+
...p
|
|
18922
|
+
};
|
|
18923
|
+
on = -1;
|
|
18924
|
+
emit();
|
|
18925
|
+
},
|
|
18926
|
+
load(i) {
|
|
18927
|
+
const p = all()[i];
|
|
18928
|
+
if (!p) return;
|
|
18929
|
+
persona = {
|
|
18930
|
+
...blank(),
|
|
18931
|
+
...p.persona
|
|
18932
|
+
};
|
|
18933
|
+
on = i;
|
|
18934
|
+
emit();
|
|
18935
|
+
},
|
|
18936
|
+
save(label) {
|
|
18937
|
+
const name = label.trim() || persona.name || "preset";
|
|
18938
|
+
saved = [...saved.filter((s) => s.label !== name), {
|
|
18939
|
+
label: name,
|
|
18940
|
+
persona: { ...persona }
|
|
18941
|
+
}];
|
|
18942
|
+
on = builtIn.length + saved.length - 1;
|
|
18943
|
+
o.onSave?.(saved);
|
|
18944
|
+
emit();
|
|
18945
|
+
},
|
|
18946
|
+
removePreset(i) {
|
|
18947
|
+
const j = i - builtIn.length;
|
|
18948
|
+
if (j < 0 || j >= saved.length) return;
|
|
18949
|
+
saved = saved.filter((_, k) => k !== j);
|
|
18950
|
+
if (on === i) on = -1;
|
|
18951
|
+
o.onSave?.(saved);
|
|
18952
|
+
emit();
|
|
18953
|
+
},
|
|
18954
|
+
system(mem = [], budgetTokens = 3e3) {
|
|
18955
|
+
const a = budget({
|
|
18956
|
+
budgetTokens,
|
|
18957
|
+
sections: [
|
|
18958
|
+
{
|
|
18959
|
+
name: "profile",
|
|
18960
|
+
priority: 40,
|
|
18961
|
+
text: persona.profile.trim()
|
|
18962
|
+
},
|
|
18963
|
+
{
|
|
18964
|
+
name: "memory",
|
|
18965
|
+
priority: 30,
|
|
18966
|
+
text: mem.length ? `things you remember:\n${mem.map((m) => `- ${m.label}`).join("\n")}` : ""
|
|
18967
|
+
},
|
|
18968
|
+
{
|
|
18969
|
+
name: "notes",
|
|
18970
|
+
priority: 20,
|
|
18971
|
+
text: persona.notes.trim() ? `notes:\n${persona.notes.trim()}` : ""
|
|
18972
|
+
},
|
|
18973
|
+
{
|
|
18974
|
+
name: "rules",
|
|
18975
|
+
priority: 10,
|
|
18976
|
+
text: persona.rules.trim() ? `rules:\n${persona.rules.trim()}` : ""
|
|
18977
|
+
}
|
|
18978
|
+
].filter((s) => s.text)
|
|
18979
|
+
});
|
|
18980
|
+
return {
|
|
18981
|
+
text: a.kept.includes("profile") || !persona.profile.trim() ? a.text : [persona.profile.trim(), a.text].filter(Boolean).join("\n\n"),
|
|
18982
|
+
dropped: a.dropped
|
|
18983
|
+
};
|
|
18984
|
+
}
|
|
18985
|
+
};
|
|
18986
|
+
}
|
|
18987
|
+
/** Creates the voice state over a native engine (`webSpeechEngine()` of @hackbuild/speak). */
|
|
18988
|
+
function voiceRow(engine, o = {}) {
|
|
18989
|
+
let s = {
|
|
18990
|
+
auto: o.auto ?? false,
|
|
18991
|
+
voice: o.voice ?? "",
|
|
18992
|
+
rate: o.rate ?? 1,
|
|
18993
|
+
pitch: o.pitch ?? 1,
|
|
18994
|
+
speaking: false,
|
|
18995
|
+
error: ""
|
|
18996
|
+
};
|
|
18997
|
+
let ac = null;
|
|
18998
|
+
const subs = /* @__PURE__ */ new Set();
|
|
18999
|
+
const snap = () => ({
|
|
19000
|
+
...s,
|
|
19001
|
+
voices: engine.voices?.() ?? []
|
|
19002
|
+
});
|
|
19003
|
+
const emit = () => subs.forEach((f) => f(snap()));
|
|
19004
|
+
globalThis.speechSynthesis?.addEventListener?.("voiceschanged", emit);
|
|
19005
|
+
const row = {
|
|
19006
|
+
snapshot: snap,
|
|
19007
|
+
subscribe(fn) {
|
|
19008
|
+
subs.add(fn);
|
|
19009
|
+
fn(snap());
|
|
19010
|
+
return () => subs.delete(fn);
|
|
19011
|
+
},
|
|
19012
|
+
set(p) {
|
|
19013
|
+
s = {
|
|
19014
|
+
...s,
|
|
19015
|
+
...p
|
|
19016
|
+
};
|
|
19017
|
+
o.onChange?.({
|
|
19018
|
+
auto: s.auto,
|
|
19019
|
+
voice: s.voice,
|
|
19020
|
+
rate: s.rate,
|
|
19021
|
+
pitch: s.pitch
|
|
19022
|
+
});
|
|
19023
|
+
emit();
|
|
19024
|
+
},
|
|
19025
|
+
async speak(text) {
|
|
19026
|
+
row.stop();
|
|
19027
|
+
const mine = ac = new AbortController();
|
|
19028
|
+
s = {
|
|
19029
|
+
...s,
|
|
19030
|
+
speaking: true,
|
|
19031
|
+
error: ""
|
|
19032
|
+
};
|
|
19033
|
+
emit();
|
|
19034
|
+
try {
|
|
19035
|
+
await engine.load({ signal: mine.signal });
|
|
19036
|
+
await engine.speak(text, {
|
|
19037
|
+
...s.voice ? { voice: s.voice } : {},
|
|
19038
|
+
rate: s.rate,
|
|
19039
|
+
pitch: s.pitch
|
|
19040
|
+
}, { onBoundary: () => void 0 }, mine.signal);
|
|
19041
|
+
} catch (e) {
|
|
19042
|
+
if (!mine.signal.aborted) s = {
|
|
19043
|
+
...s,
|
|
19044
|
+
error: e instanceof Error ? e.message : String(e)
|
|
19045
|
+
};
|
|
19046
|
+
} finally {
|
|
19047
|
+
if (ac === mine) {
|
|
19048
|
+
ac = null;
|
|
19049
|
+
s = {
|
|
19050
|
+
...s,
|
|
19051
|
+
speaking: false
|
|
19052
|
+
};
|
|
19053
|
+
emit();
|
|
19054
|
+
}
|
|
19055
|
+
}
|
|
19056
|
+
},
|
|
19057
|
+
stop() {
|
|
19058
|
+
ac?.abort();
|
|
19059
|
+
engine.stop();
|
|
19060
|
+
},
|
|
19061
|
+
reply(text) {
|
|
19062
|
+
if (s.auto && text.trim()) row.speak(text);
|
|
19063
|
+
}
|
|
19064
|
+
};
|
|
19065
|
+
return row;
|
|
19066
|
+
}
|
|
17651
19067
|
exports.ALL_RECORDS = ALL_RECORDS;
|
|
17652
19068
|
exports.FACE_API_BASE = FACE_API_BASE;
|
|
17653
19069
|
exports.JOBS = JOBS;
|
|
@@ -17657,6 +19073,7 @@ self.onmessage = async (ev) => {
|
|
|
17657
19073
|
exports.asImage = asImage;
|
|
17658
19074
|
exports.backendOf = backendOf;
|
|
17659
19075
|
exports.boxWords = boxWords;
|
|
19076
|
+
exports.canClone = canClone;
|
|
17660
19077
|
exports.chatList = chatList;
|
|
17661
19078
|
exports.chatThread = chatThread;
|
|
17662
19079
|
exports.contextSegments = contextSegments;
|
|
@@ -17674,13 +19091,18 @@ self.onmessage = async (ev) => {
|
|
|
17674
19091
|
exports.labelColour = labelColour;
|
|
17675
19092
|
exports.optionsOf = optionsOf;
|
|
17676
19093
|
exports.ownRecord = ownRecord;
|
|
19094
|
+
exports.personaRack = personaRack;
|
|
17677
19095
|
exports.rowOf = rowOf;
|
|
17678
19096
|
exports.sizeWords = sizeWords;
|
|
19097
|
+
exports.speaker = speaker;
|
|
19098
|
+
exports.storedIds = storedIds;
|
|
17679
19099
|
exports.toView = toView;
|
|
17680
19100
|
exports.traceRows = traceRows;
|
|
17681
19101
|
exports.transcribeQueue = transcribeQueue;
|
|
17682
19102
|
exports.useJobsPick = useJobsPick;
|
|
17683
19103
|
exports.useModelPick = useModelPick;
|
|
19104
|
+
exports.verifyRepo = verifyRepo;
|
|
19105
|
+
exports.voiceRow = voiceRow;
|
|
17684
19106
|
exports.weightKeys = weightKeys;
|
|
17685
19107
|
exports.weightsLoader = weightsLoader;
|
|
17686
19108
|
exports.weightsRemover = weightsRemover;
|