File size: 575 Bytes
7a52bc5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { json } from '@sveltejs/kit';
import PipelineSingleton from '$lib/server/pipeline.js';

export async function GET({ url }) {
	const text = url.searchParams.get('text');
	if (!text) {
		return json(
			{
				error: 'Missing text parameter'
			},
			{ status: 400 }
		);
	}
	// Get the classification pipeline. When called for the first time,
	// this will load the pipeline and cache it for future use.
	const classifier = await PipelineSingleton.getInstance();

	// Actually perform the classification
	const result = await classifier(text);

	return json(result);
}