Skip to content

Commit f35dcac

Browse files
committed
Add License, fix loading more models
1 parent 252d438 commit f35dcac

File tree

5 files changed

+52
-21
lines changed

5 files changed

+52
-21
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 NetroScript
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

src/lib/common.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,16 @@ export const getModelType = (model: Model): ModelTypes => {
7575

7676
return ModelTypes.OTHER;
7777
};
78+
79+
export const getModelSize = (model: Model): string => {
80+
const nameParts = model.id.split('-');
81+
82+
// The part with /^\d+B$/ is the model size
83+
for (const part of nameParts) {
84+
if (/^\d+B$/.test(part)) {
85+
return part;
86+
}
87+
}
88+
89+
return 'Unknown';
90+
};

src/lib/stores.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { derived, type Writable, writable } from 'svelte/store';
22
import type { LocalStorageValue, SidePanel } from './common';
3-
import { FilterModes } from './common';
3+
import { FilterModes, getModelSize } from './common';
44

55
import { localStorageStore } from '@skeletonlabs/skeleton';
66
import * as devalue from 'devalue';
@@ -46,17 +46,11 @@ export const availableLicences = derived(state, ($state) => {
4646
return Array.from(licences);
4747
});
4848

49-
// Available Model Metadatas
49+
// Available Model Sizes
5050
export const availableModelSizes = derived(state, ($state) => {
5151
const modelSizes = new Set<string>();
5252
$state.models.forEach((model) => {
53-
const nameParts = model.id.split('-');
54-
// The part with /^\d+B$/ is the model size
55-
nameParts.forEach((part) => {
56-
if (/^\d+B$/.test(part)) {
57-
modelSizes.add(part);
58-
}
59-
});
53+
modelSizes.add(getModelSize(model));
6054
});
6155
return Array.from(modelSizes);
6256
});

src/routes/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
</div>
4141
<a
4242
class="anchor m-4"
43-
href="https://github.com/NetroScript/huggingface-llm-filtering/blob/master/LICENSE.md"
43+
href="https://github.com/NetroScript/huggingface-llm-filtering/blob/master/LICENSE"
4444
rel="noreferrer"
4545
target="_blank">MIT License</a
4646
>

src/routes/+page.svelte

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script lang="ts">
2-
import {availableLicences, availableModelSizes, filteredModels, state} from '$lib/stores';
3-
import {onMount} from 'svelte';
4-
import type {Model} from '$lib/huggingfaceAPI';
5-
import {ModelSchema} from '$lib/huggingfaceAPI';
2+
import { availableLicences, availableModelSizes, filteredModels, state } from '$lib/stores';
3+
import { onMount } from 'svelte';
4+
import type { Model } from '$lib/huggingfaceAPI';
5+
import { ModelSchema } from '$lib/huggingfaceAPI';
66
import ModelCard from '$lib/components/ModelCard.svelte';
7-
import {ProgressRadial} from "@skeletonlabs/skeleton";
8-
import InfiniteLoading, {type StateChanger} from 'svelte-infinite-loading';
7+
import { ProgressRadial } from '@skeletonlabs/skeleton';
8+
import InfiniteLoading, { type StateChanger } from 'svelte-infinite-loading';
99
1010
const updateModels = async () => {
1111
const res = await fetch('https://huggingface.co/api/models?full=1&author=' + $state.author);
@@ -48,22 +48,24 @@
4848
});
4949
5050
let shownModelCount = 50;
51+
let loadingIdentifier = 0;
5152
5253
filteredModels.subscribe(() => {
5354
shownModelCount = 50;
55+
loadingIdentifier++;
5456
});
5557
5658
$: currentShownModels = $filteredModels.slice(0, shownModelCount);
5759
5860
$: canShowMore = $filteredModels.length > shownModelCount;
5961
60-
let loadingIdentifier = 0;
62+
6163
const loadMore = async ({detail: {loaded, complete}} : ({detail: StateChanger}) ) => {
6264
6365
shownModelCount += 50;
6466
6567
66-
if (shownModelCount >= $state.models.length) {
68+
if (shownModelCount >= $filteredModels.length) {
6769
complete();
6870
} else {
6971
loaded();
@@ -98,13 +100,14 @@
98100
{#each currentShownModels as model, i}
99101
<ModelCard {model} />
100102
{/each}
101-
<InfiniteLoading on:infinite={loadMore} distance={400} identifier={loadingIdentifier}>
102-
<div slot="noMore"></div>
103-
</InfiniteLoading>
103+
104104
</div>
105105
{/if}
106106

107107
{#if canShowMore}
108+
<InfiniteLoading on:infinite={loadMore} distance={400} identifier={loadingIdentifier}>
109+
<div slot="noMore"></div>
110+
</InfiniteLoading>
108111
<ProgressRadial width="w-8 mx-auto" meter="stroke-surface-50" stroke="{150}"/>
109112
{/if}
110113
</div>

0 commit comments

Comments
 (0)