wrapture 0.0.1
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/.browserslistrc +4 -0
- package/.editorconfig +10 -0
- package/.eslintrc +0 -0
- package/.github/FUNDING.yml +4 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/dependabot.yml +25 -0
- package/.github/labeler.yml +72 -0
- package/.github/labels.yml +24 -0
- package/.github/workflows/auto-assign.yml +19 -0
- package/.github/workflows/check.yml +72 -0
- package/.github/workflows/label.yml +16 -0
- package/.github/workflows/publish.yml +66 -0
- package/.github/workflows/triage.yml +18 -0
- package/.markdownlint.json +7 -0
- package/.prettierrc +7 -0
- package/.release-it.json +67 -0
- package/CHANGELOG.md +8 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +200 -0
- package/LICENSE +21 -0
- package/README.md +182 -0
- package/SECURITY.md +16 -0
- package/api/README.md +35 -0
- package/api/utils/convert.md +96 -0
- package/api/utils/generate-wrapper.md +91 -0
- package/api/wrapture.md +31 -0
- package/bin/wrapture.js +148 -0
- package/custom-typedoc-plugin.js +55 -0
- package/eslint.config.mjs +16 -0
- package/package.json +74 -0
- package/public/docs/README.md +1 -0
- package/python/convert.py +72 -0
- package/python/scripts/basic_model.py +20 -0
- package/scripts/test.ts +11 -0
- package/src/utils/__tests__/convert.unit.ts +47 -0
- package/src/utils/__tests__/generate-wrapper.unit.ts +29 -0
- package/src/utils/convert.ts +98 -0
- package/src/utils/generate-wrapper.ts +107 -0
- package/src/wrapture.ts +51 -0
- package/test/fixtures/basic_model.pt +0 -0
- package/tsconfig.json +27 -0
- package/tsup.config.ts +14 -0
- package/typedoc.json +33 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# Contributing to **wrapture**
|
|
2
|
+
|
|
3
|
+
First off, thanks for taking the time to contribute! ❤️
|
|
4
|
+
|
|
5
|
+
All types of contributions are encouraged and valued. See the
|
|
6
|
+
[Table of Contents](#table-of-contents) for different ways to help and details
|
|
7
|
+
about how this project handles them. Please make sure to read the relevant
|
|
8
|
+
section before making your contribution. It will make it a lot easier for us
|
|
9
|
+
maintainers and smooth out the experience for all involved. The community looks
|
|
10
|
+
forward to your contributions. 🎉
|
|
11
|
+
|
|
12
|
+
> And if you like the project, but just don't have time to contribute, that's
|
|
13
|
+
> fine. There are other easy ways to support the project and show your
|
|
14
|
+
> appreciation, which we would also be very happy about:
|
|
15
|
+
>
|
|
16
|
+
> - Star the project
|
|
17
|
+
> - Tweet about it
|
|
18
|
+
> - Refer this project in your project's readme
|
|
19
|
+
> - Mention the project at local meetups and tell your friends/colleagues
|
|
20
|
+
|
|
21
|
+
## Table of Contents
|
|
22
|
+
|
|
23
|
+
- [Contributing to **wrapture**](#contributing-to-wrapture)
|
|
24
|
+
- [Table of Contents](#table-of-contents)
|
|
25
|
+
- [Code of Conduct](#code-of-conduct)
|
|
26
|
+
- [I Have a Question](#i-have-a-question)
|
|
27
|
+
- [I Want To Contribute](#i-want-to-contribute)
|
|
28
|
+
- [Reporting Bugs](#reporting-bugs)
|
|
29
|
+
- [Before Submitting a Bug Report](#before-submitting-a-bug-report)
|
|
30
|
+
- [How Do I Submit a Good Bug Report?](#how-do-i-submit-a-good-bug-report)
|
|
31
|
+
- [Suggesting Enhancements](#suggesting-enhancements)
|
|
32
|
+
- [Before Submitting an Enhancement](#before-submitting-an-enhancement)
|
|
33
|
+
- [How Do I Submit a Good Enhancement Suggestion?](#how-do-i-submit-a-good-enhancement-suggestion)
|
|
34
|
+
- [Attribution](#attribution)
|
|
35
|
+
|
|
36
|
+
## Code of Conduct
|
|
37
|
+
|
|
38
|
+
This project and everyone participating in it is governed by the
|
|
39
|
+
[**wrapture** Code of Conduct](https://github.com/phun-ky/wrapture/blob/master/CODE_OF_CONDUCT.md).
|
|
40
|
+
By participating, you are expected to uphold this code. Please report
|
|
41
|
+
unacceptable behavior to <code-of-conduct@phun-ky.net>.
|
|
42
|
+
|
|
43
|
+
## I Have a Question
|
|
44
|
+
|
|
45
|
+
> If you want to ask a question, we assume that you have read the available
|
|
46
|
+
> [Documentation](https://github.com/phun-ky/wrapture).
|
|
47
|
+
|
|
48
|
+
Before you ask a question, it is best to search for existing
|
|
49
|
+
[Issues](https://github.com/phun-ky/wrapture/issues) that might help you. In
|
|
50
|
+
case you have found a suitable issue and still need clarification, you can write
|
|
51
|
+
your question in this issue. It is also advisable to search the internet for
|
|
52
|
+
answers first.
|
|
53
|
+
|
|
54
|
+
If you then still feel the need to ask a question and need clarification, we
|
|
55
|
+
recommend the following:
|
|
56
|
+
|
|
57
|
+
- Open an [Issue](https://github.com/phun-ky/wrapture/issues/new).
|
|
58
|
+
- Provide as much context as you can about what you're running into.
|
|
59
|
+
- Provide project and platform versions (nodejs, npm, etc), depending on what
|
|
60
|
+
seems relevant.
|
|
61
|
+
|
|
62
|
+
We will then take care of the issue as soon as possible.
|
|
63
|
+
|
|
64
|
+
<!--
|
|
65
|
+
You might want to create a separate issue tag for questions and include it in this description. People should then tag their issues accordingly.
|
|
66
|
+
|
|
67
|
+
Depending on how large the project is, you may want to outsource the questioning, e.g. to Stack Overflow or Gitter. You may add additional contact and information possibilities:
|
|
68
|
+
- IRC
|
|
69
|
+
- Slack
|
|
70
|
+
- Gitter
|
|
71
|
+
- Stack Overflow tag
|
|
72
|
+
- Blog
|
|
73
|
+
- FAQ
|
|
74
|
+
- Roadmap
|
|
75
|
+
- E-Mail List
|
|
76
|
+
- Forum
|
|
77
|
+
-->
|
|
78
|
+
|
|
79
|
+
## I Want To Contribute
|
|
80
|
+
|
|
81
|
+
> ### Legal Notice
|
|
82
|
+
>
|
|
83
|
+
> When contributing to this project, you must agree that you have authored 100%
|
|
84
|
+
> of the content, that you have the necessary rights to the content and that the
|
|
85
|
+
> content you contribute may be provided under the project license.
|
|
86
|
+
|
|
87
|
+
### Reporting Bugs
|
|
88
|
+
|
|
89
|
+
#### Before Submitting a Bug Report
|
|
90
|
+
|
|
91
|
+
A good bug report shouldn't leave others needing to chase you up for more
|
|
92
|
+
information. Therefore, we ask you to investigate carefully, collect information
|
|
93
|
+
and describe the issue in detail in your report. Please complete the following
|
|
94
|
+
steps in advance to help us fix any potential bug as fast as possible.
|
|
95
|
+
|
|
96
|
+
- Make sure that you are using the latest version.
|
|
97
|
+
- Determine if your bug is really a bug and not an error on your side e.g. using
|
|
98
|
+
incompatible environment components/versions (Make sure that you have read the
|
|
99
|
+
[documentation](https://github.com/phun-ky/wrapture). If you are looking for
|
|
100
|
+
support, you might want to check [this section](#i-have-a-question)).
|
|
101
|
+
- To see if other users have experienced (and potentially already solved) the
|
|
102
|
+
same issue you are having, check if there is not already a bug report existing
|
|
103
|
+
for your bug or error in the
|
|
104
|
+
[bug tracker](https://github.com/phun-ky/wraptureissues?q=label%3Abug).
|
|
105
|
+
- Also make sure to search the internet (including Stack Overflow) to see if
|
|
106
|
+
users outside of the GitHub community have discussed the issue.
|
|
107
|
+
- Collect information about the bug:
|
|
108
|
+
- Stack trace (Traceback)
|
|
109
|
+
- OS, Platform and Version (Windows, Linux, macOS, x86, ARM)
|
|
110
|
+
- Version of the interpreter, compiler, SDK, runtime environment, package
|
|
111
|
+
manager, depending on what seems relevant.
|
|
112
|
+
- Possibly your input and the output
|
|
113
|
+
- Can you reliably reproduce the issue? And can you also reproduce it with
|
|
114
|
+
older versions?
|
|
115
|
+
|
|
116
|
+
#### How Do I Submit a Good Bug Report?
|
|
117
|
+
|
|
118
|
+
> You must never report security related issues, vulnerabilities or bugs
|
|
119
|
+
> including sensitive information to the issue tracker, or elsewhere in public.
|
|
120
|
+
> Instead sensitive bugs must be sent by email to <wrapture@phun-ky.net>.
|
|
121
|
+
|
|
122
|
+
<!-- You may add a PGP key to allow the messages to be sent encrypted as well. -->
|
|
123
|
+
|
|
124
|
+
We use GitHub issues to track bugs and errors. If you run into an issue with the
|
|
125
|
+
project:
|
|
126
|
+
|
|
127
|
+
- Open an [Issue](https://github.com/phun-ky/wrapture/issues/new). (Since we
|
|
128
|
+
can't be sure at this point whether it is a bug or not, we ask you not to talk
|
|
129
|
+
about a bug yet and not to label the issue.)
|
|
130
|
+
- Explain the behavior you would expect and the actual behavior.
|
|
131
|
+
- Please provide as much context as possible and describe the _reproduction
|
|
132
|
+
steps_ that someone else can follow to recreate the issue on their own. This
|
|
133
|
+
usually includes your code. For good bug reports you should isolate the
|
|
134
|
+
problem and create a reduced test case.
|
|
135
|
+
- Provide the information you collected in the previous section.
|
|
136
|
+
|
|
137
|
+
Once it's filed:
|
|
138
|
+
|
|
139
|
+
- The project team will label the issue accordingly.
|
|
140
|
+
- A team member will try to reproduce the issue with your provided steps. If
|
|
141
|
+
there are no reproduction steps or no obvious way to reproduce the issue, the
|
|
142
|
+
team will ask you for those steps and mark the issue as `pending: need repro`.
|
|
143
|
+
Bugs with the `pending: need repro` tag will not be addressed until they are
|
|
144
|
+
reproduced.
|
|
145
|
+
- If the team is able to reproduce the issue, it will be marked `🐛 needs fix`,
|
|
146
|
+
as well as possibly other tags (such as `problems: critical`), and the issue
|
|
147
|
+
will be left to be implemented by someone.
|
|
148
|
+
|
|
149
|
+
<!-- You might want to create an issue template for bugs and errors that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
|
|
150
|
+
|
|
151
|
+
### Suggesting Enhancements
|
|
152
|
+
|
|
153
|
+
This section guides you through submitting an enhancement suggestion for
|
|
154
|
+
**wrapture**, **including completely new features and minor improvements to
|
|
155
|
+
existing functionality**. Following these guidelines will help maintainers and
|
|
156
|
+
the community to understand your suggestion and find related suggestions.
|
|
157
|
+
|
|
158
|
+
#### Before Submitting an Enhancement
|
|
159
|
+
|
|
160
|
+
- Make sure that you are using the latest version.
|
|
161
|
+
- Read the [documentation](https://github.com/phun-ky/wrapture) carefully and
|
|
162
|
+
find out if the functionality is already covered, maybe by an individual
|
|
163
|
+
configuration.
|
|
164
|
+
- Perform a [search](https://github.com/phun-ky/wrapture/issues) to see if the
|
|
165
|
+
enhancement has already been suggested. If it has, add a comment to the
|
|
166
|
+
existing issue instead of opening a new one.
|
|
167
|
+
- Find out whether your idea fits with the scope and aims of the project. It's
|
|
168
|
+
up to you to make a strong case to convince the project's developers of the
|
|
169
|
+
merits of this feature. Keep in mind that we want features that will be useful
|
|
170
|
+
to the majority of our users and not just a small subset. If you're just
|
|
171
|
+
targeting a minority of users, consider writing an add-on/plugin library.
|
|
172
|
+
|
|
173
|
+
#### How Do I Submit a Good Enhancement Suggestion?
|
|
174
|
+
|
|
175
|
+
Enhancement suggestions are tracked as
|
|
176
|
+
[GitHub issues](https://github.com/phun-ky/wrapture/issues).
|
|
177
|
+
|
|
178
|
+
- Use a **clear and descriptive title** for the issue to identify the
|
|
179
|
+
suggestion.
|
|
180
|
+
- Provide a **step-by-step description of the suggested enhancement** in as many
|
|
181
|
+
details as possible.
|
|
182
|
+
- **Describe the current behavior** and **explain which behavior you expected to
|
|
183
|
+
see instead** and why. At this point you can also tell which alternatives do
|
|
184
|
+
not work for you.
|
|
185
|
+
- You may want to **include screenshots and animated GIFs** which help you
|
|
186
|
+
demonstrate the steps or point out the part which the suggestion is related
|
|
187
|
+
to. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on
|
|
188
|
+
macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast)
|
|
189
|
+
or [this tool](https://github.com/GNOME/byzanz) on Linux.
|
|
190
|
+
<!-- this should only be included if the project has a GUI -->
|
|
191
|
+
- **Explain why this enhancement would be useful** to most **wrapture** users.
|
|
192
|
+
You may also want to point out the other projects that solved it better and
|
|
193
|
+
which could serve as inspiration.
|
|
194
|
+
|
|
195
|
+
<!-- You might want to create an issue template for enhancement suggestions that can be used as a guide and that defines the structure of the information to be included. If you do so, reference it here in the description. -->
|
|
196
|
+
|
|
197
|
+
## Attribution
|
|
198
|
+
|
|
199
|
+
This guide is based on the **contributing-gen**.
|
|
200
|
+
[Make your own](https://github.com/bttger/contributing-gen)!
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alexander Vassbotn Røyne-Helgesen
|
|
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,182 @@
|
|
|
1
|
+
# 🌀 Wrapture
|
|
2
|
+
|
|
3
|
+
[](http://commitizen.github.io/cz-cli/)
|
|
4
|
+
[](http://makeapullrequest.com)
|
|
5
|
+
[](http://semver.org/spec/v2.0.0.html)
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
[](https://codecov.io/gh/phun-ky/wrapture)
|
|
13
|
+
[](https://github.com/phun-ky/wrapture/actions/workflows/check.yml)
|
|
14
|
+
|
|
15
|
+
> One-click exporter from PyTorch models to Web-ready ONNX with JS/TS wrappers.
|
|
16
|
+
|
|
17
|
+
## About
|
|
18
|
+
|
|
19
|
+
Wrapture lets you go from a Python-trained model to deployable JavaScript with a
|
|
20
|
+
single command. It generates TypeScript bindings and a Web/Node-compatible
|
|
21
|
+
wrapper, using WebGPU/WASM-ready ONNX runtimes.
|
|
22
|
+
|
|
23
|
+
> [!NOTE] This is an experiment trying to fulfil a need between python and js.
|
|
24
|
+
> YMMV
|
|
25
|
+
|
|
26
|
+
## Table of Contents<!-- omit from toc -->
|
|
27
|
+
|
|
28
|
+
---- [🌀 Wrapture](#-wrapture)
|
|
29
|
+
|
|
30
|
+
- [🌀 Wrapture](#-wrapture)
|
|
31
|
+
- [About](#about)
|
|
32
|
+
- [🚀 Features](#-features)
|
|
33
|
+
- [Prerequisites](#prerequisites)
|
|
34
|
+
- [Python 3.10+ required](#python-310-required)
|
|
35
|
+
- [Install required Python packages](#install-required-python-packages)
|
|
36
|
+
- [Installation](#installation)
|
|
37
|
+
- [Generating a Model](#generating-a-model)
|
|
38
|
+
- [Usage](#usage)
|
|
39
|
+
- [Output Structure](#output-structure)
|
|
40
|
+
- [Example: Using the Generated Model](#example-using-the-generated-model)
|
|
41
|
+
- [API](#api)
|
|
42
|
+
- [Contributing](#contributing)
|
|
43
|
+
- [License](#license)
|
|
44
|
+
- [Changelog](#changelog)
|
|
45
|
+
- [Sponsor me](#sponsor-me)
|
|
46
|
+
|
|
47
|
+
## 🚀 Features
|
|
48
|
+
|
|
49
|
+
- ✅ Convert PyTorch models to ONNX
|
|
50
|
+
- ✅ Optional ONNX simplification and quantization
|
|
51
|
+
- ✅ Generate `loadModel()` + `predict()` JavaScript wrappers
|
|
52
|
+
- ✅ Auto-generate `.d.ts` TypeScript bindings
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Prerequisites
|
|
57
|
+
|
|
58
|
+
### Python 3.10+ required
|
|
59
|
+
|
|
60
|
+
Install Python if you don’t have it: 👉 <https://www.python.org/downloads/>
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### Install required Python packages
|
|
65
|
+
|
|
66
|
+
```shell-session
|
|
67
|
+
python3 -m pip install torch onnx onnxsim onnxruntime onnxruntime-tools
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Check your installation:
|
|
71
|
+
|
|
72
|
+
```shell-session
|
|
73
|
+
python3 -c "import torch; print(torch.__version__)"
|
|
74
|
+
python3 -c "import onnx; print(onnx.__version__)"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
You should see output like:
|
|
78
|
+
|
|
79
|
+
`2.x.x` etc..
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
```shell-session
|
|
84
|
+
npm i -g wrapture
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Generating a Model
|
|
88
|
+
|
|
89
|
+
A helper script is provided to create a basic test model.
|
|
90
|
+
|
|
91
|
+
```shell-session
|
|
92
|
+
python3 python/scripts/basic_model.py
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
This generates:
|
|
96
|
+
|
|
97
|
+
```shell-session
|
|
98
|
+
test/fixtures/basic_model.pt
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Usage
|
|
102
|
+
|
|
103
|
+
```shell-session
|
|
104
|
+
wrapture --input test/fixtures/basic_model.pt --output ./wrapped
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
You’ll see a spinner as the model is converted, and then a JS/TS wrapper is
|
|
108
|
+
written to the ./wrapped/ directory.
|
|
109
|
+
|
|
110
|
+
## Output Structure
|
|
111
|
+
|
|
112
|
+
Example contents of a `--output ./` folder:
|
|
113
|
+
|
|
114
|
+
```shell-session
|
|
115
|
+
/
|
|
116
|
+
├── wrapped.ts # The loadModel() + predict() logic
|
|
117
|
+
├── wrapped.d.ts # Fully typed API
|
|
118
|
+
└── model.onnx # Exported ONNX model
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Example: Using the Generated Model
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { loadModel } from './wrapped.js';
|
|
125
|
+
|
|
126
|
+
const model = await loadModel();
|
|
127
|
+
|
|
128
|
+
const input = { data: new Float32Array(1 _3_ 224 \* 224), dims: [1, 3, 224, 224]
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const result = await model.predict(input); console.log(result); // { // logits:
|
|
132
|
+
Float32Array, // probabilities: number[], // predictedClass: number // }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## API
|
|
138
|
+
|
|
139
|
+
Full API documentation is available
|
|
140
|
+
[here](https://github.com/phun-ky/wrapture/blob/main/api/README.md).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
Want to contribute? Please read the
|
|
147
|
+
[CONTRIBUTING.md](https://github.com/phun-ky/wrapture/blob/main/CONTRIBUTING.md)
|
|
148
|
+
and
|
|
149
|
+
[CODE_OF_CONDUCT.md](https://github.com/phun-ky/wrapture/blob/main/CODE_OF_CONDUCT.md)
|
|
150
|
+
|
|
151
|
+
## License
|
|
152
|
+
|
|
153
|
+
This project is licensed under the MIT License - see the
|
|
154
|
+
[LICENSE](https://github.com/phun-ky/wrapture/blob/main/LICENSE) file for
|
|
155
|
+
details.
|
|
156
|
+
|
|
157
|
+
## Changelog
|
|
158
|
+
|
|
159
|
+
See the
|
|
160
|
+
[CHANGELOG.md](https://github.com/phun-ky/wrapture/blob/main/CHANGELOG.md) for
|
|
161
|
+
details on the latest updates.
|
|
162
|
+
|
|
163
|
+
## Sponsor me
|
|
164
|
+
|
|
165
|
+
I'm an Open Source evangelist, creating stuff that does not exist yet to help
|
|
166
|
+
get rid of secondary activities and to enhance systems already in place, be it
|
|
167
|
+
documentation or web sites.
|
|
168
|
+
|
|
169
|
+
The sponsorship is an unique opportunity to alleviate more hours for me to
|
|
170
|
+
maintain my projects, create new ones and contribute to the large community
|
|
171
|
+
we're all part of :)
|
|
172
|
+
|
|
173
|
+
[Support me on GitHub Sponsors](https://github.com/sponsors/phun-ky).
|
|
174
|
+
|
|
175
|
+
p.s. **Ukraine is still under brutal Russian invasion. A lot of Ukrainian people
|
|
176
|
+
are hurt, without shelter and need help**. You can help in various ways, for
|
|
177
|
+
instance, directly helping refugees, spreading awareness, putting pressure on
|
|
178
|
+
your local government or companies. You can also support Ukraine by donating
|
|
179
|
+
e.g. to [Red Cross](https://www.icrc.org/en/donate/ukraine),
|
|
180
|
+
[Ukraine humanitarian organisation](https://savelife.in.ua/en/donate-en/#donate-army-card-weekly)
|
|
181
|
+
or
|
|
182
|
+
[donate Ambulances for Ukraine](https://www.gofundme.com/f/help-to-save-the-lives-of-civilians-in-a-war-zone).
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
I strive to keep this as secure as possible.
|
|
4
|
+
|
|
5
|
+
## Supported Versions
|
|
6
|
+
|
|
7
|
+
These are the versions that is updated with security patches.
|
|
8
|
+
|
|
9
|
+
| Version | Supported |
|
|
10
|
+
| ------- | ------------------ |
|
|
11
|
+
| >= 1.0 | :white_check_mark: |
|
|
12
|
+
| < 1.0 | :x: |
|
|
13
|
+
|
|
14
|
+
## Reporting a Vulnerability
|
|
15
|
+
|
|
16
|
+
Report vulnerabilities to <security@phun-ky.net>
|
package/api/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# wrapture API documentation
|
|
2
|
+
|
|
3
|
+
> Last updated 2025-05-14T13:01:48.933Z
|
|
4
|
+
|
|
5
|
+
## Modules
|
|
6
|
+
|
|
7
|
+
- [utils/convert](utils/convert.md)
|
|
8
|
+
- [utils/generate-wrapper](utils/generate-wrapper.md)
|
|
9
|
+
- [wrapture](wrapture.md)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
**Contributing**
|
|
14
|
+
|
|
15
|
+
Want to contribute? Please read the
|
|
16
|
+
[CONTRIBUTING.md](https://github.com/phun-ky/wrapture/blob/main/CONTRIBUTING.md)
|
|
17
|
+
and
|
|
18
|
+
[CODE_OF_CONDUCT.md](https://github.com/phun-ky/wrapture/blob/main/CODE_OF_CONDUCT.md)
|
|
19
|
+
|
|
20
|
+
**Sponsor me**
|
|
21
|
+
|
|
22
|
+
I'm an Open Source evangelist, creating stuff that does not exist yet to help
|
|
23
|
+
get rid of secondary activities and to enhance systems already in place, be it
|
|
24
|
+
documentation or web sites.
|
|
25
|
+
|
|
26
|
+
The sponsorship is an unique opportunity to alleviate more hours for me to
|
|
27
|
+
maintain my projects, create new ones and contribute to the large community
|
|
28
|
+
we're all part of :)
|
|
29
|
+
|
|
30
|
+
[Support me on GitHub Sponsors](https://github.com/sponsors/phun-ky).
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
This project created by [Alexander Vassbotn Røyne-Helgesen](http://phun-ky.net)
|
|
35
|
+
is licensed under a [MIT License](https://choosealicense.com/licenses/mit/).
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
[wrapture](../README.md) / utils/convert
|
|
2
|
+
|
|
3
|
+
# utils/convert
|
|
4
|
+
|
|
5
|
+
> Last updated 2025-05-14T13:01:49.077Z
|
|
6
|
+
|
|
7
|
+
## Interfaces
|
|
8
|
+
|
|
9
|
+
### ConvertOptionsInterface
|
|
10
|
+
|
|
11
|
+
Defined in:
|
|
12
|
+
[utils/convert.ts:17](https://github.com/phun-ky/wrapture/blob/main/src/utils/convert.ts#L17)
|
|
13
|
+
|
|
14
|
+
Options for the [convert](#convert) function.
|
|
15
|
+
|
|
16
|
+
#### Properties
|
|
17
|
+
|
|
18
|
+
| Property | Type | Description | Defined in |
|
|
19
|
+
| --------------------------------- | --------- | --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
20
|
+
| <a id="format"></a> `format?` | `string` | The output format for the converted model (e.g., 'onnx'). Defaults to 'onnx' if not provided. | [utils/convert.ts:22](https://github.com/phun-ky/wrapture/blob/main/src/utils/convert.ts#L22) |
|
|
21
|
+
| <a id="quantize"></a> `quantize?` | `boolean` | Whether to apply quantization to the model. | [utils/convert.ts:27](https://github.com/phun-ky/wrapture/blob/main/src/utils/convert.ts#L27) |
|
|
22
|
+
|
|
23
|
+
## Functions
|
|
24
|
+
|
|
25
|
+
### convert()
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
function convert(inputPath, outputDir, opts): Promise<void>;
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Defined in:
|
|
32
|
+
[utils/convert.ts:54](https://github.com/phun-ky/wrapture/blob/main/src/utils/convert.ts#L54)
|
|
33
|
+
|
|
34
|
+
Converts a machine learning model to ONNX or another supported format by
|
|
35
|
+
delegating to a Python script (`convert.py`).
|
|
36
|
+
|
|
37
|
+
This function spawns a subprocess using `python3` and monitors stdout/stderr. It
|
|
38
|
+
supports additional options such as format selection and quantization.
|
|
39
|
+
|
|
40
|
+
convert
|
|
41
|
+
|
|
42
|
+
#### Parameters
|
|
43
|
+
|
|
44
|
+
| Parameter | Type | Description |
|
|
45
|
+
| ----------- | ----------------------------------------------------- | --------------------------------------------------- |
|
|
46
|
+
| `inputPath` | `string` | Path to the input model file |
|
|
47
|
+
| `outputDir` | `string` | Directory where the converted model should be saved |
|
|
48
|
+
| `opts` | [`ConvertOptionsInterface`](#convertoptionsinterface) | Conversion options |
|
|
49
|
+
|
|
50
|
+
#### Returns
|
|
51
|
+
|
|
52
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>
|
|
53
|
+
|
|
54
|
+
A promise that resolves on success or rejects if conversion fails
|
|
55
|
+
|
|
56
|
+
#### Throws
|
|
57
|
+
|
|
58
|
+
If the Python process exits with a non-zero code
|
|
59
|
+
|
|
60
|
+
#### Example
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
await convert('models/model.pt', 'out/', { format: 'onnx', quantize: true });
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### See
|
|
67
|
+
|
|
68
|
+
- https://nodejs.org/api/child\_process.html#child\_processspawncommand-args-options
|
|
69
|
+
- https://github.com/sindresorhus/ora - Ora spinner for CLI feedback
|
|
70
|
+
- https://github.com/chalk/chalk - Chalk for terminal coloring
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
**Contributing**
|
|
75
|
+
|
|
76
|
+
Want to contribute? Please read the
|
|
77
|
+
[CONTRIBUTING.md](https://github.com/phun-ky/wrapture/blob/main/CONTRIBUTING.md)
|
|
78
|
+
and
|
|
79
|
+
[CODE_OF_CONDUCT.md](https://github.com/phun-ky/wrapture/blob/main/CODE_OF_CONDUCT.md)
|
|
80
|
+
|
|
81
|
+
**Sponsor me**
|
|
82
|
+
|
|
83
|
+
I'm an Open Source evangelist, creating stuff that does not exist yet to help
|
|
84
|
+
get rid of secondary activities and to enhance systems already in place, be it
|
|
85
|
+
documentation or web sites.
|
|
86
|
+
|
|
87
|
+
The sponsorship is an unique opportunity to alleviate more hours for me to
|
|
88
|
+
maintain my projects, create new ones and contribute to the large community
|
|
89
|
+
we're all part of :)
|
|
90
|
+
|
|
91
|
+
[Support me on GitHub Sponsors](https://github.com/sponsors/phun-ky).
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
This project created by [Alexander Vassbotn Røyne-Helgesen](http://phun-ky.net)
|
|
96
|
+
is licensed under a [MIT License](https://choosealicense.com/licenses/mit/).
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
[wrapture](../README.md) / utils/generate-wrapper
|
|
2
|
+
|
|
3
|
+
# utils/generate-wrapper
|
|
4
|
+
|
|
5
|
+
> Last updated 2025-05-14T13:01:49.182Z
|
|
6
|
+
|
|
7
|
+
## Interfaces
|
|
8
|
+
|
|
9
|
+
### GenerateWrapperOptionsInterface
|
|
10
|
+
|
|
11
|
+
Defined in:
|
|
12
|
+
[utils/generate-wrapper.ts:9](https://github.com/phun-ky/wrapture/blob/main/src/utils/generate-wrapper.ts#L9)
|
|
13
|
+
|
|
14
|
+
Options for generating ONNX wrapper files.
|
|
15
|
+
|
|
16
|
+
#### Properties
|
|
17
|
+
|
|
18
|
+
| Property | Type | Description | Defined in |
|
|
19
|
+
| ------------------------------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
20
|
+
| <a id="backend"></a> `backend` | `string` | The backend to use for inference. This affects the model file used. If set to `'wasm'`, the generated wrapper will load `model_quant.onnx`, otherwise it will load `model.onnx`. | [utils/generate-wrapper.ts:15](https://github.com/phun-ky/wrapture/blob/main/src/utils/generate-wrapper.ts#L15) |
|
|
21
|
+
|
|
22
|
+
## Functions
|
|
23
|
+
|
|
24
|
+
### generateWrapper()
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
function generateWrapper(outputDir, opts): Promise<void>;
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Defined in:
|
|
31
|
+
[utils/generate-wrapper.ts:39](https://github.com/phun-ky/wrapture/blob/main/src/utils/generate-wrapper.ts#L39)
|
|
32
|
+
|
|
33
|
+
Generates a TypeScript wrapper and type definition file (`wrapped.ts` and
|
|
34
|
+
`wrapped.d.ts`) for use with `onnxruntime-web`, including utility functions like
|
|
35
|
+
`softmax`, `argmax`, and a typed `predict()` function.
|
|
36
|
+
|
|
37
|
+
The generated code loads the correct ONNX model based on the provided backend.
|
|
38
|
+
|
|
39
|
+
#### Parameters
|
|
40
|
+
|
|
41
|
+
| Parameter | Type | Description |
|
|
42
|
+
| ----------- | --------------------------------------------------------------------- | ------------------------------------------------------ |
|
|
43
|
+
| `outputDir` | `string` | The directory where the wrapper files will be written. |
|
|
44
|
+
| `opts` | [`GenerateWrapperOptionsInterface`](#generatewrapperoptionsinterface) | Wrapper generation options, including backend type. |
|
|
45
|
+
|
|
46
|
+
#### Returns
|
|
47
|
+
|
|
48
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`>
|
|
49
|
+
|
|
50
|
+
A Promise that resolves when the wrapper files are successfully written.
|
|
51
|
+
|
|
52
|
+
#### Throws
|
|
53
|
+
|
|
54
|
+
Will throw an error if file writing fails.
|
|
55
|
+
|
|
56
|
+
#### Example
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
await generateWrapper('./dist', { backend: 'wasm' });
|
|
60
|
+
// Creates `wrapped.ts` and `wrapped.d.ts` in ./dist
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
#### See
|
|
64
|
+
|
|
65
|
+
https://www.npmjs.com/package/onnxruntime-web
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
**Contributing**
|
|
70
|
+
|
|
71
|
+
Want to contribute? Please read the
|
|
72
|
+
[CONTRIBUTING.md](https://github.com/phun-ky/wrapture/blob/main/CONTRIBUTING.md)
|
|
73
|
+
and
|
|
74
|
+
[CODE_OF_CONDUCT.md](https://github.com/phun-ky/wrapture/blob/main/CODE_OF_CONDUCT.md)
|
|
75
|
+
|
|
76
|
+
**Sponsor me**
|
|
77
|
+
|
|
78
|
+
I'm an Open Source evangelist, creating stuff that does not exist yet to help
|
|
79
|
+
get rid of secondary activities and to enhance systems already in place, be it
|
|
80
|
+
documentation or web sites.
|
|
81
|
+
|
|
82
|
+
The sponsorship is an unique opportunity to alleviate more hours for me to
|
|
83
|
+
maintain my projects, create new ones and contribute to the large community
|
|
84
|
+
we're all part of :)
|
|
85
|
+
|
|
86
|
+
[Support me on GitHub Sponsors](https://github.com/sponsors/phun-ky).
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
This project created by [Alexander Vassbotn Røyne-Helgesen](http://phun-ky.net)
|
|
91
|
+
is licensed under a [MIT License](https://choosealicense.com/licenses/mit/).
|
package/api/wrapture.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[wrapture](README.md) / wrapture
|
|
2
|
+
|
|
3
|
+
# wrapture
|
|
4
|
+
|
|
5
|
+
> Last updated 2025-05-14T13:01:49.217Z
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
**Contributing**
|
|
10
|
+
|
|
11
|
+
Want to contribute? Please read the
|
|
12
|
+
[CONTRIBUTING.md](https://github.com/phun-ky/wrapture/blob/main/CONTRIBUTING.md)
|
|
13
|
+
and
|
|
14
|
+
[CODE_OF_CONDUCT.md](https://github.com/phun-ky/wrapture/blob/main/CODE_OF_CONDUCT.md)
|
|
15
|
+
|
|
16
|
+
**Sponsor me**
|
|
17
|
+
|
|
18
|
+
I'm an Open Source evangelist, creating stuff that does not exist yet to help
|
|
19
|
+
get rid of secondary activities and to enhance systems already in place, be it
|
|
20
|
+
documentation or web sites.
|
|
21
|
+
|
|
22
|
+
The sponsorship is an unique opportunity to alleviate more hours for me to
|
|
23
|
+
maintain my projects, create new ones and contribute to the large community
|
|
24
|
+
we're all part of :)
|
|
25
|
+
|
|
26
|
+
[Support me on GitHub Sponsors](https://github.com/sponsors/phun-ky).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
This project created by [Alexander Vassbotn Røyne-Helgesen](http://phun-ky.net)
|
|
31
|
+
is licensed under a [MIT License](https://choosealicense.com/licenses/mit/).
|