Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

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

| Name | Description | Links |
| ------------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------ |
| [Phi-3.5 WebGPU](./phi-3.5-webgpu/) | Conversational large language model | [Demo](https://huggingface.co/spaces/webml-community/phi-3.5-webgpu) |
| [Llama-3.2 WebGPU](./llama-3.2-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/llama-3.2-webgpu) |
| [SmolLM WebGPU](./smollm-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/smollm-webgpu) |
| [Segment Anything WebGPU](./segment-anything-webgpu/) | WebGPU image segmentation | [Demo](https://huggingface.co/spaces/webml-community/segment-anything-webgpu) |
| [Remove Background WebGPU](./remove-background-webgpu/) | WebGPU image background removal | [Demo](https://huggingface.co/spaces/webml-community/remove-background-webgpu) |
| [PGlite Semantic Search](./pglite-semantic-search/) | Semantic search | [Demo](https://huggingface.co/spaces/thorwebdev/pglite-semantic-search) |
| [Sapiens](./sapiens-node/) | Image segmentation, depth, and normal estimation in Node.js | n/a |
| [Bun](./bun/) | Compute text embeddings in [Bun](https://bun.sh/) | n/a |
| [Deno](./deno-embed/) | Compute text embeddings in [Deno](https://deno.com/) | n/a |
| [Node.js (ESM)](./node-esm/) | Sentiment analysis in Node.js w/ ECMAScript modules | n/a |
| [Node.js (CJS)](./node-cjs/) | Sentiment analysis in Node.js w/ CommonJS | n/a |
| [Next.js](./next-server/) | Sentiment analysis in Next.js | [Demo](https://huggingface.co/spaces/webml-community/next-server-template) |
| Name | Description | Links |
| ------------------------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------------------------- |
| [Phi-3.5 WebGPU](./phi-3.5-webgpu/) | Conversational large language model | [Demo](https://huggingface.co/spaces/webml-community/phi-3.5-webgpu) |
| [Llama-3.2 WebGPU](./llama-3.2-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/llama-3.2-webgpu) |
| [SmolLM WebGPU](./smollm-webgpu/) | Conversational small language model | [Demo](https://huggingface.co/spaces/webml-community/smollm-webgpu) |
| [Segment Anything WebGPU](./segment-anything-webgpu/) | WebGPU image segmentation | [Demo](https://huggingface.co/spaces/webml-community/segment-anything-webgpu) |
| [Remove Background WebGPU](./remove-background-webgpu/) | WebGPU image background removal | [Demo](https://huggingface.co/spaces/webml-community/remove-background-webgpu) |
| [PGlite Semantic Search](./pglite-semantic-search/) | Semantic search | [Demo](https://huggingface.co/spaces/thorwebdev/pglite-semantic-search) |
| [Sapiens](./sapiens-node/) | Image segmentation, depth, and normal estimation in Node.js | n/a |
| [Bun](./bun/) | Compute text embeddings in [Bun](https://bun.sh/) | n/a |
| [Deno](./deno-embed/) | Compute text embeddings in [Deno](https://deno.com/) | n/a |
| [Node.js (ESM)](./node-esm/) | Sentiment analysis in Node.js w/ ECMAScript modules | n/a |
| [Node.js (CJS)](./node-cjs/) | Sentiment analysis in Node.js w/ CommonJS | n/a |
| [Next.js](./next-server/) | Sentiment analysis in Next.js | [Demo](https://huggingface.co/spaces/webml-community/next-server-template) |
| [SvelteKit](./sveltekit/) | Sentiment analysis in SvelteKit | [Demo](https://huggingface.co/spaces/webml-community/sveltekit-server-template) |

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!
2 changes: 1 addition & 1 deletion next-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ app_port: 3000

# next-server

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).
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).

## Instructions

Expand Down
10 changes: 6 additions & 4 deletions next-server/app/api/classify/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@

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

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

export async function GET(request) {
// https://nextjs.org/docs/app/building-your-axpplication/routing/route-handlers#url-query-parameters
const searchParams = request.nextUrl.searchParams;
const text = searchParams.get("text");
const text = request.nextUrl.searchParams.get("text");

if (!text) {
return Response.json({ message: "No text provided" }, { status: 400 });
}

const result = await classifier(text);
return Response.json(result[0]);
Expand Down
110 changes: 55 additions & 55 deletions next-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions next-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
},
"dependencies": {
"@huggingface/transformers": "^3.0.0",
"next": "15.0.0",
"react": "19.0.0-rc-65a56d0e-20241020",
"react-dom": "19.0.0-rc-65a56d0e-20241020"
"next": "15.0.1",
"react": "19.0.0-rc-69d4b800-20241021",
"react-dom": "19.0.0-rc-69d4b800-20241021"
},
"devDependencies": {
"eslint": "^9",
Expand Down
Loading