Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
change export, use siblings first
Browse files
src/lib/components/models/drawer/Drawer.svelte
CHANGED
@@ -8,11 +8,12 @@
|
|
8 |
import { modelStore } from "$lib/stores/use-model";
|
9 |
import UserIsLogged from '$lib/components/UserIsLogged.svelte';
|
10 |
import Comments from '$lib/components/models/drawer/comments/Comments.svelte';
|
11 |
-
import { env } from '$env/dynamic/public';
|
12 |
-
import { browser } from '$app/environment';
|
13 |
|
14 |
let { open, model } = get(modelStore);
|
15 |
|
|
|
|
|
|
|
16 |
modelStore.subscribe((value) => {
|
17 |
open = value?.open;
|
18 |
model = value?.model;
|
@@ -42,6 +43,11 @@
|
|
42 |
handleClose();
|
43 |
}
|
44 |
};
|
|
|
|
|
|
|
|
|
|
|
45 |
</script>
|
46 |
|
47 |
<div
|
@@ -60,8 +66,8 @@
|
|
60 |
<div class="flex items-center justify-start gap-3 lg:gap-6">
|
61 |
<img src={model?.image} class="lg:w-16 lg:h-16 w-12 h-12 rounded-xl bg-neutral-800 object-cover" alt={model?.id} />
|
62 |
<div>
|
63 |
-
<p class="text-
|
64 |
-
{
|
65 |
</p>
|
66 |
<a href="https://huggingface.co/{model?.id}" target="_blank" class="text-neutral-400 underline hover:text-neutral-300 flex items-center justify-start gap-1">
|
67 |
<Icon icon="iconamoon:link-external-fill" class="w-4 h-4" />
|
|
|
8 |
import { modelStore } from "$lib/stores/use-model";
|
9 |
import UserIsLogged from '$lib/components/UserIsLogged.svelte';
|
10 |
import Comments from '$lib/components/models/drawer/comments/Comments.svelte';
|
|
|
|
|
11 |
|
12 |
let { open, model } = get(modelStore);
|
13 |
|
14 |
+
let author = model?.id.split('/')[0];
|
15 |
+
let repo = model?.id.split('/')[1];
|
16 |
+
|
17 |
modelStore.subscribe((value) => {
|
18 |
open = value?.open;
|
19 |
model = value?.model;
|
|
|
43 |
handleClose();
|
44 |
}
|
45 |
};
|
46 |
+
const handleClickAuthor = () => {
|
47 |
+
$page.url.searchParams.set('search', author as string);
|
48 |
+
goto(`?${$page.url.searchParams.toString()}`);
|
49 |
+
handleClose()
|
50 |
+
}
|
51 |
</script>
|
52 |
|
53 |
<div
|
|
|
66 |
<div class="flex items-center justify-start gap-3 lg:gap-6">
|
67 |
<img src={model?.image} class="lg:w-16 lg:h-16 w-12 h-12 rounded-xl bg-neutral-800 object-cover" alt={model?.id} />
|
68 |
<div>
|
69 |
+
<p class="text-neutral-300 font-semibold text-lg lg:text-2xl mb-1 truncate">
|
70 |
+
<button class="underline text-white" on:click={handleClickAuthor}>{author}</button>/{repo}
|
71 |
</p>
|
72 |
<a href="https://huggingface.co/{model?.id}" target="_blank" class="text-neutral-400 underline hover:text-neutral-300 flex items-center justify-start gap-1">
|
73 |
<Icon icon="iconamoon:link-external-fill" class="w-4 h-4" />
|
src/routes/+page.svelte
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
<script lang="ts">
|
2 |
import { browser } from "$app/environment";
|
3 |
import InfiniteScroll from "svelte-infinite-scroll";
|
4 |
-
|
5 |
import Button from "$lib/components/Button.svelte";
|
6 |
import Card from "$lib/components/models/Card.svelte";
|
7 |
import Input from "$lib/components/fields/Input.svelte";
|
@@ -11,13 +10,15 @@
|
|
11 |
import Dialog from "$lib/components/dialog/Dialog.svelte";
|
12 |
import SubmitModel from "$lib/components/models/Submit.svelte";
|
13 |
import Drawer from "$lib/components/models/drawer/Drawer.svelte";
|
|
|
|
|
14 |
// import UserIsLogged from "$lib/components/UserIsLogged.svelte";
|
15 |
|
16 |
export let data
|
17 |
|
18 |
let form = {
|
19 |
-
filter:
|
20 |
-
search:
|
21 |
page: "0",
|
22 |
}
|
23 |
let submitModelDialog = false;
|
@@ -30,15 +31,20 @@
|
|
30 |
}
|
31 |
const handleChangeFilter = async (filter: string) => {
|
32 |
form = { ...form, filter, page: (0).toString()};
|
33 |
-
|
|
|
34 |
}
|
35 |
let timeout: any;
|
36 |
const handleChangeSearch = async (search: string) => {
|
37 |
clearTimeout(timeout);
|
38 |
form = { ...form, search, page: (0).toString()};
|
39 |
-
timeout = setTimeout(() =>
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
-
|
42 |
const refetch = async (add: boolean) => {
|
43 |
const request = await fetch(`/api/models?${new URLSearchParams(form)}`);
|
44 |
const response = await request.json();
|
|
|
1 |
<script lang="ts">
|
2 |
import { browser } from "$app/environment";
|
3 |
import InfiniteScroll from "svelte-infinite-scroll";
|
|
|
4 |
import Button from "$lib/components/Button.svelte";
|
5 |
import Card from "$lib/components/models/Card.svelte";
|
6 |
import Input from "$lib/components/fields/Input.svelte";
|
|
|
10 |
import Dialog from "$lib/components/dialog/Dialog.svelte";
|
11 |
import SubmitModel from "$lib/components/models/Submit.svelte";
|
12 |
import Drawer from "$lib/components/models/drawer/Drawer.svelte";
|
13 |
+
import { page } from "$app/stores";
|
14 |
+
import { goto } from "$app/navigation";
|
15 |
// import UserIsLogged from "$lib/components/UserIsLogged.svelte";
|
16 |
|
17 |
export let data
|
18 |
|
19 |
let form = {
|
20 |
+
filter: data?.filter,
|
21 |
+
search: data?.search,
|
22 |
page: "0",
|
23 |
}
|
24 |
let submitModelDialog = false;
|
|
|
31 |
}
|
32 |
const handleChangeFilter = async (filter: string) => {
|
33 |
form = { ...form, filter, page: (0).toString()};
|
34 |
+
$page.url.searchParams.set('filter', filter);
|
35 |
+
goto(`?${$page.url.searchParams.toString()}`);
|
36 |
}
|
37 |
let timeout: any;
|
38 |
const handleChangeSearch = async (search: string) => {
|
39 |
clearTimeout(timeout);
|
40 |
form = { ...form, search, page: (0).toString()};
|
41 |
+
timeout = setTimeout(() => {
|
42 |
+
if (search === "") $page.url.searchParams.delete('search');
|
43 |
+
else $page.url.searchParams.set('search', search);
|
44 |
+
goto(`?${$page.url.searchParams.toString()}`);
|
45 |
+
}, 500);
|
46 |
}
|
47 |
+
|
48 |
const refetch = async (add: boolean) => {
|
49 |
const request = await fetch(`/api/models?${new URLSearchParams(form)}`);
|
50 |
const response = await request.json();
|
src/routes/+page.ts
CHANGED
@@ -2,6 +2,8 @@ import { modelStore } from "$lib/stores/use-model";
|
|
2 |
|
3 |
export async function load({ fetch, url }) {
|
4 |
const model_param = url.searchParams.get("model")
|
|
|
|
|
5 |
|
6 |
if (model_param) {
|
7 |
const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
|
@@ -17,7 +19,13 @@ export async function load({ fetch, url }) {
|
|
17 |
});
|
18 |
}
|
19 |
|
20 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
method: "GET",
|
22 |
headers: {
|
23 |
"Content-Type": "application/json"
|
@@ -27,6 +35,8 @@ export async function load({ fetch, url }) {
|
|
27 |
return {
|
28 |
models: models?.cards ?? [],
|
29 |
total_items: models?.total_items ?? 0,
|
|
|
|
|
30 |
// model: model?.model ?? null
|
31 |
}
|
32 |
}
|
|
|
2 |
|
3 |
export async function load({ fetch, url }) {
|
4 |
const model_param = url.searchParams.get("model")
|
5 |
+
const search_param = url.searchParams.get("search") ?? ""
|
6 |
+
const filter_param = url.searchParams.get("filter") ?? "hotest"
|
7 |
|
8 |
if (model_param) {
|
9 |
const model_request = await fetch(`/api/models/${model_param?.replace("/", "@")}?full=true`, {
|
|
|
19 |
});
|
20 |
}
|
21 |
|
22 |
+
const data = {
|
23 |
+
filter: filter_param,
|
24 |
+
page: "0",
|
25 |
+
search: search_param ?? ""
|
26 |
+
}
|
27 |
+
|
28 |
+
const response = await fetch(`/api/models?${new URLSearchParams(data)}`, {
|
29 |
method: "GET",
|
30 |
headers: {
|
31 |
"Content-Type": "application/json"
|
|
|
35 |
return {
|
36 |
models: models?.cards ?? [],
|
37 |
total_items: models?.total_items ?? 0,
|
38 |
+
search: search_param ?? "",
|
39 |
+
filter: filter_param,
|
40 |
// model: model?.model ?? null
|
41 |
}
|
42 |
}
|
src/routes/api/scrap-models/+server.ts
CHANGED
@@ -20,25 +20,30 @@ export async function POST({ request }) {
|
|
20 |
let index = 0;
|
21 |
for (const model of responseData) {
|
22 |
if (index % 50 === 0) {
|
23 |
-
await new Promise(resolve => setTimeout(resolve,
|
24 |
}
|
25 |
|
26 |
-
const
|
27 |
-
if (
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
-
const imageRegex = /!\[.*\]\((.*)\)/
|
34 |
-
let image = readme.match(imageRegex)?.[1]
|
35 |
-
|
36 |
-
if (!image) {
|
37 |
-
continue
|
38 |
-
}
|
39 |
-
image = image.replace(///g, "/")
|
40 |
-
if (image.startsWith("http")) model.image = image
|
41 |
-
else model.image = `https://huggingface.co/${model.id}/resolve/main/${image.replace("./", "")}`
|
42 |
}
|
43 |
|
44 |
await prisma.model.create({
|
|
|
20 |
let index = 0;
|
21 |
for (const model of responseData) {
|
22 |
if (index % 50 === 0) {
|
23 |
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
24 |
}
|
25 |
|
26 |
+
const hasImages = model?.siblings?.filter((sibling: Record<string, string>) => sibling?.rfilename.endsWith(".png") || sibling?.rfilename.endsWith(".jpeg") || sibling?.rfilename.endsWith(".jpg"))
|
27 |
+
if (hasImages.length > 0) {
|
28 |
+
model.image = hasImages[1]?.rfilename ? `https://huggingface.co/${model.id}/resolve/main/${hasImages[1]?.rfilename}` : `https://huggingface.co/${model.id}/resolve/main/${hasImages[0]?.rfilename}`
|
29 |
+
} else {
|
30 |
+
const hasReadme = model?.siblings?.find((sibling: Record<string, string>) => sibling?.rfilename === "README.md")
|
31 |
+
if (hasReadme) {
|
32 |
+
const readmeRes = await fetch(`https://huggingface.co/${model.id}/raw/main/README.md`)
|
33 |
+
const readme = await readmeRes.text().catch(() => null)
|
34 |
+
if (!readme) {
|
35 |
+
continue
|
36 |
+
}
|
37 |
+
const imageRegex = /!\[.*\]\((.*)\)/
|
38 |
+
let image = readme.match(imageRegex)?.[1]
|
39 |
+
|
40 |
+
if (!image) {
|
41 |
+
continue
|
42 |
+
}
|
43 |
+
image = image.replace(///g, "/")
|
44 |
+
if (image.startsWith("http")) model.image = image
|
45 |
+
else model.image = `https://huggingface.co/${model.id}/resolve/main/${image.replace("./", "")}`
|
46 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
}
|
48 |
|
49 |
await prisma.model.create({
|
src/routes/api/scrap-models/[slug]/+server.ts
CHANGED
@@ -18,7 +18,11 @@ export async function POST({ request, params }) {
|
|
18 |
const response = await fetch(`https://huggingface.co/api/models/${slug}`)
|
19 |
const model = await response.json();
|
20 |
|
21 |
-
const
|
|
|
|
|
|
|
|
|
22 |
if (hasReadme) {
|
23 |
const readmeRes = await fetch(`https://huggingface.co/${model.id}/raw/main/README.md`)
|
24 |
const readme = await readmeRes.text().catch(() => null)
|
@@ -29,27 +33,28 @@ export async function POST({ request, params }) {
|
|
29 |
}
|
30 |
const imageRegex = /!\[.*\]\((.*)\)/
|
31 |
let image = readme.match(imageRegex)?.[1]
|
32 |
-
|
33 |
if (!image) {
|
34 |
return json({
|
35 |
-
message: "No
|
36 |
}, { status: 404 })
|
37 |
}
|
38 |
image = image.replace(///g, "/")
|
39 |
if (image.startsWith("http")) model.image = image
|
40 |
else model.image = `https://huggingface.co/${model.id}/resolve/main/${image.replace("./", "")}`
|
41 |
}
|
|
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
return json({
|
55 |
message: `Successfully added the model ${model.id}`,
|
|
|
18 |
const response = await fetch(`https://huggingface.co/api/models/${slug}`)
|
19 |
const model = await response.json();
|
20 |
|
21 |
+
const hasImages = model?.siblings?.filter((sibling: Record<string, string>) => sibling?.rfilename.endsWith(".png") || sibling?.rfilename.endsWith(".jpeg") || sibling?.rfilename.endsWith(".jpg"))
|
22 |
+
if (hasImages.length > 0) {
|
23 |
+
model.image = hasImages[1]?.rfilename ? `https://huggingface.co/${model.id}/resolve/main/${hasImages[1]?.rfilename}` : `https://huggingface.co/${model.id}/resolve/main/${hasImages[0]?.rfilename}`
|
24 |
+
} else {
|
25 |
+
const hasReadme = model?.siblings?.find((sibling: Record<string, string>) => sibling?.rfilename === "README.md")
|
26 |
if (hasReadme) {
|
27 |
const readmeRes = await fetch(`https://huggingface.co/${model.id}/raw/main/README.md`)
|
28 |
const readme = await readmeRes.text().catch(() => null)
|
|
|
33 |
}
|
34 |
const imageRegex = /!\[.*\]\((.*)\)/
|
35 |
let image = readme.match(imageRegex)?.[1]
|
36 |
+
|
37 |
if (!image) {
|
38 |
return json({
|
39 |
+
message: "No image found"
|
40 |
}, { status: 404 })
|
41 |
}
|
42 |
image = image.replace(///g, "/")
|
43 |
if (image.startsWith("http")) model.image = image
|
44 |
else model.image = `https://huggingface.co/${model.id}/resolve/main/${image.replace("./", "")}`
|
45 |
}
|
46 |
+
}
|
47 |
|
48 |
+
await prisma.model.create({
|
49 |
+
data: {
|
50 |
+
id: model.id,
|
51 |
+
image: model.image,
|
52 |
+
likes: model.likes,
|
53 |
+
downloads: model.downloads,
|
54 |
+
isPublic: true,
|
55 |
+
instance_prompt: model?.cardData?.instance_prompt,
|
56 |
+
}
|
57 |
+
}).catch(() => {})
|
58 |
|
59 |
return json({
|
60 |
message: `Successfully added the model ${model.id}`,
|