Skip to content

Wrapture lets you go from a Python-trained model to deployable JavaScript with a single command. It generates TypeScript bindings and a Web/Node-compatible wrapper, using WebGPU/WASM-ready ONNX runtimes.

License

Notifications You must be signed in to change notification settings

phun-ky/wrapture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

84 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Wrapture

wrapture logo

One-click exporter from PyTorch models to Web-ready ONNX with JS/TS wrappers.

Commitizen friendly PRs Welcome SemVer 2.0 npm version issues license size npm GitHub Repo stars codecov build

About

Wrapture lets you go from a Python-trained model to deployable JavaScript with a single command. It generates TypeScript bindings and a Web/Node-compatible wrapper, using WebGPU/WASM-ready ONNX runtimes.

Note

This is an experiment trying to fulfil a need between python and js. YMMV

Table of Contents

πŸš€ Features

  • βœ… Convert PyTorch models to ONNX
  • βœ… Optional ONNX simplification and quantization
  • βœ… Generate loadModel() + predict() JavaScript wrappers
  • βœ… Auto-generate .d.ts TypeScript bindings

Prerequisites

Python 3.10+ required

Install Python if you don’t have it: πŸ‘‰ https://www.python.org/downloads/


Install required Python packages

python3 -m pip install torch onnx onnxsim onnxruntime

Check your installation:

python3 -c "import torch; print(torch.__version__)"
python3 -c "import onnx; print(onnx.__version__)"

You should see output like:

2.x.x etc..

Installation

npm i -g wrapture

Generating a Model

A helper script is provided to create a basic test model.

python3 python/scripts/basic_model.py

This generates:

test/fixtures/basic_model.pt

Usage

wrapture --input test/fixtures/basic_model.pt --output ./wrapped

You’ll see a spinner as the model is converted, and then a JS/TS wrapper is written to the ./wrapped/ directory.

Output Structure

Example contents of a --output ./ folder:

/
 β”œβ”€β”€ wrapped.ts # The loadModel() + predict() logic
 β”œβ”€β”€ wrapped.d.ts # Fully typed API
 └── model.onnx # Exported ONNX model

Example: Using the Generated Model

import { loadModel } from './wrapped.js';

const model = await loadModel();

const input = { data: new Float32Array(1 _3_ 224 \* 224), dims: [1, 3, 224, 224]
};

const result = await model.predict(input); console.log(result); // { // logits:
Float32Array, // probabilities: number[], // predictedClass: number // }

API

Full API documentation is available here.


Contributing

Want to contribute? Please read the CONTRIBUTING.md and CODE_OF_CONDUCT.md

License

This project is licensed under the MIT License - see the LICENSE file for details.

Changelog

See the CHANGELOG.md for details on the latest updates.

Sponsor me

I'm an Open Source evangelist, creating stuff that does not exist yet to help get rid of secondary activities and to enhance systems already in place, be it documentation or web sites.

The sponsorship is an unique opportunity to alleviate more hours for me to maintain my projects, create new ones and contribute to the large community we're all part of :)

Support me on GitHub Sponsors.

p.s. Ukraine is still under brutal Russian invasion. A lot of Ukrainian people are hurt, without shelter and need help. You can help in various ways, for instance, directly helping refugees, spreading awareness, putting pressure on your local government or companies. You can also support Ukraine by donating e.g. to Red Cross, Ukraine humanitarian organisation or donate Ambulances for Ukraine.

About

Wrapture lets you go from a Python-trained model to deployable JavaScript with a single command. It generates TypeScript bindings and a Web/Node-compatible wrapper, using WebGPU/WASM-ready ONNX runtimes.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 2

  •  
  •