loretoparisi / fasttext.js

FastText for Node.js
MIT License
192 stars 28 forks source link

Using in the browser with WASM #27

Open Uzay-G opened 2 years ago

Uzay-G commented 2 years ago

Are the uploaded binaries for WASM usable in the browser? I tried following https://fasttext.cc/docs/en/webassembly-module.html#build-a-webpage-that-uses-fasttext to load fasttext using the provided binaries but I got import errors:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
</head>
<body>
    <script type="module">
        import {FastText, addOnPostRun} from "./fasttext.js";

        addOnPostRun(() => {
            let ft = new FastText();
            console.log(ft);
        });

    </script>
</body>
</html>

Uncaught SyntaxError: import not found: addOnPostRun in the browser.

loretoparisi commented 2 years ago

@Uzay-G correct I will provide a modified WASM module for browser based inference.

wonderwhy-er commented 1 year ago

Was actually looking for something to do language identification client side, bit sad this does work even though it seems it could.