Commit
•
ecba77a
1
Parent(s):
cf32e4e
use api instead of duckdb on dataset
Browse files- bun.lockb +0 -0
- package.json +0 -1
- src/pages/index.tsx +69 -106
bun.lockb
CHANGED
Binary files a/bun.lockb and b/bun.lockb differ
|
|
package.json
CHANGED
@@ -9,7 +9,6 @@
|
|
9 |
"lint": "next lint"
|
10 |
},
|
11 |
"dependencies": {
|
12 |
-
"@duckdb/duckdb-wasm": "^1.28.1-dev106.0",
|
13 |
"@emotion/react": "^11.13.0",
|
14 |
"@emotion/styled": "^11.13.0",
|
15 |
"@mui/material": "^5.16.6",
|
|
|
9 |
"lint": "next lint"
|
10 |
},
|
11 |
"dependencies": {
|
|
|
12 |
"@emotion/react": "^11.13.0",
|
13 |
"@emotion/styled": "^11.13.0",
|
14 |
"@mui/material": "^5.16.6",
|
src/pages/index.tsx
CHANGED
@@ -2,145 +2,107 @@
|
|
2 |
|
3 |
import { Inter } from "next/font/google";
|
4 |
import ActivityCalendar from "react-activity-calendar";
|
5 |
-
import * as duckdb from "@duckdb/duckdb-wasm"
|
6 |
import { useState, useEffect } from "react";
|
7 |
import { Tooltip as MuiTooltip } from '@mui/material';
|
8 |
|
9 |
const inter = Inter({ subsets: ["latin"] });
|
10 |
|
11 |
-
interface
|
|
|
|
|
|
|
|
|
|
|
12 |
date: string;
|
13 |
count: number;
|
14 |
level: number;
|
15 |
-
details: Array<{ provider: string; count: number }>;
|
16 |
}
|
17 |
|
18 |
-
type ProviderKey = "mistralai" | "meta-llama" | "openai" | "anthropic" | "google";
|
19 |
-
|
20 |
export default function Home() {
|
21 |
-
const [calendarData, setCalendarData] = useState<Record<
|
22 |
const [isLoading, setIsLoading] = useState(true);
|
23 |
|
24 |
-
const PROVIDERS_MAP: Record<
|
25 |
-
"
|
26 |
-
"
|
27 |
-
"
|
28 |
-
"
|
29 |
-
"
|
30 |
}
|
31 |
|
32 |
-
const
|
33 |
-
const
|
34 |
-
|
35 |
-
|
36 |
-
CASE
|
37 |
-
WHEN provider IN ('meta-llama', 'facebook') THEN 'meta-llama'
|
38 |
-
ELSE provider
|
39 |
-
END AS provider,
|
40 |
-
COUNT(*) AS count
|
41 |
-
FROM (
|
42 |
-
SELECT *, SPLIT_PART(id, '/', 1) AS provider
|
43 |
-
FROM models
|
44 |
-
WHERE CAST(createdAt AS DATE) >= DATE_TRUNC('year', CURRENT_DATE)
|
45 |
-
) subquery
|
46 |
-
WHERE provider IN (${Object.keys(PROVIDERS_MAP).map(p => `'${p}'`).join(', ')}, 'facebook')
|
47 |
-
GROUP BY 1, 2
|
48 |
-
ORDER BY date
|
49 |
-
`);
|
50 |
-
return result.toArray().map((row: any) => ({
|
51 |
-
date: row.date,
|
52 |
-
provider: row.provider,
|
53 |
-
count: Number(row.count)
|
54 |
-
}));
|
55 |
-
}
|
56 |
-
|
57 |
-
const generateCalendarData = (modelData: any[]) => {
|
58 |
-
const data: Record<ProviderKey, CustomActivity[]> = Object.keys(PROVIDERS_MAP).reduce((acc, provider) => {
|
59 |
-
acc[provider as ProviderKey] = [];
|
60 |
-
return acc;
|
61 |
-
}, {} as Record<ProviderKey, CustomActivity[]>);
|
62 |
|
63 |
const today = new Date();
|
64 |
const startOfYear = new Date(today.getFullYear(), 0, 1);
|
65 |
|
|
|
66 |
for (let d = new Date(startOfYear); d <= today; d.setDate(d.getDate() + 1)) {
|
67 |
const dateString = d.toISOString().split('T')[0];
|
68 |
|
69 |
-
Object.
|
70 |
-
const
|
71 |
-
|
|
|
|
|
72 |
|
73 |
-
data[provider
|
74 |
-
date: dateString,
|
75 |
-
count,
|
76 |
-
level: 0,
|
77 |
-
details: dayData,
|
78 |
-
});
|
79 |
});
|
80 |
}
|
81 |
|
82 |
-
|
83 |
-
|
|
|
84 |
provider,
|
85 |
-
|
86 |
])
|
87 |
-
)
|
88 |
|
|
|
89 |
Object.entries(data).forEach(([provider, days]) => {
|
90 |
-
const avgCount = avgCounts[provider
|
91 |
days.forEach(day => {
|
92 |
-
day.level =
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
96 |
});
|
97 |
});
|
98 |
|
99 |
return data;
|
100 |
}
|
101 |
|
102 |
-
const
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
}
|
115 |
-
|
116 |
-
const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES)
|
117 |
-
const worker_url = URL.createObjectURL(
|
118 |
-
new Blob([`importScripts("${bundle.mainWorker}");`], {
|
119 |
-
type: "text/javascript",
|
120 |
-
})
|
121 |
-
)
|
122 |
-
|
123 |
-
const worker = new Worker(worker_url)
|
124 |
-
const logger = new duckdb.ConsoleLogger()
|
125 |
-
const db = new duckdb.AsyncDuckDB(logger, worker)
|
126 |
-
await db.instantiate(bundle.mainModule)
|
127 |
-
|
128 |
-
const connection = await db.connect()
|
129 |
-
|
130 |
-
await connection.query(`
|
131 |
-
CREATE VIEW models AS SELECT * FROM read_parquet('https://huggingface.co/datasets/cfahlgren1/hub-stats/resolve/refs%2Fconvert%2Fparquet/models/train/0000.parquet?download=true');
|
132 |
-
`);
|
133 |
-
|
134 |
-
const modelData = await getModelData(connection);
|
135 |
-
const calendarData = generateCalendarData(modelData);
|
136 |
-
setCalendarData(calendarData);
|
137 |
-
setIsLoading(false);
|
138 |
-
|
139 |
-
await connection.close();
|
140 |
}
|
141 |
|
142 |
useEffect(() => {
|
143 |
-
|
144 |
}, []);
|
145 |
|
146 |
return (
|
@@ -154,21 +116,22 @@ export default function Home() {
|
|
154 |
<>
|
155 |
{Object.entries(PROVIDERS_MAP)
|
156 |
.sort(([keyA], [keyB]) =>
|
157 |
-
calendarData[keyB
|
158 |
-
calendarData[keyA
|
159 |
)
|
160 |
-
.map(([
|
161 |
-
<div key={
|
162 |
-
<h2 className="text-2xl font-bold mb-2">{
|
163 |
<ActivityCalendar
|
164 |
-
data={calendarData[
|
165 |
theme={{
|
166 |
-
dark: ['#161b22',
|
167 |
}}
|
|
|
168 |
colorScheme="dark"
|
169 |
renderBlock={(block, activity) => (
|
170 |
<MuiTooltip
|
171 |
-
title={`${activity.count}
|
172 |
>
|
173 |
{block}
|
174 |
</MuiTooltip>
|
|
|
2 |
|
3 |
import { Inter } from "next/font/google";
|
4 |
import ActivityCalendar from "react-activity-calendar";
|
|
|
5 |
import { useState, useEffect } from "react";
|
6 |
import { Tooltip as MuiTooltip } from '@mui/material';
|
7 |
|
8 |
const inter = Inter({ subsets: ["latin"] });
|
9 |
|
10 |
+
interface ModelData {
|
11 |
+
createdAt: string;
|
12 |
+
id: string;
|
13 |
+
}
|
14 |
+
|
15 |
+
interface Activity {
|
16 |
date: string;
|
17 |
count: number;
|
18 |
level: number;
|
|
|
19 |
}
|
20 |
|
|
|
|
|
21 |
export default function Home() {
|
22 |
+
const [calendarData, setCalendarData] = useState<Record<string, Activity[]>>({});
|
23 |
const [isLoading, setIsLoading] = useState(true);
|
24 |
|
25 |
+
const PROVIDERS_MAP: Record<string, { color: string; authors: string[] }> = {
|
26 |
+
"Mistral AI": { color: "#ff7000", authors: ["mistralai"] },
|
27 |
+
"Meta": { color: "#0668E1", authors: ["facebook", "meta-llama"] },
|
28 |
+
"OpenAI": { color: "#10A37F", authors: ["openai"] },
|
29 |
+
"Anthropic": { color: "#cc785c", authors: ["anthropic"] },
|
30 |
+
"Google": { color: "#4285F4", authors: ["google"] },
|
31 |
}
|
32 |
|
33 |
+
const generateCalendarData = (modelData: ModelData[]) => {
|
34 |
+
const data: Record<string, Activity[]> = Object.fromEntries(
|
35 |
+
Object.keys(PROVIDERS_MAP).map(provider => [provider, []])
|
36 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
const today = new Date();
|
39 |
const startOfYear = new Date(today.getFullYear(), 0, 1);
|
40 |
|
41 |
+
// generate daily data for each provider
|
42 |
for (let d = new Date(startOfYear); d <= today; d.setDate(d.getDate() + 1)) {
|
43 |
const dateString = d.toISOString().split('T')[0];
|
44 |
|
45 |
+
Object.entries(PROVIDERS_MAP).forEach(([provider, { authors }]) => {
|
46 |
+
const count = modelData.filter(item =>
|
47 |
+
item.createdAt.startsWith(dateString) &&
|
48 |
+
authors.some(author => item.id.startsWith(author))
|
49 |
+
).length;
|
50 |
|
51 |
+
data[provider].push({ date: dateString, count, level: 0 });
|
|
|
|
|
|
|
|
|
|
|
52 |
});
|
53 |
}
|
54 |
|
55 |
+
// calculate average counts for each provider
|
56 |
+
const avgCounts = Object.fromEntries(
|
57 |
+
Object.entries(data).map(([provider, days]) => [
|
58 |
provider,
|
59 |
+
days.reduce((sum, day) => sum + day.count, 0) / days.length || 0
|
60 |
])
|
61 |
+
);
|
62 |
|
63 |
+
// assign levels based on count relative to average
|
64 |
Object.entries(data).forEach(([provider, days]) => {
|
65 |
+
const avgCount = avgCounts[provider];
|
66 |
days.forEach(day => {
|
67 |
+
day.level =
|
68 |
+
day.count === 0 ? 0 :
|
69 |
+
day.count <= avgCount * 0.5 ? 1 :
|
70 |
+
day.count <= avgCount ? 2 :
|
71 |
+
day.count <= avgCount * 1.5 ? 3 : 4;
|
72 |
});
|
73 |
});
|
74 |
|
75 |
return data;
|
76 |
}
|
77 |
|
78 |
+
const initData = async () => {
|
79 |
+
try {
|
80 |
+
const allAuthors = Object.values(PROVIDERS_MAP).flatMap(({ authors }) => authors);
|
81 |
+
const uniqueAuthors = Array.from(new Set(allAuthors));
|
82 |
+
|
83 |
+
const allModelData = await Promise.all(
|
84 |
+
uniqueAuthors.map(async (author) => {
|
85 |
+
const response = await fetch(`https://huggingface.co/api/models?author=${author}&sort=createdAt&direction=-1`);
|
86 |
+
const data = await response.json();
|
87 |
+
return data.map((item: any) => ({
|
88 |
+
createdAt: item.createdAt,
|
89 |
+
id: item.id,
|
90 |
+
}));
|
91 |
+
})
|
92 |
+
);
|
93 |
+
|
94 |
+
const flatModelData = allModelData.flat();
|
95 |
+
const calendarData = generateCalendarData(flatModelData);
|
96 |
+
setCalendarData(calendarData);
|
97 |
+
} catch (error) {
|
98 |
+
console.error("Error fetching data:", error);
|
99 |
+
} finally {
|
100 |
+
setIsLoading(false);
|
101 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
|
104 |
useEffect(() => {
|
105 |
+
initData();
|
106 |
}, []);
|
107 |
|
108 |
return (
|
|
|
116 |
<>
|
117 |
{Object.entries(PROVIDERS_MAP)
|
118 |
.sort(([keyA], [keyB]) =>
|
119 |
+
calendarData[keyB].reduce((sum, day) => sum + day.count, 0) -
|
120 |
+
calendarData[keyA].reduce((sum, day) => sum + day.count, 0)
|
121 |
)
|
122 |
+
.map(([providerName, { color }]) => (
|
123 |
+
<div key={providerName} className="mb-8">
|
124 |
+
<h2 className="text-2xl font-bold mb-2">{providerName}</h2>
|
125 |
<ActivityCalendar
|
126 |
+
data={calendarData[providerName]}
|
127 |
theme={{
|
128 |
+
dark: ['#161b22', color],
|
129 |
}}
|
130 |
+
hideTotalCount
|
131 |
colorScheme="dark"
|
132 |
renderBlock={(block, activity) => (
|
133 |
<MuiTooltip
|
134 |
+
title={`${activity.count} models created on ${activity.date}`}
|
135 |
>
|
136 |
{block}
|
137 |
</MuiTooltip>
|