opencomic-ai-bin 1.0.1 → 1.0.3
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 -0
- package/dist/calculate-latency.mjs +7 -3
- package/dist/index.cjs +7 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.mjs +7 -3
- package/index.mts +11 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,6 +31,9 @@ import OpenComicAI from 'opencomic-ai-bin';
|
|
|
31
31
|
|
|
32
32
|
(async () => {
|
|
33
33
|
|
|
34
|
+
// Set the base directory for binary paths, for example change to app.asar.unpacked path in Electron apps
|
|
35
|
+
OpenComicAI.setDirname(OpenComicAI.__dirname.replace(/app(-(?:arm64|x64))?\.asar/, 'app$1.asar.unpacked'));
|
|
36
|
+
|
|
34
37
|
// Models path, if the model is not found in this folder, it will be downloaded
|
|
35
38
|
OpenComicAI.setModelsPath('./models');
|
|
36
39
|
|
|
@@ -68,6 +71,14 @@ import OpenComicAI from 'opencomic-ai-bin';
|
|
|
68
71
|
})();
|
|
69
72
|
```
|
|
70
73
|
|
|
74
|
+
### OpenComicAI.setDirname
|
|
75
|
+
|
|
76
|
+
Set the base directory for binary paths.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
OpenComicAI.setDirname(dirname: string): void
|
|
80
|
+
```
|
|
81
|
+
|
|
71
82
|
### OpenComicAI.setModelsPath
|
|
72
83
|
|
|
73
84
|
Set the directory where models will be downloaded and stored.
|
|
@@ -76,6 +87,14 @@ Set the directory where models will be downloaded and stored.
|
|
|
76
87
|
OpenComicAI.setModelsPath(path: string): void
|
|
77
88
|
```
|
|
78
89
|
|
|
90
|
+
### OpenComicAI.\_\_dirname
|
|
91
|
+
|
|
92
|
+
Get the base directory for binary paths.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
OpenComicAI.__dirname: string
|
|
96
|
+
```
|
|
97
|
+
|
|
79
98
|
### OpenComicAI.models
|
|
80
99
|
|
|
81
100
|
Object containing all available models organized by type (upscale, descreen, artifact-removal).
|
|
@@ -125,6 +144,7 @@ OpenComicAI.model(model: Model): ModelObject
|
|
|
125
144
|
```
|
|
126
145
|
|
|
127
146
|
### OpenComicAI.pipeline
|
|
147
|
+
|
|
128
148
|
Process an image through one or more AI models.
|
|
129
149
|
|
|
130
150
|
```ts
|
|
@@ -137,6 +157,14 @@ OpenComicAI.pipeline(
|
|
|
137
157
|
): Promise<string>
|
|
138
158
|
```
|
|
139
159
|
|
|
160
|
+
### OpenComicAI.closest
|
|
161
|
+
|
|
162
|
+
Returns the value in the array closest to the target value.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
OpenComicAI.closest(array: number[], target: number): number
|
|
166
|
+
```
|
|
167
|
+
|
|
140
168
|
## Types
|
|
141
169
|
|
|
142
170
|
### `Model`
|
|
@@ -164,7 +164,7 @@ let models = {
|
|
|
164
164
|
'waifu2x-models-cunet': {
|
|
165
165
|
name: 'Waifu2x CUnet',
|
|
166
166
|
upscaler: 'waifu2x',
|
|
167
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
167
|
+
scales: [/*1, */ 2, 4, 8, 16, 32],
|
|
168
168
|
noise: [0, 1, 2, 3],
|
|
169
169
|
latency: 2.92,
|
|
170
170
|
folder: './waifu2x/models-cunet',
|
|
@@ -192,7 +192,7 @@ let models = {
|
|
|
192
192
|
'waifu2x-models-upconv': {
|
|
193
193
|
name: 'Waifu2x UpConv',
|
|
194
194
|
upscaler: 'waifu2x',
|
|
195
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
195
|
+
scales: [/*1, */ 2, 4, 8, 16, 32],
|
|
196
196
|
noise: [0, 1, 2, 3],
|
|
197
197
|
latency: 0.8,
|
|
198
198
|
folder: './waifu2x/models-upconv_7_anime_style_art_rgb',
|
|
@@ -486,6 +486,7 @@ class OpenComicAI {
|
|
|
486
486
|
static modelsList = modelsList;
|
|
487
487
|
static modelsTypeList = modelsTypeList;
|
|
488
488
|
static modelsPath = undefined;
|
|
489
|
+
static __dirname = ___dirname;
|
|
489
490
|
static resolve = (path) => {
|
|
490
491
|
if (!p.isAbsolute(path)) {
|
|
491
492
|
if (typeof module !== 'undefined')
|
|
@@ -501,6 +502,9 @@ class OpenComicAI {
|
|
|
501
502
|
throw new Error(`Models path does not exist: ${path}`);
|
|
502
503
|
OpenComicAI.modelsPath = path;
|
|
503
504
|
};
|
|
505
|
+
static setDirname = (dirname) => {
|
|
506
|
+
OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
|
|
507
|
+
};
|
|
504
508
|
static model = (model = DEFAULT_MODEL) => {
|
|
505
509
|
if (!modelsList.includes(model))
|
|
506
510
|
throw new Error(`Model not found: ${model}`);
|
|
@@ -515,7 +519,7 @@ class OpenComicAI {
|
|
|
515
519
|
static binary = (model) => {
|
|
516
520
|
if (!modelsList.includes(model))
|
|
517
521
|
throw new Error(`Model not found: ${model}`);
|
|
518
|
-
const base = p.join(
|
|
522
|
+
const base = p.join(OpenComicAI.__dirname, '..');
|
|
519
523
|
const upscaler = OpenComicAI.model(model).upscaler;
|
|
520
524
|
const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
|
|
521
525
|
return p.join(base, result);
|
package/dist/index.cjs
CHANGED
|
@@ -166,7 +166,7 @@ let models = {
|
|
|
166
166
|
'waifu2x-models-cunet': {
|
|
167
167
|
name: 'Waifu2x CUnet',
|
|
168
168
|
upscaler: 'waifu2x',
|
|
169
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
169
|
+
scales: [/*1, */ 2, 4, 8, 16, 32],
|
|
170
170
|
noise: [0, 1, 2, 3],
|
|
171
171
|
latency: 2.92,
|
|
172
172
|
folder: './waifu2x/models-cunet',
|
|
@@ -194,7 +194,7 @@ let models = {
|
|
|
194
194
|
'waifu2x-models-upconv': {
|
|
195
195
|
name: 'Waifu2x UpConv',
|
|
196
196
|
upscaler: 'waifu2x',
|
|
197
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
197
|
+
scales: [/*1, */ 2, 4, 8, 16, 32],
|
|
198
198
|
noise: [0, 1, 2, 3],
|
|
199
199
|
latency: 0.8,
|
|
200
200
|
folder: './waifu2x/models-upconv_7_anime_style_art_rgb',
|
|
@@ -488,6 +488,7 @@ class OpenComicAI {
|
|
|
488
488
|
static modelsList = modelsList;
|
|
489
489
|
static modelsTypeList = modelsTypeList;
|
|
490
490
|
static modelsPath = undefined;
|
|
491
|
+
static __dirname = ___dirname;
|
|
491
492
|
static resolve = (path) => {
|
|
492
493
|
if (!p.isAbsolute(path)) {
|
|
493
494
|
if (typeof module !== 'undefined')
|
|
@@ -503,6 +504,9 @@ class OpenComicAI {
|
|
|
503
504
|
throw new Error(`Models path does not exist: ${path}`);
|
|
504
505
|
OpenComicAI.modelsPath = path;
|
|
505
506
|
};
|
|
507
|
+
static setDirname = (dirname) => {
|
|
508
|
+
OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
|
|
509
|
+
};
|
|
506
510
|
static model = (model = DEFAULT_MODEL) => {
|
|
507
511
|
if (!modelsList.includes(model))
|
|
508
512
|
throw new Error(`Model not found: ${model}`);
|
|
@@ -517,7 +521,7 @@ class OpenComicAI {
|
|
|
517
521
|
static binary = (model) => {
|
|
518
522
|
if (!modelsList.includes(model))
|
|
519
523
|
throw new Error(`Model not found: ${model}`);
|
|
520
|
-
const base = p.join(
|
|
524
|
+
const base = p.join(OpenComicAI.__dirname, '..');
|
|
521
525
|
const upscaler = OpenComicAI.model(model).upscaler;
|
|
522
526
|
const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
|
|
523
527
|
return p.join(base, result);
|
package/dist/index.d.ts
CHANGED
|
@@ -42,14 +42,16 @@ declare class OpenComicAI {
|
|
|
42
42
|
static modelsList: string[];
|
|
43
43
|
static modelsTypeList: Record<ModelType, string[]>;
|
|
44
44
|
static modelsPath: string | undefined;
|
|
45
|
+
static __dirname: any;
|
|
45
46
|
private static resolve;
|
|
46
47
|
static setModelsPath: (path: string) => void;
|
|
48
|
+
static setDirname: (dirname: string) => void;
|
|
47
49
|
static model: (model?: Model) => ModelObject;
|
|
48
50
|
static binary: (model: Model) => string;
|
|
49
51
|
private static download;
|
|
50
52
|
private static getModels;
|
|
51
53
|
static pipeline: (source: string, dest: string, steps: OpenComicAIOptions[], progress?: ((progress?: number) => void) | false, downloading?: Downloading | false) => Promise<string>;
|
|
52
|
-
|
|
54
|
+
static closest: (array: number[], target: number) => number;
|
|
53
55
|
private static image;
|
|
54
56
|
}
|
|
55
57
|
|
package/dist/index.mjs
CHANGED
|
@@ -164,7 +164,7 @@ let models = {
|
|
|
164
164
|
'waifu2x-models-cunet': {
|
|
165
165
|
name: 'Waifu2x CUnet',
|
|
166
166
|
upscaler: 'waifu2x',
|
|
167
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
167
|
+
scales: [/*1, */ 2, 4, 8, 16, 32],
|
|
168
168
|
noise: [0, 1, 2, 3],
|
|
169
169
|
latency: 2.92,
|
|
170
170
|
folder: './waifu2x/models-cunet',
|
|
@@ -192,7 +192,7 @@ let models = {
|
|
|
192
192
|
'waifu2x-models-upconv': {
|
|
193
193
|
name: 'Waifu2x UpConv',
|
|
194
194
|
upscaler: 'waifu2x',
|
|
195
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
195
|
+
scales: [/*1, */ 2, 4, 8, 16, 32],
|
|
196
196
|
noise: [0, 1, 2, 3],
|
|
197
197
|
latency: 0.8,
|
|
198
198
|
folder: './waifu2x/models-upconv_7_anime_style_art_rgb',
|
|
@@ -486,6 +486,7 @@ class OpenComicAI {
|
|
|
486
486
|
static modelsList = modelsList;
|
|
487
487
|
static modelsTypeList = modelsTypeList;
|
|
488
488
|
static modelsPath = undefined;
|
|
489
|
+
static __dirname = ___dirname;
|
|
489
490
|
static resolve = (path) => {
|
|
490
491
|
if (!p.isAbsolute(path)) {
|
|
491
492
|
if (typeof module !== 'undefined')
|
|
@@ -501,6 +502,9 @@ class OpenComicAI {
|
|
|
501
502
|
throw new Error(`Models path does not exist: ${path}`);
|
|
502
503
|
OpenComicAI.modelsPath = path;
|
|
503
504
|
};
|
|
505
|
+
static setDirname = (dirname) => {
|
|
506
|
+
OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
|
|
507
|
+
};
|
|
504
508
|
static model = (model = DEFAULT_MODEL) => {
|
|
505
509
|
if (!modelsList.includes(model))
|
|
506
510
|
throw new Error(`Model not found: ${model}`);
|
|
@@ -515,7 +519,7 @@ class OpenComicAI {
|
|
|
515
519
|
static binary = (model) => {
|
|
516
520
|
if (!modelsList.includes(model))
|
|
517
521
|
throw new Error(`Model not found: ${model}`);
|
|
518
|
-
const base = p.join(
|
|
522
|
+
const base = p.join(OpenComicAI.__dirname, '..');
|
|
519
523
|
const upscaler = OpenComicAI.model(model).upscaler;
|
|
520
524
|
const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
|
|
521
525
|
return p.join(base, result);
|
package/index.mts
CHANGED
|
@@ -212,7 +212,7 @@ let models: Record<ModelType, Record<string, ModelObject>> = {
|
|
|
212
212
|
'waifu2x-models-cunet': {
|
|
213
213
|
name: 'Waifu2x CUnet',
|
|
214
214
|
upscaler: 'waifu2x',
|
|
215
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
215
|
+
scales: [/*1, */2, 4, 8, 16, 32],
|
|
216
216
|
noise: [0, 1, 2, 3],
|
|
217
217
|
latency: 2.92,
|
|
218
218
|
folder: './waifu2x/models-cunet',
|
|
@@ -240,7 +240,7 @@ let models: Record<ModelType, Record<string, ModelObject>> = {
|
|
|
240
240
|
'waifu2x-models-upconv': {
|
|
241
241
|
name: 'Waifu2x UpConv',
|
|
242
242
|
upscaler: 'waifu2x',
|
|
243
|
-
scales: [1, 2, 4, 8, 16, 32],
|
|
243
|
+
scales: [/*1, */2, 4, 8, 16, 32],
|
|
244
244
|
noise: [0, 1, 2, 3],
|
|
245
245
|
latency: 0.8,
|
|
246
246
|
folder: './waifu2x/models-upconv_7_anime_style_art_rgb',
|
|
@@ -566,6 +566,7 @@ export default class OpenComicAI {
|
|
|
566
566
|
public static modelsList = modelsList;
|
|
567
567
|
public static modelsTypeList = modelsTypeList;
|
|
568
568
|
public static modelsPath: string | undefined = undefined;
|
|
569
|
+
public static __dirname = ___dirname;
|
|
569
570
|
|
|
570
571
|
private static resolve = (path: string): string => {
|
|
571
572
|
|
|
@@ -592,6 +593,12 @@ export default class OpenComicAI {
|
|
|
592
593
|
|
|
593
594
|
}
|
|
594
595
|
|
|
596
|
+
public static setDirname = (dirname: string): void => {
|
|
597
|
+
|
|
598
|
+
OpenComicAI.__dirname = OpenComicAI.resolve(dirname);
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
595
602
|
public static model = (model: Model = DEFAULT_MODEL): ModelObject => {
|
|
596
603
|
|
|
597
604
|
if(!modelsList.includes(model as Model))
|
|
@@ -612,7 +619,7 @@ export default class OpenComicAI {
|
|
|
612
619
|
if(!modelsList.includes(model as Model))
|
|
613
620
|
throw new Error(`Model not found: ${model}`);
|
|
614
621
|
|
|
615
|
-
const base = p.join(
|
|
622
|
+
const base = p.join(OpenComicAI.__dirname, '..');
|
|
616
623
|
|
|
617
624
|
const upscaler = OpenComicAI.model(model as Model).upscaler;
|
|
618
625
|
const result = upscalers[upscaler].platforms[process.platform]?.[process.arch] ?? upscalers[upscaler].platforms[process.platform]?.x64 ?? upscalers[upscaler].platforms.linux?.x64 ?? '';
|
|
@@ -787,7 +794,7 @@ export default class OpenComicAI {
|
|
|
787
794
|
|
|
788
795
|
}
|
|
789
796
|
|
|
790
|
-
|
|
797
|
+
public static closest = (array: number[], target: number): number => {
|
|
791
798
|
|
|
792
799
|
return array.reduce((prev, curr) => {
|
|
793
800
|
return Math.abs(curr - target) < Math.abs(prev - target) ? curr : prev;
|