Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
trending sort
Browse files- prisma/schema.prisma +1 -0
- server.js +4 -3
- src/lib/utils/index.ts +7 -7
- src/routes/api/models/+server.ts +20 -15
prisma/schema.prisma
CHANGED
@@ -18,6 +18,7 @@ model Model {
|
|
18 |
downloads Int?
|
19 |
instance_prompt String?
|
20 |
isPublic Boolean @default(false)
|
|
|
21 |
user User? @relation(fields: [userId], references: [sub])
|
22 |
userId String?
|
23 |
gallery Gallery[]
|
|
|
18 |
downloads Int?
|
19 |
instance_prompt String?
|
20 |
isPublic Boolean @default(false)
|
21 |
+
likes7d Int? @default(0)
|
22 |
user User? @relation(fields: [userId], references: [sub])
|
23 |
userId String?
|
24 |
gallery Gallery[]
|
server.js
CHANGED
@@ -19,7 +19,7 @@ app.listen(3000, () => {
|
|
19 |
});
|
20 |
|
21 |
cron.schedule("0 * * * *", async () => {
|
22 |
-
console.log('Scraping models'
|
23 |
const request = await fetch(`https://${process.env.SPACE_HOST}/api/scrap-models`, {
|
24 |
method: 'POST',
|
25 |
headers: {
|
@@ -31,8 +31,9 @@ cron.schedule("0 * * * *", async () => {
|
|
31 |
console.info(response?.message)
|
32 |
});
|
33 |
|
34 |
-
cron.schedule("0 0
|
35 |
-
|
|
|
36 |
method: 'PATCH',
|
37 |
headers: {
|
38 |
'Content-Type': 'application/json',
|
|
|
19 |
});
|
20 |
|
21 |
cron.schedule("0 * * * *", async () => {
|
22 |
+
console.log('Scraping models')
|
23 |
const request = await fetch(`https://${process.env.SPACE_HOST}/api/scrap-models`, {
|
24 |
method: 'POST',
|
25 |
headers: {
|
|
|
31 |
console.info(response?.message)
|
32 |
});
|
33 |
|
34 |
+
cron.schedule("0 0 */12 * *", async () => {
|
35 |
+
console.log('Updating models')
|
36 |
+
const request = await fetch(`http://${process.env.SPACE_HOST}/api/models`, {
|
37 |
method: 'PATCH',
|
38 |
headers: {
|
39 |
'Content-Type': 'application/json',
|
src/lib/utils/index.ts
CHANGED
@@ -16,12 +16,6 @@ export const COMMUNITY_FILTER_OPTIONS = [
|
|
16 |
];
|
17 |
|
18 |
export const MODELS_FILTER_OPTIONS = [
|
19 |
-
{
|
20 |
-
label: "Most Liked",
|
21 |
-
value: "likes",
|
22 |
-
icon: "lucide:heart",
|
23 |
-
iconColor: "text-red-500"
|
24 |
-
},
|
25 |
{
|
26 |
label: "Hotest",
|
27 |
value: "hotest",
|
@@ -33,7 +27,13 @@ export const MODELS_FILTER_OPTIONS = [
|
|
33 |
value: "newest",
|
34 |
icon: "ph:clock-bold",
|
35 |
iconColor: "text-blue-500"
|
36 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
];
|
38 |
|
39 |
export const SIDEBAR_MENUS = [ {
|
|
|
16 |
];
|
17 |
|
18 |
export const MODELS_FILTER_OPTIONS = [
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
{
|
20 |
label: "Hotest",
|
21 |
value: "hotest",
|
|
|
27 |
value: "newest",
|
28 |
icon: "ph:clock-bold",
|
29 |
iconColor: "text-blue-500"
|
30 |
+
},
|
31 |
+
{
|
32 |
+
label: "Most Liked",
|
33 |
+
value: "likes",
|
34 |
+
icon: "lucide:heart",
|
35 |
+
iconColor: "text-red-500"
|
36 |
+
},
|
37 |
];
|
38 |
|
39 |
export const SIDEBAR_MENUS = [ {
|
src/routes/api/models/+server.ts
CHANGED
@@ -21,6 +21,15 @@ export async function GET(request : RequestEvent) {
|
|
21 |
const search = request.url.searchParams.get('search') || ''
|
22 |
const limit = parseInt(request.url.searchParams.get('limit') || '20')
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
const cards = await prisma.model.findMany({
|
25 |
where: {
|
26 |
...(IS_ADMIN ? {} : { isPublic: true }),
|
@@ -28,9 +37,7 @@ export async function GET(request : RequestEvent) {
|
|
28 |
{ id: { contains: search } },
|
29 |
]
|
30 |
},
|
31 |
-
orderBy:
|
32 |
-
...(filter === 'hotest' ? { downloads: 'desc' } : filter === 'likes' ? { likes: 'desc' } : { createdAt: 'desc' })
|
33 |
-
},
|
34 |
skip: page * limit,
|
35 |
take: limit,
|
36 |
})
|
@@ -59,28 +66,26 @@ export async function PATCH({ request } : RequestEvent) {
|
|
59 |
}, { status: 401 });
|
60 |
}
|
61 |
|
62 |
-
const
|
63 |
-
|
64 |
-
isPublic: true,
|
65 |
-
}
|
66 |
-
})
|
67 |
|
68 |
let total_updates = 0;
|
69 |
|
70 |
-
for (const model of
|
71 |
-
const response = await fetch(`https://huggingface.co/api/models/${model.id}`)
|
72 |
-
const hf_model = await response.json();
|
73 |
-
|
74 |
await prisma.model.update({
|
75 |
where: {
|
76 |
id: model.id
|
77 |
},
|
78 |
data: {
|
79 |
-
likes:
|
80 |
-
downloads:
|
|
|
81 |
}
|
82 |
})
|
83 |
-
|
|
|
|
|
|
|
84 |
}
|
85 |
|
86 |
return json({
|
|
|
21 |
const search = request.url.searchParams.get('search') || ''
|
22 |
const limit = parseInt(request.url.searchParams.get('limit') || '20')
|
23 |
|
24 |
+
const orderBy: Record<string, string> = {}
|
25 |
+
if (filter === 'hotest') {
|
26 |
+
orderBy['likes7d'] = 'desc'
|
27 |
+
} else if (filter === 'likes') {
|
28 |
+
orderBy['likes'] = 'desc'
|
29 |
+
} else {
|
30 |
+
orderBy['createdAt'] = 'desc'
|
31 |
+
}
|
32 |
+
|
33 |
const cards = await prisma.model.findMany({
|
34 |
where: {
|
35 |
...(IS_ADMIN ? {} : { isPublic: true }),
|
|
|
37 |
{ id: { contains: search } },
|
38 |
]
|
39 |
},
|
40 |
+
orderBy: orderBy,
|
|
|
|
|
41 |
skip: page * limit,
|
42 |
take: limit,
|
43 |
})
|
|
|
66 |
}, { status: 401 });
|
67 |
}
|
68 |
|
69 |
+
const hf_request = await fetch(`https://huggingface.co/api/models?limit=10000&filter=lora%2Cdiffusers&sort=likes7d`)
|
70 |
+
const hf_models = await hf_request.json();
|
|
|
|
|
|
|
71 |
|
72 |
let total_updates = 0;
|
73 |
|
74 |
+
for (const model of hf_models) {
|
|
|
|
|
|
|
75 |
await prisma.model.update({
|
76 |
where: {
|
77 |
id: model.id
|
78 |
},
|
79 |
data: {
|
80 |
+
likes: model.likes,
|
81 |
+
downloads: model.downloads,
|
82 |
+
likes7d: model.likes7d,
|
83 |
}
|
84 |
})
|
85 |
+
.then(() => {
|
86 |
+
total_updates++
|
87 |
+
})
|
88 |
+
.catch(() => {})
|
89 |
}
|
90 |
|
91 |
return json({
|