Skip to content

Commit

Permalink
add tag colors
Browse files Browse the repository at this point in the history
  • Loading branch information
juansensio committed Aug 9, 2024
1 parent 294d0cc commit d30d2f7
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 24 deletions.
1 change: 1 addition & 0 deletions api/api/src/models/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
class Tag(BaseModel):
name: str
category: str
color: str
2 changes: 1 addition & 1 deletion api/api/src/usecases/user/create_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def create_api_key(user: User) -> ApiKey:
repo = UserDBRepo()
if len(retrieve_api_keys(user)) >= 2:
if len(retrieve_api_keys(user)) >= 5:
raise Exception(
"API key limit reached. Delete an existing key to create a new one."
)
Expand Down
7 changes: 5 additions & 2 deletions ui/src/components/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export let data;
export let liked = null;
export let link = "datasets";
export let tags;
</script>

<a
Expand All @@ -22,7 +23,9 @@
<div class="flex flex-wrap gap-1 content-start mt-1">
{#each data.tags as tag}
<p
class="badge badge-outline bg-white border-slate-300 text-slate-400 text-xs h-full"
class="badge border-0 text-slate-800 text-xs"
style="background-color: {tags?.find((t) => t.name == tag)
.color || 'none'};"
>
{tag}
</p>
Expand All @@ -47,7 +50,7 @@
<Sd color="gray" size={14} />
<p>
{formatFileSize(
data.versions[data.versions.length - 1]?.size || 0
data.versions[data.versions.length - 1]?.size || 0,
)}
</p>
</span>
Expand Down
11 changes: 6 additions & 5 deletions ui/src/components/Tags.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
{#each tags as tag}
{#if tag.category == category}
<button
class="badge text-slate-400 text-xs mx-[1px] {selected_tags.includes(
tag.name,
)
? 'badge badge-accent bg-green-100 text-slate-600 '
: 'badge-outline'}"
class={`badge text-slate-400 text-xs mx-[1px] ${
selected_tags.includes(tag.name)
? `badge badge-outline text-slate-600 border-0`
: "badge-outline"
}`}
style={`${selected_tags.includes(tag.name) && `background-color: ${tag.color};`}`}
on:click={() => toggleTag(tag.name)}
>
{tag.name}
Expand Down
6 changes: 5 additions & 1 deletion ui/src/routes/+page.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import retrieveTags from '../lib/tags/retrieveTags'

export const load = async ({fetch}) => {
const response = await fetch(`/api/posts`);
const posts = await response.json();
const tags = await retrieveTags(fetch)
return {
posts: posts.slice(0, 3)
posts: posts.slice(0, 3),
tags
}
}

Expand Down
8 changes: 4 additions & 4 deletions ui/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
class="w-full"
style="background: url('backgrounds/Group-1170.png') center center/cover"
>
<RecentDatasets />
<PopularDatasets />
<RecentDatasets tags={data.tags} />
<PopularDatasets tags={data.tags} />
<DatasetsLeaderboard />
</div>
<div
class="w-full"
style="background: url('backgrounds/Group-1170.png') center center/cover"
>
<RecentModels />
<PopularModels />
<RecentModels tags={data.tags} />
<PopularModels tags={data.tags} />
<ModelsLeaderboard />
</div>
<Posts posts={data.posts} />
Expand Down
3 changes: 2 additions & 1 deletion ui/src/routes/Popular.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export let data;
export let title;
export let tags;
</script>

