Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
my generations page added
Browse files- src/lib/components/generate/Response.svelte +1 -1
- src/lib/components/sidebar/Sidebar.svelte +6 -2
- src/lib/utils/index.ts +1 -1
- src/routes/+page.svelte +1 -1
- src/routes/api/@me/generations/+server.ts +53 -0
- src/routes/api/generate/share/+server.ts +11 -1
- src/routes/gallery/+page.svelte +1 -0
- src/routes/saved-generations/+page.svelte +27 -0
- src/routes/saved-generations/+page.ts +10 -0
src/lib/components/generate/Response.svelte
CHANGED
@@ -69,7 +69,7 @@
|
|
69 |
|
70 |
</script>
|
71 |
|
72 |
-
<div class=" w-full border-t xl:border-t-0 xl:border-l border-neutral-800 h-full col-span-5 xl:col-span-2" class:!border-black={!generation?.image || loading_generation}
|
73 |
{#if loading_generation}
|
74 |
<div class="w-full h-full flex items-center justify-center flex-col gap-3 bg-neutral-950 relative">
|
75 |
<p class="text-neutral-100 text-xl font-semibold">
|
|
|
69 |
|
70 |
</script>
|
71 |
|
72 |
+
<div class=" w-full border-t xl:border-t-0 xl:border-l border-neutral-800 h-full col-span-5 xl:col-span-2" class:!border-black={!generation?.image || loading_generation}>
|
73 |
{#if loading_generation}
|
74 |
<div class="w-full h-full flex items-center justify-center flex-col gap-3 bg-neutral-950 relative">
|
75 |
<p class="text-neutral-100 text-xl font-semibold">
|
src/lib/components/sidebar/Sidebar.svelte
CHANGED
@@ -5,7 +5,6 @@
|
|
5 |
|
6 |
import { userStore, openWindowLogin } from "$lib/stores/use-user";
|
7 |
import { SIDEBAR_MENUS } from "$lib/utils";
|
8 |
-
import HFLogo from "$lib/assets/hf-logo.svg";
|
9 |
|
10 |
import Menu from "./Menu.svelte";
|
11 |
|
@@ -41,8 +40,13 @@
|
|
41 |
<Icon icon={menu.icon} class="w-5 h-5" />
|
42 |
{menu.label}
|
43 |
</Menu>
|
44 |
-
|
45 |
{/each}
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
</ul>
|
47 |
<hr class="border-neutral-800/50 mt-10 mx-4">
|
48 |
<Menu href="https://huggingface.co/spaces/enzostvs/loras-studio/discussions/1">
|
|
|
5 |
|
6 |
import { userStore, openWindowLogin } from "$lib/stores/use-user";
|
7 |
import { SIDEBAR_MENUS } from "$lib/utils";
|
|
|
8 |
|
9 |
import Menu from "./Menu.svelte";
|
10 |
|
|
|
40 |
<Icon icon={menu.icon} class="w-5 h-5" />
|
41 |
{menu.label}
|
42 |
</Menu>
|
|
|
43 |
{/each}
|
44 |
+
{#if user?.sub}
|
45 |
+
<Menu href="/saved-generations">
|
46 |
+
<Icon icon="mdi:heart" class="w-5 h-5" />
|
47 |
+
Saved generations
|
48 |
+
</Menu>
|
49 |
+
{/if}
|
50 |
</ul>
|
51 |
<hr class="border-neutral-800/50 mt-10 mx-4">
|
52 |
<Menu href="https://huggingface.co/spaces/enzostvs/loras-studio/discussions/1">
|
src/lib/utils/index.ts
CHANGED
@@ -12,7 +12,7 @@ export const COMMUNITY_FILTER_OPTIONS = [
|
|
12 |
value: "new",
|
13 |
icon: "lucide:zap",
|
14 |
iconColor: "text-yellow-500"
|
15 |
-
}
|
16 |
];
|
17 |
|
18 |
export const MODELS_FILTER_OPTIONS = [
|
|
|
12 |
value: "new",
|
13 |
icon: "lucide:zap",
|
14 |
iconColor: "text-yellow-500"
|
15 |
+
}
|
16 |
];
|
17 |
|
18 |
export const MODELS_FILTER_OPTIONS = [
|
src/routes/+page.svelte
CHANGED
@@ -91,7 +91,7 @@
|
|
91 |
<div class="mt-5 max-w-sm">
|
92 |
<Input value={form.search} placeholder="Search a model" onChange={handleChangeSearch} />
|
93 |
</div>
|
94 |
-
<div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3
|
95 |
{#each data.cards as card}
|
96 |
<Card card={card} />
|
97 |
{/each}
|
|
|
91 |
<div class="mt-5 max-w-sm">
|
92 |
<Input value={form.search} placeholder="Search a model" onChange={handleChangeSearch} />
|
93 |
</div>
|
94 |
+
<div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
|
95 |
{#each data.cards as card}
|
96 |
<Card card={card} />
|
97 |
{/each}
|
src/routes/api/@me/generations/+server.ts
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { json, type RequestEvent } from '@sveltejs/kit';
|
2 |
+
import prisma from '$lib/prisma';
|
3 |
+
|
4 |
+
import { tokenIsAvailable } from '$lib/utils';
|
5 |
+
|
6 |
+
/** @type {import('./$types').RequestHandler} */
|
7 |
+
|
8 |
+
export async function GET({ cookies } : RequestEvent) {
|
9 |
+
const token = cookies.get('hf_access_token')
|
10 |
+
if (!token) {
|
11 |
+
return json({
|
12 |
+
error: {
|
13 |
+
token: "You must be logged"
|
14 |
+
}
|
15 |
+
}, { status: 401 })
|
16 |
+
}
|
17 |
+
|
18 |
+
const user = await tokenIsAvailable(token)
|
19 |
+
if (!user) {
|
20 |
+
return json({
|
21 |
+
error: {
|
22 |
+
token: "Invalid token"
|
23 |
+
}
|
24 |
+
}, { status: 401 })
|
25 |
+
}
|
26 |
+
|
27 |
+
const cards = await prisma.gallery.findMany({
|
28 |
+
where: {
|
29 |
+
hf_user_id: user.sub
|
30 |
+
},
|
31 |
+
orderBy: {
|
32 |
+
createdAt: 'desc'
|
33 |
+
},
|
34 |
+
select: {
|
35 |
+
reactions: true,
|
36 |
+
id: true,
|
37 |
+
prompt: true,
|
38 |
+
image: true,
|
39 |
+
model: true,
|
40 |
+
},
|
41 |
+
})
|
42 |
+
|
43 |
+
const total_reposId = await prisma.gallery.count({
|
44 |
+
where: {
|
45 |
+
hf_user_id: user.sub
|
46 |
+
},
|
47 |
+
})
|
48 |
+
|
49 |
+
return json({
|
50 |
+
cards,
|
51 |
+
total_items: total_reposId
|
52 |
+
})
|
53 |
+
}
|
src/routes/api/generate/share/+server.ts
CHANGED
@@ -4,9 +4,18 @@ import { UploaderDataset } from '$lib/utils/uploader';
|
|
4 |
import { json, type RequestEvent } from '@sveltejs/kit';
|
5 |
|
6 |
import prisma from '$lib/prisma';
|
|
|
7 |
|
8 |
-
export async function POST({ request } : RequestEvent) {
|
9 |
const { generation, image } = await request.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
if (!generation?.model?.id) {
|
12 |
return json({
|
@@ -50,6 +59,7 @@ export async function POST({ request } : RequestEvent) {
|
|
50 |
data: {
|
51 |
image: success.path as string,
|
52 |
prompt: generation.inputs,
|
|
|
53 |
model: {
|
54 |
connect: {
|
55 |
id: generation.model.id
|
|
|
4 |
import { json, type RequestEvent } from '@sveltejs/kit';
|
5 |
|
6 |
import prisma from '$lib/prisma';
|
7 |
+
import { tokenIsAvailable } from '$lib/utils';
|
8 |
|
9 |
+
export async function POST({ request, cookies } : RequestEvent) {
|
10 |
const { generation, image } = await request.json()
|
11 |
+
const token = cookies.get('hf_access_token')
|
12 |
+
|
13 |
+
let hf_user_id = null;
|
14 |
+
|
15 |
+
if (token) {
|
16 |
+
const user = await tokenIsAvailable(token)
|
17 |
+
if (user) hf_user_id = user?.sub;
|
18 |
+
}
|
19 |
|
20 |
if (!generation?.model?.id) {
|
21 |
return json({
|
|
|
59 |
data: {
|
60 |
image: success.path as string,
|
61 |
prompt: generation.inputs,
|
62 |
+
hf_user_id,
|
63 |
model: {
|
64 |
connect: {
|
65 |
id: generation.model.id
|
src/routes/gallery/+page.svelte
CHANGED
@@ -70,6 +70,7 @@
|
|
70 |
<div class="mt-5 max-w-sm">
|
71 |
<Input value={form.search} placeholder="Search an image" onChange={handleChangeSearch} />
|
72 |
</div>
|
|
|
73 |
<div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
|
74 |
{#each data.cards as card}
|
75 |
<Card card={card} />
|
|
|
70 |
<div class="mt-5 max-w-sm">
|
71 |
<Input value={form.search} placeholder="Search an image" onChange={handleChangeSearch} />
|
72 |
</div>
|
73 |
+
<!-- mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-4 3xl:grid-cols-5 gap-5 mt-8 lg:mt-10 -->
|
74 |
<div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
|
75 |
{#each data.cards as card}
|
76 |
<Card card={card} />
|
src/routes/saved-generations/+page.svelte
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
import { browser } from "$app/environment";
|
3 |
+
|
4 |
+
import Card from "$lib/components/community/Card.svelte";
|
5 |
+
import GoTop from "$lib/components/GoTop.svelte";
|
6 |
+
|
7 |
+
export let data
|
8 |
+
|
9 |
+
$: elementScroll = browser ? document?.getElementById('app') : undefined;
|
10 |
+
</script>
|
11 |
+
|
12 |
+
<svelte:head>
|
13 |
+
<title>My saved generations</title>
|
14 |
+
<meta name="description" content="Svelte demo app" />
|
15 |
+
</svelte:head>
|
16 |
+
|
17 |
+
<main class="px-6 py-10 lg:px-10 lg:py-12">
|
18 |
+
<h1 class="text-white font-semibold text-2xl">
|
19 |
+
Saved generations ({data.total_items})
|
20 |
+
</h1>
|
21 |
+
<div class="mx-auto grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 2xl:grid-cols-4 gap-5 mt-8 lg:mt-10">
|
22 |
+
{#each data.cards as card}
|
23 |
+
<Card card={card} />
|
24 |
+
{/each}
|
25 |
+
<GoTop />
|
26 |
+
</div>
|
27 |
+
</main>
|
src/routes/saved-generations/+page.ts
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export async function load({ fetch }) {
|
2 |
+
const response = await fetch("/api/@me/generations", {
|
3 |
+
method: "GET",
|
4 |
+
headers: {
|
5 |
+
"Content-Type": "application/json"
|
6 |
+
}
|
7 |
+
})
|
8 |
+
const data = await response.json()
|
9 |
+
return data
|
10 |
+
}
|