opencomic-ai-bin 1.0.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/LICENSE +21 -0
- package/README.md +260 -0
- package/calculate-latency.mts +72 -0
- package/dist/calculate-latency.mjs +761 -0
- package/dist/index.cjs +714 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.mjs +712 -0
- package/index.mts +922 -0
- package/linux/arm64/realcugan/realcugan-ncnn-vulkan +0 -0
- package/linux/arm64/waifu2x/waifu2x-ncnn-vulkan +0 -0
- package/linux/x64/realcugan/realcugan-ncnn-vulkan +0 -0
- package/linux/x64/upscayl/upscayl-bin +0 -0
- package/linux/x64/waifu2x/waifu2x-ncnn-vulkan +0 -0
- package/mac/arm64/realcugan/realcugan-ncnn-vulkan.app +0 -0
- package/mac/arm64/upscayl/upscayl-bin.app +0 -0
- package/mac/arm64/waifu2x/waifu2x-ncnn-vulkan.app +0 -0
- package/mac/x64/realcugan/realcugan-ncnn-vulkan.app +0 -0
- package/mac/x64/upscayl/upscayl-bin.app +0 -0
- package/mac/x64/waifu2x/waifu2x-ncnn-vulkan.app +0 -0
- package/package.json +42 -0
- package/rollup.config.js +47 -0
- package/tsconfig.json +13 -0
- package/win/x64/realcugan/realcugan-ncnn-vulkan.exe +0 -0
- package/win/x64/realcugan/vcomp140.dll +0 -0
- package/win/x64/upscayl/upscayl-bin.exe +0 -0
- package/win/x64/waifu2x/vcomp140.dll +0 -0
- package/win/x64/waifu2x/waifu2x-ncnn-vulkan.exe +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Oleguer Llopart
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# opencomic-ai-bin
|
|
2
|
+
|
|
3
|
+
This package provides pre-built binaries (`realcugan`, `waifu2x`, and `upscayl`) through a simple Node.js API.
|
|
4
|
+
|
|
5
|
+
Model files are not included, they are downloaded automatically when needed.
|
|
6
|
+
|
|
7
|
+
If you prefer to install all models upfront, use the [`opencomic-ai-models`](https://github.com/ollm/opencomic-ai-models) package.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install opencomic-ai-bin
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
This package can be used using CommonJS or ES Module.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
// CommonJS
|
|
21
|
+
const OpenComicAI = require('opencomic-ai-bin');
|
|
22
|
+
|
|
23
|
+
// ES Module
|
|
24
|
+
import OpenComicAI from 'opencomic-ai-bin';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Simple example of package usage
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import OpenComicAI from 'opencomic-ai-bin';
|
|
31
|
+
|
|
32
|
+
(async () => {
|
|
33
|
+
|
|
34
|
+
// Models path, if the model is not found in this folder, it will be downloaded
|
|
35
|
+
OpenComicAI.setModelsPath('./models');
|
|
36
|
+
|
|
37
|
+
await OpenComicAI.pipeline('./input.jpg', './output.jpg', [
|
|
38
|
+
{
|
|
39
|
+
model: '1x_halftone_patch_060000_G',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
model: 'realcugan',
|
|
43
|
+
scale: 4,
|
|
44
|
+
noise: 0,
|
|
45
|
+
}
|
|
46
|
+
], (progress) => {
|
|
47
|
+
|
|
48
|
+
console.log(`Processing: ${Math.round(progress * 100)}%`);
|
|
49
|
+
|
|
50
|
+
}, {
|
|
51
|
+
start: () => {
|
|
52
|
+
|
|
53
|
+
console.log(`Start download`);
|
|
54
|
+
|
|
55
|
+
},
|
|
56
|
+
progress: (progress) => {
|
|
57
|
+
|
|
58
|
+
console.log(`Downloading: ${Math.round(progress * 100)}%`);
|
|
59
|
+
|
|
60
|
+
},
|
|
61
|
+
end: () => {
|
|
62
|
+
|
|
63
|
+
console.log(`End download`);
|
|
64
|
+
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
})();
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### OpenComicAI.setModelsPath
|
|
72
|
+
|
|
73
|
+
Set the directory where models will be downloaded and stored.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
OpenComicAI.setModelsPath(path: string): void
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### OpenComicAI.models
|
|
80
|
+
|
|
81
|
+
Object containing all available models organized by type (upscale, descreen, artifact-removal).
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
OpenComicAI.models: Record<ModelType, Record<string, ModelObject>>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### OpenComicAI.modelsList
|
|
88
|
+
|
|
89
|
+
Array of all available model keys.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
OpenComicAI.modelsList: Model[]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### OpenComicAI.modelsTypeList
|
|
96
|
+
|
|
97
|
+
Models organized by type.
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
OpenComicAI.modelsTypeList: Record<ModelType, Model[]>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### OpenComicAI.modelsPath
|
|
104
|
+
|
|
105
|
+
Current path where models are stored.
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
OpenComicAI.modelsPath: string | undefined
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### OpenComicAI.binary
|
|
112
|
+
|
|
113
|
+
Get the path to the binary executable for a model.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
OpenComicAI.binary(model: Model): string
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### OpenComicAI.model
|
|
120
|
+
|
|
121
|
+
Get detailed information about a specific model.
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
OpenComicAI.model(model: Model): ModelObject
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### OpenComicAI.pipeline
|
|
128
|
+
Process an image through one or more AI models.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
OpenComicAI.pipeline(
|
|
132
|
+
source: string,
|
|
133
|
+
dest: string,
|
|
134
|
+
steps: OpenComicAIOptions[],
|
|
135
|
+
progress?: (progress: number) => void,
|
|
136
|
+
downloading?: Downloading
|
|
137
|
+
): Promise<string>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Types
|
|
141
|
+
|
|
142
|
+
### `Model`
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
type Model =
|
|
146
|
+
| 'realcugan'
|
|
147
|
+
| 'realesr-animevideov3'
|
|
148
|
+
| 'realesrgan-x4plus'
|
|
149
|
+
...
|
|
150
|
+
```
|
|
151
|
+
### `ModelType`
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
type ModelType = 'upscale' | 'descreen' | 'artifact-removal';
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### `Upscaler`
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
type Upscaler = 'realcugan' | 'upscayl' | 'waifu2x';
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### `Speed`
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
type Speed = 'Very Fast' | 'Fast' | 'Moderate' | 'Slow' | 'Very Slow';
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### `OpenComicAIOptions`
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
interface OpenComicAIOptions {
|
|
173
|
+
model?: Model | string;
|
|
174
|
+
noise?: 0 | 1 | 2 | 3;
|
|
175
|
+
scale?: number;
|
|
176
|
+
tileSize?: number;
|
|
177
|
+
gpuId?: string;
|
|
178
|
+
threads?: number;
|
|
179
|
+
tta?: boolean;
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### `ModelObject`
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
interface ModelObject {
|
|
187
|
+
key?: Model;
|
|
188
|
+
name: string;
|
|
189
|
+
upscaler: Upscaler;
|
|
190
|
+
type?: ModelType;
|
|
191
|
+
scales: number[];
|
|
192
|
+
noise: number[] | undefined;
|
|
193
|
+
latency: number;
|
|
194
|
+
speed?: Speed;
|
|
195
|
+
folder: string;
|
|
196
|
+
path?: string;
|
|
197
|
+
files: string[];
|
|
198
|
+
supportCurrentPlatform?: boolean;
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### `Downloading`
|
|
203
|
+
|
|
204
|
+
```typescript
|
|
205
|
+
interface Downloading {
|
|
206
|
+
start?: () => void;
|
|
207
|
+
progress?: (progress: number) => void;
|
|
208
|
+
end?: () => void;
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Models Info
|
|
213
|
+
|
|
214
|
+
### Artifact removal
|
|
215
|
+
|
|
216
|
+
Model | Name | Upscaler | Source
|
|
217
|
+
------|------|----------|-------
|
|
218
|
+
`1x_NMKD-Jaywreck3-Lite_320k` | NMKD Jaywreck3 Lite | `upscayl` | [NMKD.de](https://nmkd.de/?esrgan)
|
|
219
|
+
`1x_NMKD-Jaywreck3-Soft-Lite_320k` | NMKD Jaywreck3 Soft Lite | `upscayl` | [NMKD.de](https://nmkd.de/?esrgan)
|
|
220
|
+
`1x-SaiyaJin-DeJpeg` | SaiyaJin DeJpeg | `upscayl` | [OpenModelDB](https://openmodeldb.info/models/1x-SaiyaJin-DeJpeg)
|
|
221
|
+
|
|
222
|
+
### Descreen
|
|
223
|
+
|
|
224
|
+
Model | Name | Upscaler | Source
|
|
225
|
+
------|------|----------|-------
|
|
226
|
+
`1x_halftone_patch_060000_G` | Halftone Patch 060000 G | `upscayl` | [NMKD.de](https://nmkd.de/shared/?dir=ESRGAN/Models/Compression/Halftone)
|
|
227
|
+
`1x_wtp_descreenton_compact` | WTP DescreenTon Compact | `upscayl` | [OpenModelDB](https://openmodeldb.info/models/1x-wtp-descreentone-compact)
|
|
228
|
+
|
|
229
|
+
### Upscale
|
|
230
|
+
|
|
231
|
+
Model | Name | Upscaler | Source
|
|
232
|
+
------|------|----------|-------
|
|
233
|
+
`realcugan` | RealCUGAN | `realcugan` | [Moebytes/waifu2x](https://github.com/Moebytes/waifu2x/tree/eaadd13cf54ba3bcb3cbd3e4a1cb2cd922420c9b/real-cugan/models-se)
|
|
234
|
+
`realesr-animevideov3` | RealESR AnimeVideo v3 | `upscayl` | [xinntao/Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN)
|
|
235
|
+
`realesrgan-x4plus` | RealESRGAN x4 Plus | `upscayl` | [xinntao/Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN)
|
|
236
|
+
`realesrgan-x4plus-anime` | RealESRGAN x4 Plus Anime | `upscayl` | [xinntao/Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN)
|
|
237
|
+
`realesrnet-x4plus` | RealESRNet x4 Plus | `upscayl` | [xinntao/Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN)
|
|
238
|
+
`waifu2x-models-cunet` | Waifu2x CUnet | `waifu2x` | [Moebytes/waifu2x](https://github.com/Moebytes/waifu2x/tree/eaadd13cf54ba3bcb3cbd3e4a1cb2cd922420c9b/waifu2x/models-cunet)
|
|
239
|
+
`waifu2x-models-upconv` | Waifu2x UpConv | `waifu2x` | [Moebytes/waifu2x](https://github.com/Moebytes/waifu2x/tree/eaadd13cf54ba3bcb3cbd3e4a1cb2cd922420c9b/waifu2x/models-upconv_7_anime_style_art_rgb)
|
|
240
|
+
`4x-WTP-ColorDS` | WTP ColorDS | `upscayl` | [OpenModelDB](https://openmodeldb.info/models/4x-WTP-ColorDS)
|
|
241
|
+
`remacri-4x` | Remacri | `upscayl` | [upscayl/upscayl](https://github.com/upscayl/upscayl/tree/d6e9a36b894d302e6268dc239e8a51ff29c49ded/resources/models)
|
|
242
|
+
`ultramix-balanced-4x` | Ultramix Balanced | `upscayl` | [upscayl/upscayl](https://github.com/upscayl/upscayl/tree/d6e9a36b894d302e6268dc239e8a51ff29c49ded/resources/models)
|
|
243
|
+
`ultrasharp-4x` | Ultrasharp | `upscayl` | [upscayl/upscayl](https://github.com/upscayl/upscayl/tree/d6e9a36b894d302e6268dc239e8a51ff29c49ded/resources/models)
|
|
244
|
+
`4xHFA2k` | HFA2k | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
245
|
+
`4xLSDIRCompactC3` | LSDIR Compact C3 | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
246
|
+
`4xLSDIRplusC` | LSDIR Plus C | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
247
|
+
`4x_NMKD-Siax_200k` | NMKD Siax | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
248
|
+
`4xNomos8kSC` | Nomos 8k SC | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
249
|
+
`RealESRGAN_General_WDN_x4_v3` | RealESRGAN General WDN v3 | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
250
|
+
`RealESRGAN_General_x4_v3` | RealESRGAN General v3 | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
251
|
+
`uniscale_restore_x4` | Uniscale Restore x4 | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
252
|
+
`unknown-2.0.1` | Unknown 2.0.1 | `upscayl` | [upscayl/custom-models](https://github.com/upscayl/custom-models/tree/4b6d2cfa59c7442af115dfc6e50fd8d7d40b96ef/models)
|
|
253
|
+
|
|
254
|
+
## Credits
|
|
255
|
+
|
|
256
|
+
This project uses the following AI models and upscalers:
|
|
257
|
+
- [Real-CUGAN](https://github.com/bilibili/ailab/tree/main/Real-CUGAN)
|
|
258
|
+
- [Real-ESRGAN](https://github.com/xinntao/Real-ESRGAN)
|
|
259
|
+
- [Waifu2x](https://github.com/nagadomi/waifu2x)
|
|
260
|
+
- [Upscayl](https://github.com/upscayl/upscayl)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import OpenComicAI from './index.mjs';
|
|
2
|
+
|
|
3
|
+
(async function(){
|
|
4
|
+
|
|
5
|
+
console.log('Calculating latency for available models...');
|
|
6
|
+
|
|
7
|
+
const images = [
|
|
8
|
+
'../assets/sample-image-1.jpg',
|
|
9
|
+
// '../assets/sample-image-2.jpg',
|
|
10
|
+
// '../assets/sample-image-3.jpg',
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
OpenComicAI.setModelsPath('../assets/models');
|
|
14
|
+
|
|
15
|
+
const modelsList = OpenComicAI.modelsList;
|
|
16
|
+
const latencies : Record<string, number> = {};
|
|
17
|
+
const latenciesList: number[] = [];
|
|
18
|
+
|
|
19
|
+
for(const _model of modelsList)
|
|
20
|
+
{
|
|
21
|
+
const model = OpenComicAI.model(_model);
|
|
22
|
+
const startTime = Date.now();
|
|
23
|
+
|
|
24
|
+
for(const image of images)
|
|
25
|
+
{
|
|
26
|
+
await OpenComicAI.pipeline(image, '../assets/calculate-latency_'+_model+'.jpg', [
|
|
27
|
+
{
|
|
28
|
+
model: _model,
|
|
29
|
+
scale: 4,
|
|
30
|
+
}
|
|
31
|
+
], false, {
|
|
32
|
+
start: () => {
|
|
33
|
+
|
|
34
|
+
console.log(`Start download model: ${model.name}`);
|
|
35
|
+
|
|
36
|
+
},
|
|
37
|
+
progress: (progress) => {
|
|
38
|
+
|
|
39
|
+
console.log(`Downloading model: ${model.name} - ${Math.round(progress * 100)}%`);
|
|
40
|
+
|
|
41
|
+
},
|
|
42
|
+
end: () => {
|
|
43
|
+
|
|
44
|
+
console.log(`End download model: ${model.name}`);
|
|
45
|
+
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const endTime = Date.now();
|
|
51
|
+
const latency = endTime - startTime;
|
|
52
|
+
console.log(`Model: ${model.name}, Latency: ${latency} ms`);
|
|
53
|
+
latencies[model.name] = latency;
|
|
54
|
+
latenciesList.push(latency);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Min latency as 0.5 value max as 10
|
|
58
|
+
const minLatency = Math.min(...latenciesList);
|
|
59
|
+
const maxLatency = Math.max(...latenciesList);
|
|
60
|
+
|
|
61
|
+
for(const modelName in latencies)
|
|
62
|
+
{
|
|
63
|
+
const latency = latencies[modelName];
|
|
64
|
+
const normalizedLatency = (latency - minLatency) / (maxLatency - minLatency);
|
|
65
|
+
const scaledLatency = 0.5 + normalizedLatency * (10 - 0.5);
|
|
66
|
+
latencies[modelName] = Math.round(scaledLatency * 100) / 100;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
console.log('Latency calculation completed.');
|
|
70
|
+
console.log('Latencies:', latencies);
|
|
71
|
+
|
|
72
|
+
})();
|