Spaces:
Paused
Paused
add route to manually update models from specific author
Browse files
src/routes/api/scrap-models/[slug]/+server.ts
CHANGED
|
@@ -19,7 +19,12 @@ export async function POST({ request, params }) {
|
|
| 19 |
const model = await response.json();
|
| 20 |
|
| 21 |
if (model?.cardData?.thumbnail) {
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
} else {
|
| 24 |
const hasImages = model?.siblings?.filter((sibling: Record<string, string>) => sibling?.rfilename.endsWith(".png") || sibling?.rfilename.endsWith(".jpeg") || sibling?.rfilename.endsWith(".jpg"))
|
| 25 |
if (hasImages.length > 0) {
|
|
@@ -77,12 +82,14 @@ export async function PATCH({ request, params } : RequestEvent) {
|
|
| 77 |
|
| 78 |
const models = await prisma.model.findMany({
|
| 79 |
where: {
|
| 80 |
-
id:
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
})
|
| 83 |
|
| 84 |
for (const model of models) {
|
| 85 |
-
const hf_model = await fetch(`https://huggingface.co/api/models/${
|
| 86 |
const new_model = await hf_model.json();
|
| 87 |
const update_data = {
|
| 88 |
instance_prompt: model.instance_prompt,
|
|
@@ -93,7 +100,12 @@ export async function PATCH({ request, params } : RequestEvent) {
|
|
| 93 |
update_data.instance_prompt = new_model?.cardData?.instance_prompt
|
| 94 |
}
|
| 95 |
if (new_model?.cardData?.thumbnail) {
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
|
| 99 |
await prisma.model.update({
|
|
|
|
| 19 |
const model = await response.json();
|
| 20 |
|
| 21 |
if (model?.cardData?.thumbnail) {
|
| 22 |
+
const filename = model?.cardData?.thumbnail?.split("/").pop()
|
| 23 |
+
const hasImage = model?.siblings?.find((sibling: Record<string, string>) => sibling?.rfilename.includes(filename))
|
| 24 |
+
|
| 25 |
+
if (hasImage?.rfilename) {
|
| 26 |
+
model.image = `https://huggingface.co/${model.id}/resolve/main/${hasImage?.rfilename}`
|
| 27 |
+
}
|
| 28 |
} else {
|
| 29 |
const hasImages = model?.siblings?.filter((sibling: Record<string, string>) => sibling?.rfilename.endsWith(".png") || sibling?.rfilename.endsWith(".jpeg") || sibling?.rfilename.endsWith(".jpg"))
|
| 30 |
if (hasImages.length > 0) {
|
|
|
|
| 82 |
|
| 83 |
const models = await prisma.model.findMany({
|
| 84 |
where: {
|
| 85 |
+
id: {
|
| 86 |
+
startsWith: slug
|
| 87 |
+
}
|
| 88 |
+
},
|
| 89 |
})
|
| 90 |
|
| 91 |
for (const model of models) {
|
| 92 |
+
const hf_model = await fetch(`https://huggingface.co/api/models/${model.id}`)
|
| 93 |
const new_model = await hf_model.json();
|
| 94 |
const update_data = {
|
| 95 |
instance_prompt: model.instance_prompt,
|
|
|
|
| 100 |
update_data.instance_prompt = new_model?.cardData?.instance_prompt
|
| 101 |
}
|
| 102 |
if (new_model?.cardData?.thumbnail) {
|
| 103 |
+
const filename = new_model?.cardData?.thumbnail?.split("/").pop()
|
| 104 |
+
const hasImage = new_model?.siblings?.find((sibling: Record<string, string>) => sibling?.rfilename.includes(filename))
|
| 105 |
+
|
| 106 |
+
if (hasImage?.rfilename) {
|
| 107 |
+
update_data.image = `https://huggingface.co/${model.id}/resolve/main/${hasImage?.rfilename}`
|
| 108 |
+
}
|
| 109 |
}
|
| 110 |
|
| 111 |
await prisma.model.update({
|