File size: 1,886 Bytes
31a2d08
 
 
 
 
 
c99cc8d
 
 
31a2d08
 
 
 
c99cc8d
31a2d08
 
 
c4d103b
c99cc8d
 
 
 
 
 
 
 
 
 
31a2d08
 
 
 
 
 
 
 
 
c99cc8d
31a2d08
c99cc8d
 
31a2d08
c99cc8d
 
 
 
 
 
 
 
 
 
31a2d08
 
 
 
 
 
 
 
 
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
<script lang="ts">
    import { onMount } from "svelte";
    import { ProgressBarRound } from "carbon-icons-svelte";

    interface Entry {
        name: string;
        rank: number;
        score: number;
        votes: number;
    }

    export let onEntryClick: (entry: Entry) => void;

    const baseUrl = "https://huggingface.co/datasets/dylanebert/3d-arena/resolve/main/outputs";
    let leaderboard: Entry[] = [];

    const fetchLeaderboardData = async () => {
        const url = "/api/leaderboard";
        const response = await fetch(url, {
            method: "GET",
            headers: {
                "Cache-Control": "no-cache",
            },
        });
        const data = (await response.json()) as Entry[];
        data.sort((a, b) => a.rank - b.rank);

        leaderboard = data;
    };

    onMount(async () => {
        await fetchLeaderboardData();
    });
</script>

{#if leaderboard.length > 0}
    <div class="grid">
        {#each leaderboard as entry}
            <button class="grid-item" on:click={() => onEntryClick(entry)}>
                <img src={`${baseUrl}/${entry.name}/thumbnail.png`} alt={entry.name} class="thumbnail" />
                <div class="ranking">{entry.rank}</div>
                <div class="title">{entry.name}</div>
                <div class="score-container">
                    <div class="score">
                        <span class="label">Score:</span>
                        {entry.score}
                    </div>
                    <div class="votes">
                        <span class="label">Votes:</span>
                        {entry.votes}
                    </div>
                </div>
            </button>
        {/each}
    </div>
{:else}
    <div class="loading-container">
        <ProgressBarRound class="loading-icon" />
        <div class="loading-text">Loading...</div>
    </div>
{/if}