Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,365 Bytes
17aecfb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import { json } from '@sveltejs/kit';
import prisma from '$lib/prisma';
// import { env } from '$env/dynamic/private'
// import jsonData from "$lib/utils/loras.json";
// import type { ModelCard } from '$lib/type';
/** @type {import('./$types').RequestHandler} */
export async function POST({ request }) {
const headers = Object.fromEntries(request.headers.entries());
if (headers["x-hf-token"] !== process.env.HF_TOKEN) {
return Response.json({
message: "Wrong castle fam :^)"
}, { status: 401 });
}
const { models } = await request.json();
const cards = await Promise.all(models.map(async (model: Record<string, string>) => {
const res = await fetch(`https://huggingface.co/api/models/${model.repo}`)
const data = await res.json();
const mergedData = {
image: model.image,
repo: model.repo,
title: model.title,
likes: data.likes,
downloads: data.downloads,
}
return mergedData
}
))
for (const model of cards) {
await prisma.model.create({
data: {
repo: model.repo,
image: model.image,
title: model.title,
likes: model.likes,
downloads: model.downloads,
isPublic: true,
}
})
}
const total_items = await prisma.model.count()
return json({
message: `Successfully added ${total_items} models`,
})
}
|