Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,990 Bytes
1c0590e 727ce74 1c0590e d6da254 1c0590e d6da254 db78a09 d6da254 db78a09 d6da254 db78a09 1c0590e 727ce74 d6da254 1c0590e 727ce74 1c0590e |
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
import { json, type RequestEvent } from '@sveltejs/kit';
import { env } from '$env/dynamic/private'
import prisma from '$lib/prisma';
/** @type {import('./$types').RequestHandler} */
export async function GET({ url, params } : RequestEvent) {
const id = params.id?.replace("@", "/")
// to Booelan
const full = Boolean(url.searchParams.get('full')) ?? false
const model = await prisma.model.findFirst({
where: {
id,
},
select: full ? {
id: true,
likes: true,
downloads: true,
image: true,
title: true,
instance_prompt: true,
gallery: {
select: {
id: true,
prompt: true,
image: true,
createdAt: true,
},
where: {
isPublic: true
},
orderBy: {
createdAt: 'desc'
},
take: 10
},
comments: {
select: {
id: true,
createdAt: true,
text: true,
user: {
select: {
id: true,
name: true,
sub: true,
picture: true,
preferred_username: true,
}
}
}
}
} : {
instance_prompt: true,
image: true,
title: true,
id: true,
}
})
if (!model) {
return json({
error: {
token: "Model params is required"
}
}, { status: 401 })
}
let infos: Record<string, string | string[]> = {};
if (full) {
const hf_model_request = await fetch(`https://huggingface.co/api/models/${id}`, {
headers: {
"Authorization": `Bearer ${env.SECRET_HF_TOKEN}`
}
})
const hf_model_response = await hf_model_request.json();
infos = {
base_model: hf_model_response?.cardData?.base_model,
license: hf_model_response?.cardData?.license,
tags: hf_model_response?.cardData?.tags,
}
}
return json({
model: {
...model,
infos
}
})
}
|