File size: 515 Bytes
adf1923
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { NextRequest, NextResponse } from "next/server";
import { pipeline, env } from "@huggingface/transformers";
env.cacheDir = "./.cache";

export const POST = async (request: NextRequest) => {
    try{
        const {key, text} = await request.json();
        const qa_pipeline = await pipeline('document-question-answering', 'Xenova/donut-base-finetuned-docvqa');
        const output = await qa_pipeline(key, text);
        return NextResponse.json(output);
    }catch (e) {
        console.error(e)
    }
};