@richardmcquiston01/ai-tools 0.2.0 → 0.3.0
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 +28 -1
- package/package.json +19 -4
package/README.md
CHANGED
|
@@ -36,6 +36,33 @@ const upscaler = await loadUpscaleModel(4);
|
|
|
36
36
|
const bigger: ImageData = await upscaler.upscale(image);
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
## Entry points
|
|
40
|
+
|
|
41
|
+
TensorFlow.js and ONNX Runtime are large, and most apps need only one of them. Import from the entry point you need so a bundler never has to include the rest:
|
|
42
|
+
|
|
43
|
+
| Import | Brings | Heavy dependency |
|
|
44
|
+
| ------------------------------------------------- | ----------------------------------- | --------------------------- |
|
|
45
|
+
| `@richardmcquiston01/ai-tools/background-removal` | `loadBackgroundRemovalModel` | ONNX Runtime Web |
|
|
46
|
+
| `@richardmcquiston01/ai-tools/auto-crop` | `computeCropRegion` | none |
|
|
47
|
+
| `@richardmcquiston01/ai-tools/upscale` | `loadUpscaleModel` | TensorFlow.js, the upscaler |
|
|
48
|
+
| `@richardmcquiston01/ai-tools/provider` | `OnnxBackgroundRemover` (see below) | none until the model loads |
|
|
49
|
+
| `@richardmcquiston01/ai-tools` | all of the above except `provider` | everything |
|
|
50
|
+
|
|
51
|
+
The main entry keeps working as before; the others are for apps that care about size. `computeCropRegion` is plain maths, so auto-crop's region helper never needs a model runtime (running the model for the saliency mask still does: that is `background-removal`).
|
|
52
|
+
|
|
53
|
+
## The model file
|
|
54
|
+
|
|
55
|
+
The U²-Net model is exported, so a bundler can emit it for you and you can drop any copy step. With Vite:
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
import modelUrl from "@richardmcquiston01/ai-tools/models/u2netp.onnx?url";
|
|
59
|
+
import { loadBackgroundRemovalModel } from "@richardmcquiston01/ai-tools/background-removal";
|
|
60
|
+
|
|
61
|
+
const model = await loadBackgroundRemovalModel(modelUrl);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
In Node, `import.meta.resolve("@richardmcquiston01/ai-tools/models/u2netp.onnx")` gives its location. The licence and attribution files in `models/` are exported the same way.
|
|
65
|
+
|
|
39
66
|
## As an `ImageGenerator` (optional)
|
|
40
67
|
|
|
41
68
|
`@richardmcquiston01/ai-tools/provider` wraps background removal as an `ImageGenerator` from [`@richardmcquiston01/ai-providers`](https://www.npmjs.com/package/@richardmcquiston01/ai-providers), so an app can offer it next to other providers (a local ComfyUI, a hosted API) and swap between them through one interface. `ai-providers` is an optional peer dependency: install it only if you use this entry point.
|
|
@@ -70,7 +97,7 @@ else console.error(result.error); // names the provider and what failed
|
|
|
70
97
|
|
|
71
98
|
## Model files and offline use
|
|
72
99
|
|
|
73
|
-
- **Background removal:** the package ships `models/u2netp.onnx` (about 4.5 MB). Serve or import it
|
|
100
|
+
- **Background removal:** the package ships `models/u2netp.onnx` (about 4.5 MB) and exports it (see above). Serve or import it and pass it to `loadBackgroundRemovalModel`; nothing is fetched on your behalf.
|
|
74
101
|
- **Upscaling:** by default the model definitions load their weights from a public CDN mirror of `@upscalerjs/esrgan-slim`. For a self-contained deployment, serve that package's `models/<scale>x/` directory and pass the resolved `model.json` URL as `modelUrl`.
|
|
75
102
|
- **Size:** TensorFlow.js and ONNX Runtime are large. Load this package lazily (`await import(...)`) rather than in your main bundle.
|
|
76
103
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@richardmcquiston01/ai-tools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "In-browser AI image tools (background removal, upscaling, auto-crop) for laser/CNC/maker workflows",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"background-removal",
|
|
@@ -33,10 +33,23 @@
|
|
|
33
33
|
"types": "./dist/index.d.ts",
|
|
34
34
|
"default": "./dist/index.js"
|
|
35
35
|
},
|
|
36
|
+
"./background-removal": {
|
|
37
|
+
"types": "./dist/background-removal.d.ts",
|
|
38
|
+
"default": "./dist/background-removal.js"
|
|
39
|
+
},
|
|
40
|
+
"./upscale": {
|
|
41
|
+
"types": "./dist/upscale.d.ts",
|
|
42
|
+
"default": "./dist/upscale.js"
|
|
43
|
+
},
|
|
44
|
+
"./auto-crop": {
|
|
45
|
+
"types": "./dist/auto-crop.d.ts",
|
|
46
|
+
"default": "./dist/auto-crop.js"
|
|
47
|
+
},
|
|
36
48
|
"./provider": {
|
|
37
49
|
"types": "./dist/provider.d.ts",
|
|
38
50
|
"default": "./dist/provider.js"
|
|
39
|
-
}
|
|
51
|
+
},
|
|
52
|
+
"./models/*": "./models/*"
|
|
40
53
|
},
|
|
41
54
|
"files": [
|
|
42
55
|
"dist",
|
|
@@ -53,7 +66,7 @@
|
|
|
53
66
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
54
67
|
},
|
|
55
68
|
"dependencies": {
|
|
56
|
-
"@richardmcquiston01/core-image": "0.
|
|
69
|
+
"@richardmcquiston01/core-image": "0.3.0",
|
|
57
70
|
"@tensorflow/tfjs": "4.11.0",
|
|
58
71
|
"@upscalerjs/esrgan-slim": "1.0.0",
|
|
59
72
|
"onnxruntime-web": "1.27.0",
|
|
@@ -61,6 +74,7 @@
|
|
|
61
74
|
},
|
|
62
75
|
"devDependencies": {
|
|
63
76
|
"@richardmcquiston01/ai-providers": "^0.1.0",
|
|
77
|
+
"esbuild": "^0.25.12",
|
|
64
78
|
"jsdom": "^25.0.1",
|
|
65
79
|
"typescript": "^5.7.3",
|
|
66
80
|
"vitest": "^3.0.4"
|
|
@@ -72,5 +86,6 @@
|
|
|
72
86
|
"@richardmcquiston01/ai-providers": {
|
|
73
87
|
"optional": true
|
|
74
88
|
}
|
|
75
|
-
}
|
|
89
|
+
},
|
|
90
|
+
"sideEffects": false
|
|
76
91
|
}
|