Skip to content

Commit 565317e

Browse files
authored
Merge pull request huggingface#10 from huggingface/sveltekit
Add SvelteKit example
2 parents 4800c13 + 96dd297 commit 565317e

35 files changed

+5797
-79
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
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-
| [Llama-3.2 WebGPU](./llama-3.2-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/llama-3.2-webgpu) |
9-
| [SmolLM WebGPU](./smollm-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/smollm-webgpu) |
10-
| [Segment Anything WebGPU](./segment-anything-webgpu/) | WebGPU image segmentation | [Demo](https://huggingface.co/spaces/webml-community/segment-anything-webgpu) |
11-
| [Remove Background WebGPU](./remove-background-webgpu/) | WebGPU image background removal | [Demo](https://huggingface.co/spaces/webml-community/remove-background-webgpu) |
12-
| [PGlite Semantic Search](./pglite-semantic-search/) | Semantic search | [Demo](https://huggingface.co/spaces/thorwebdev/pglite-semantic-search) |
13-
| [Sapiens](./sapiens-node/) | Image segmentation, depth, and normal estimation in Node.js | n/a |
14-
| [Bun](./bun/) | Compute text embeddings in [Bun](https://bun.sh/) | n/a |
15-
| [Deno](./deno-embed/) | Compute text embeddings in [Deno](https://deno.com/) | n/a |
16-
| [Node.js (ESM)](./node-esm/) | Sentiment analysis in Node.js w/ ECMAScript modules | n/a |
17-
| [Node.js (CJS)](./node-cjs/) | Sentiment analysis in Node.js w/ CommonJS | n/a |
18-
| [Next.js](./next-server/) | Sentiment analysis in Next.js | [Demo](https://huggingface.co/spaces/webml-community/next-server-template) |
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+
| [Llama-3.2 WebGPU](./llama-3.2-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/llama-3.2-webgpu) |
9+
| [SmolLM WebGPU](./smollm-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/smollm-webgpu) |
10+
| [Segment Anything WebGPU](./segment-anything-webgpu/) | WebGPU image segmentation | [Demo](https://huggingface.co/spaces/webml-community/segment-anything-webgpu) |
11+
| [Remove Background WebGPU](./remove-background-webgpu/) | WebGPU image background removal | [Demo](https://huggingface.co/spaces/webml-community/remove-background-webgpu) |
12+
| [PGlite Semantic Search](./pglite-semantic-search/) | Semantic search | [Demo](https://huggingface.co/spaces/thorwebdev/pglite-semantic-search) |
13+
| [Sapiens](./sapiens-node/) | Image segmentation, depth, and normal estimation in Node.js | n/a |
14+
| [Bun](./bun/) | Compute text embeddings in [Bun](https://bun.sh/) | n/a |
15+
| [Deno](./deno-embed/) | Compute text embeddings in [Deno](https://deno.com/) | n/a |
16+
| [Node.js (ESM)](./node-esm/) | Sentiment analysis in Node.js w/ ECMAScript modules | n/a |
17+
| [Node.js (CJS)](./node-cjs/) | Sentiment analysis in Node.js w/ CommonJS | n/a |
18+
| [Next.js](./next-server/) | Sentiment analysis in Next.js | [Demo](https://huggingface.co/spaces/webml-community/next-server-template) |
19+
| [SvelteKit](./sveltekit/) | Sentiment analysis in SvelteKit | [Demo](https://huggingface.co/spaces/webml-community/sveltekit-server-template) |
1920

2021
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!

next-server/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ app_port: 3000
1010

1111
# next-server
1212

13-
This project, bootstrapped using generated by [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app), demonstrates how to use `@huggingface/transformers` in [Next.js](https://nextjs.org).
13+
This project, bootstrapped using [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app), demonstrates how to use `@huggingface/transformers` in [Next.js](https://nextjs.org).
1414

1515
## Instructions
1616

next-server/app/api/classify/route.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
import { pipeline } from "@huggingface/transformers";
44

5-
// NOTE: We attach the classifier to the global object to avoid loading it multiple times
5+
// NOTE: We attach the classifier to the global object to avoid unnecessary reloads during development
66
const classifier = (globalThis.classifier ??= await pipeline(
77
"text-classification",
88
"Xenova/distilbert-base-uncased-finetuned-sst-2-english",
99
));
1010

1111
export async function GET(request) {
12-
// https://nextjs.org/docs/app/building-your-axpplication/routing/route-handlers#url-query-parameters
13-
const searchParams = request.nextUrl.searchParams;
14-
const text = searchParams.get("text");
12+
const text = request.nextUrl.searchParams.get("text");
13+
14+
if (!text) {
15+
return Response.json({ message: "No text provided" }, { status: 400 });
16+
}
1517

1618
const result = await classifier(text);
1719
return Response.json(result[0]);

next-server/package-lock.json

Lines changed: 55 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

next-server/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
},
1111
"dependencies": {
1212
"@huggingface/transformers": "^3.0.0",
13-
"next": "15.0.0",
14-
"react": "19.0.0-rc-65a56d0e-20241020",
15-
"react-dom": "19.0.0-rc-65a56d0e-20241020"
13+
"next": "15.0.1",
14+
"react": "19.0.0-rc-69d4b800-20241021",
15+
"react-dom": "19.0.0-rc-69d4b800-20241021"
1616
},
1717
"devDependencies": {
1818
"eslint": "^9",

0 commit comments

Comments
 (0)