Skip to content

Commit 26a1ba8

Browse files
committed
Create Node.js example scripts
1 parent d60561c commit 26a1ba8

File tree

9 files changed

+2059
-8
lines changed

9 files changed

+2059
-8
lines changed

Diff for: README.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
A collection of [🤗 Transformers.js](https://huggingface.co/docs/transformers.js) demos and example applications.
44

5-
| Name | Description | Links |
6-
| ------------------------------------------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------ |
7-
| [Phi-3.5 WebGPU](./phi-3.5-webgpu/) | Conversational large language model | [Demo](https://huggingface.co/spaces/webml-community/phi-3.5-webgpu) |
8-
| [SmolLM WebGPU](./smollm-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/smollm-webgpu) |
9-
| [Segment Anything WebGPU](./segment-anything-webgpu/) | WebGPU image segmentation | [Demo](https://huggingface.co/spaces/webml-community/segment-anything-webgpu) |
10-
| [Remove Background WebGPU](./remove-background-webgpu/) | WebGPU image background removal | [Demo](https://huggingface.co/spaces/webml-community/remove-background-webgpu) |
11-
| [PGlite Semantic Search](./pglite-semantic-search/) | Semantic search | [Demo](https://huggingface.co/spaces/thorwebdev/pglite-semantic-search) |
12-
| [Bun](./bun/) | Compute text embeddings in [Bun](https://bun.sh/) | n/a |
5+
| Name | Description | Links |
6+
| ------------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------------------------------ |
7+
| [Phi-3.5 WebGPU](./phi-3.5-webgpu/) | Conversational large language model | [Demo](https://huggingface.co/spaces/webml-community/phi-3.5-webgpu) |
8+
| [SmolLM WebGPU](./smollm-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/smollm-webgpu) |
9+
| [Segment Anything WebGPU](./segment-anything-webgpu/) | WebGPU image segmentation | [Demo](https://huggingface.co/spaces/webml-community/segment-anything-webgpu) |
10+
| [Remove Background WebGPU](./remove-background-webgpu/) | WebGPU image background removal | [Demo](https://huggingface.co/spaces/webml-community/remove-background-webgpu) |
11+
| [PGlite Semantic Search](./pglite-semantic-search/) | Semantic search | [Demo](https://huggingface.co/spaces/thorwebdev/pglite-semantic-search) |
12+
| [Bun](./bun/) | Compute text embeddings in [Bun](https://bun.sh/) | n/a |
13+
| [Node.js (ESM)](./node-esm/) | Sentiment analysis in Node.js w/ ECMAScript modules | n/a |
14+
| [Node.js (CJS)](./node-cjs/) | Sentiment analysis in Node.js w/ CommonJS | n/a |
1315

1416
Check out the Transformers.js [template](https://huggingface.co/new-space?template=static-templates%2Ftransformers.js) on Hugging Face to get started in one click!

Diff for: node-cjs/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# node-cjs
2+
3+
This project demonstrates how to use `@huggingface/transformers` in a Node.js environment using CommonJS Modules (CJS). The example utilizes `require` statements for module loading.
4+
5+
## Instructions
6+
7+
1. Clone the repository:
8+
```sh
9+
git clone https://github.com/huggingface/transformers.js-examples.git
10+
```
11+
2. Change directory to the `node-cjs` project:
12+
```sh
13+
cd transformers.js-examples/node-cjs
14+
```
15+
3. Install the dependencies:
16+
```sh
17+
npm install
18+
```
19+
4. Run the example:
20+
```sh
21+
node index.js
22+
```

Diff for: node-cjs/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { pipeline } = require("@huggingface/transformers");
2+
3+
async function main() {
4+
const classifier = await pipeline("text-classification");
5+
const result = await classifier("I love Transformers.js!");
6+
console.log(result); // [{ label: 'POSITIVE', score: 0.9997673034667969 }]
7+
}
8+
main();

0 commit comments

Comments
 (0)