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
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
type AuthorData = {
avatarUrl: string;
fullname: string;
name: string;
type: string;
isHf: boolean;
};
interface Repo {
author: string;
id: string;
isLikedByUser: boolean;
lastModified: string;
likes: number;
private: boolean;
}
type ModelRepo = Repo & {
authorData: AuthorData;
downloads: number;
gated: boolean;
pipeline_tag: string;
repoType: "model";
};
type DatasetRepo = Repo & {
downloads: number;
gated: boolean;
previewable: boolean;
repoType: "dataset";
};
type SpaceRepo = Repo & {
authorData: AuthorData;
colorFrom: string;
colorTo: string;
emoji: string;
pinned: boolean;
runtime: object;
title: string;
repoType: "space";
};
type TrendingRepo = {
likes: number;
typeRank: number;
allRank?: number;
repoType: "model" | "dataset" | "space";
repoData: ModelRepo | DatasetRepo | SpaceRepo;
};
export const HuggingFace_getTrending = async (params: {
type: "all" | "model" | "dataset" | "space";
}): Promise<TrendingRepo[]> => {
const url = "https://huggingface.co/api/trending";
const query = new URLSearchParams({ type: params.type, limit: String(100) });
const json = await fetchJSON(
url + "?" + query.toString(),
);
const data: TrendingRepo[] = json.recentlyTrending;
["model", "dataset", "space"].forEach((type) =>
data.filter((repo) => repo.repoType == type).forEach((repo, i) => {
repo.typeRank = i + 1;
})
);
if (params.type == "all") {
data.forEach((repo, i) => repo.allRank = i + 1);
}
return data;
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.