Spaces:
Runtime error
Runtime error
Download app/api/classify/route.js from Topcoder-Platform/space-demo-template: direct link, hf CLI and curl.
- Browser
- Download file 660 Bytes
-
https://huggingface.co/spaces/Topcoder-Platform/space-demo-template/resolve/main/app/api/classify/route.js
- Command line
-
hf download hf://spaces/Topcoder-Platform/space-demo-template/app/api/classify/route.js
-
curl -L -o route.js https://huggingface.co/spaces/Topcoder-Platform/space-demo-template/resolve/main/app/api/classify/route.js
660 Bytes
| // https://nextjs.org/docs/app/building-your-application/routing/route-handlers | |
| import { pipeline } from "@huggingface/transformers"; | |
| // 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) { | |
| 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]); | |
| } | |