<div class="flex flex-col items-center w-full pt-10">
Expand All @@ -14,7 +15,7 @@
>
{#if data}
{#each data as item}
<Card data={item} />
<Card data={item} {tags} />
{/each}
{:else}
{#each [1, 2, 3] as _}
Expand Down
4 changes: 3 additions & 1 deletion ui/src/routes/PopularDatasets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import retrievePopularDatasets from "$lib/datasets/retrievePopularDatasets";
import Popular from "./Popular.svelte";
export let tags;
let data = null;
onMount(async () => {
data = await retrievePopularDatasets(fetch, 3);
});
</script>

<Popular {data} title="Popular datasets" />
<Popular {data} title="Popular datasets" {tags} />
4 changes: 3 additions & 1 deletion ui/src/routes/PopularModels.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import retrievePopularModels from "$lib/models/retrievePopularModels";
import Popular from "./Popular.svelte";
export let tags;
let data = null;
onMount(async () => {
data = await retrievePopularModels(fetch, 3);
});
</script>

<Popular {data} title="Popular models" />
<Popular {data} title="Popular models" {tags} />
3 changes: 2 additions & 1 deletion ui/src/routes/Recent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
export let data;
export let title;
export let tags;
</script>

<div class="flex flex-col items-center w-full">
Expand All @@ -27,7 +28,7 @@
>
{#if data}
{#each data as item}
<Card data={item} />
<Card data={item} {tags} />
{/each}
{:else}
{#each [1, 2, 3] as _}
Expand Down
4 changes: 3 additions & 1 deletion ui/src/routes/RecentDatasets.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import retrieveDatasets from "$lib/datasets/retrieveDatasets";
import Recent from "./Recent.svelte";
export let tags;
let data = null;
onMount(async () => {
data = await retrieveDatasets(fetch, 3);
});
</script>

<Recent {data} title="Recent datasets" />
<Recent {data} title="Recent datasets" {tags} />
4 changes: 3 additions & 1 deletion ui/src/routes/RecentModels.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import retrieveModels from "$lib/models/retrieveModels";
import Recent from "./Recent.svelte";
export let tags;
let data = null;
onMount(async () => {
data = await retrieveModels(fetch, 3);
});
</script>

<Recent {data} title="Recent models" />
<Recent {data} title="Recent models" {tags} />
1 change: 1 addition & 0 deletions ui/src/routes/datasets/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
<Card
data={dataset}
liked={$user?.liked_datasets.includes(dataset.id)}
tags={data.tags}
/>
{/each}
</div>
Expand Down
7 changes: 5 additions & 2 deletions ui/src/routes/datasets/IngestForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,14 @@
<div class="flex flex-wrap gap-1">
{#each tags as tag}
<p
class="badge badge-outline cursor-pointer text-slate-400 text-xs {selected_tags.includes(
class="badge cursor-pointer text-slate-400 text-xs {selected_tags.includes(
tag.name,
) && 'badge-accent'}"
)
? 'text-slate-800 border-0'
: 'badge-outline'}"
on:click={() => toggleTag(tag.name)}
on:keyup={() => {}}
style={`${selected_tags.includes(tag.name) && `background-color: ${tag.color};`}`}
>
{tag.name}
</p>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/routes/datasets/[name]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
<div class="flex flex-wrap gap-1">
{#each dataset.tags as tag}
<p
class="badge badge-outline border-slate-300 text-slate-400 text-xs"
class="badge border-0 text-slate-800 text-xs"
style="background-color: {data.tags?.find(
(t) => t.name == tag,
).color || 'none'};"
>
{tag}
</p>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/routes/models/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
filtered_models = $models.data
?.filter((models) => {
if (selected_tags.length === 0) return true;
return selected_tags.every((tag) => models.tags.includes(tag.name));
return selected_tags.every((tag) =>
models.tags.includes(tag.name),
);
})
.filter((models) => {
if (filterName.length === 0) return true;
Expand Down Expand Up @@ -123,6 +125,7 @@
data={model}
link="models"
liked={$user?.liked_models?.includes(model.id)}
tags={data.tags}
/>
{/each}
</div>
Expand Down
5 changes: 4 additions & 1 deletion ui/src/routes/models/[name]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
<div class="flex flex-wrap gap-1">
{#each model.tags as tag}
<p
class="badge badge-outline border-slate-300 text-slate-400 text-xs"
class="badge border-0 text-slate-800 text-xs"
style="background-color: {data.tags?.find(
(t) => t.name == tag,
).color || 'none'};"
>
{tag}
</p>
Expand Down

0 comments on commit d30d2f7

Please sign in to comment.