lora-studio / src /routes /+page.svelte
enzostvs's picture
enzostvs HF staff
responsive stuffs
c16a39b
raw
history blame
3.61 kB
<script lang="ts">
import { browser } from "$app/environment";
import InfiniteScroll from "svelte-infinite-scroll";
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 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;
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, cards: [...data.cards, ...response.cards ]};
else data = response;
}
</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>
<h1 class="text-white font-semibold text-2xl">
Explore Models ({data.total_items})
</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="Search a model" onChange={handleChangeSearch} />
</div>
<div class="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">
{#each data.cards as card}
<Card card={card} />
{/each}
<InfiniteScroll
elementScroll="{elementScroll ?? undefined}"
threshold={100}
hasMore={data.total_items > data.cards.length}
on:loadMore={handleFetchMore}
/>
<GoTop />
</div>
</main>