File size: 3,887 Bytes
e71d24a
c479a59
 
83deba1
 
e71d24a
eb29a95
dd7ec11
e71d24a
eb29a95
c479a59
eb29a95
 
d6da254
c16a39b
97ec6f2
eb29a95
e71d24a
 
eb29a95
 
c479a59
e71d24a
eb29a95
e71d24a
c479a59
e71d24a
83deba1
644d65a
 
 
 
83deba1
 
eb29a95
c479a59
eb29a95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a084673
ab02e94
644d65a
 
 
 
c479a59
e71d24a
 
 
eb29a95
e71d24a
 
 
eb29a95
 
 
 
644d65a
eb29a95
83deba1
eb29a95
 
 
 
 
c16a39b
a1d7896
 
 
 
c16a39b
a1d7896
 
 
 
c16a39b
eb29a95
 
 
c16a39b
a1d7896
 
 
 
c16a39b
a1d7896
 
 
 
c16a39b
eb29a95
 
 
d6da254
e71d24a
7b25d55
83deba1
eb29a95
 
 
 
 
83deba1
eb29a95
 
 
a084673
eb29a95
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<script lang="ts">
	import { browser } from "$app/environment";
	import InfiniteScroll from "svelte-infinite-scroll";

	import { modelStore } from "$lib/stores/use-model.js";
	import Button from "$lib/components/Button.svelte";
	import Card from "$lib/components/models/Card.svelte";
	import Input from "$lib/components/fields/Input.svelte";
	import Radio from "$lib/components/fields/Radio.svelte";
	import { MODELS_FILTER_OPTIONS } from "$lib/utils/index.js";
	import GoTop from "$lib/components/GoTop.svelte";
	import Dialog from "$lib/components/dialog/Dialog.svelte";
	import SubmitModel from "$lib/components/models/Submit.svelte";
	import Drawer from "$lib/components/models/drawer/Drawer.svelte";
	// import UserIsLogged from "$lib/components/UserIsLogged.svelte";

	export let data

	let form = {
		filter: "hotest",
		search: "",
		page: "0",
	}
	let submitModelDialog = false;

	$: elementScroll = browser ? document?.getElementById('app') : undefined;

	if (data?.model?.id) {
		modelStore.set({
			model: data.model,
			open: true
		});
	}

	const handleFetchMore = async () => {
		form = {...form, page: (Number(form.page) + 1).toString()};
		refetch(true);
	}
	const handleChangeFilter = async (filter: string) => {
		form = { ...form, filter, page: (0).toString()};
		refetch(false)
	}
	let timeout: any;
	const handleChangeSearch = async (search: string) => {
		clearTimeout(timeout);
		form = { ...form, search, page: (0).toString()};
		timeout = setTimeout(() => refetch(false), 500);
	}

	const refetch = async (add: boolean) => {
		const request = await fetch(`/api/models?${new URLSearchParams(form)}`);
		const response = await request.json();
		if (add) data = {...data, models: [...data.models, ...response.cards ]};
		else {
			data.models = response.cards;
			data.total_items = response.total_items;
		}
	}
</script>

<svelte:head>
	<title>Explore Models</title>
	<meta name="description" content="Svelte demo app" />
</svelte:head>

<main class="px-6 py-10 lg:px-10 lg:py-12">
	<Dialog open={submitModelDialog} onClose={() => submitModelDialog = false}>
		<SubmitModel onClose={() => submitModelDialog = false} />
	</Dialog>
	<Drawer />
	<h1 class="text-white font-semibold text-2xl">
		Explore Models ({data?.total_items ?? 0})
	</h1>
	<div class="flex items-start sm:items-center justify-between mt-5 flex-col sm:flex-row gap-5 sm:justify-between">
		<Radio options={MODELS_FILTER_OPTIONS} value="{form.filter}" onChange={handleChangeFilter} />
		<div class="items-center justify-end gap-5 hidden lg:flex">
			<Button href="https://huggingface.co/new/stable-diffusion-lora" target="_blank" icon="ic:round-plus" theme="dark" size="lg">Create</Button>
			<!-- <UserIsLogged> -->
				<Button
					icon="octicon:upload-16"
					theme="blue"
					size="lg"
					disabled={true}
					onClick={() => submitModelDialog = true}
				>
					Upload model
				</Button>
			<!-- </UserIsLogged> -->
		</div>
		<div class="items-center justify-end gap-3 flex lg:hidden">
			<Button href="https://huggingface.co/new/stable-diffusion-lora" target="_blank" icon="ic:round-plus" theme="dark" size="md">Create</Button>
			<!-- <UserIsLogged> -->
				<Button
					icon="octicon:upload-16"
					theme="blue"
					size="md"
					disabled={true}
					onClick={() => submitModelDialog = true}
				>
					Upload model
				</Button>
			<!-- </UserIsLogged> -->
		</div>
	</div>
	<div class="mt-5 max-w-sm">
		<Input value={form.search} placeholder="Filter by model name" onChange={handleChangeSearch} />
	</div>
	<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">
		{#each data.models as card}
			<Card card={card} />
		{/each}
		<InfiniteScroll
			elementScroll="{elementScroll ?? undefined}"
			threshold={100}
			hasMore={data.total_items > data.models.length}
			on:loadMore={handleFetchMore}
		/>
		<GoTop />
	</div>
</main>