davanstrien HF Staff commited on
Commit
6c4c663
·
verified ·
1 Parent(s): 5438efc

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +163 -40
index.html CHANGED
@@ -1,12 +1,14 @@
1
- <!doctype html>
2
  <html>
3
  <head>
4
  <meta charset="utf-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>SQL Console Demos</title>
7
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600&display=swap" rel="stylesheet" />
 
8
  <script src="https://cdn.jsdelivr.net/npm/@duckdb/[email protected]/dist/duckdb-browser-blocking.js"></script>
9
  <script src="https://cdn.jsdelivr.net/npm/@duckdb/[email protected]/dist/duckdb-browser.js"></script>
 
10
  <style>
11
  body {
12
  font-family: 'Source Sans Pro', system-ui, -apple-system, sans-serif;
@@ -76,6 +78,39 @@
76
  display: block;
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  @media (max-width: 768px) {
80
  body {
81
  padding: 1rem;
@@ -94,7 +129,8 @@
94
  </header>
95
 
96
  <div class="summary" id="total-annotations">
97
- <p>Loading total annotations...</p>
 
98
  </div>
99
 
100
  <div class="grid">
@@ -126,53 +162,140 @@
126
  // Import DuckDB
127
  import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/[email protected]/+esm'
128
 
129
- async function initDuckDB() {
130
- try {
131
- // Get the bundle from JSDelivr
132
- const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
133
-
134
- // Select a bundle based on browser checks
135
- const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);
136
-
137
- // Create a worker URL
138
- const worker_url = URL.createObjectURL(
139
- new Blob([`importScripts("${bundle.mainWorker}");`], {type: 'text/javascript'})
140
- );
141
-
142
- // Initialize the database
143
- const worker = new Worker(worker_url);
144
- const logger = new duckdb.ConsoleLogger();
145
- const db = new duckdb.AsyncDuckDB(logger, worker);
146
- await db.instantiate(bundle.mainModule, bundle.pthreadWorker);
147
- URL.revokeObjectURL(worker_url);
148
 
149
- // Create a connection
150
- const conn = await db.connect();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
- // Load the httpfs extension for remote file access
153
- await conn.query(`INSTALL httpfs; LOAD httpfs;`);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
 
155
- // Query total annotations
156
- const result = await conn.query(`
157
- SELECT SUM(submitted) as total_annotations
158
- FROM 'https://huggingface.co/datasets/davanstrien/progress/resolve/main/train/train.parquet'
159
- `);
 
 
 
 
160
 
161
- const totalAnnotations = result.get(0).total_annotations;
162
- document.getElementById('total-annotations').innerHTML =
163
- `<p>Total annotations submitted: <strong>${totalAnnotations.toLocaleString()}</strong></p>`;
164
 
165
- // Close the connection
166
- await conn.close();
 
 
 
 
167
 
168
  } catch (error) {
169
- console.error('Error:', error);
170
- document.getElementById('total-annotations').innerHTML =
171
- `<p>Error loading total annotations: ${error.message}</p>`;
 
172
  }
173
  }
174
 
175
- initDuckDB();
 
 
 
 
 
176
  </script>
177
  </body>
178
  </html>
 
1
+ <!DOCTYPE html>
2
  <html>
3
  <head>
4
  <meta charset="utf-8" />
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Leaderboards</title>
7
  <link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600&display=swap" rel="stylesheet" />
8
+ <!-- Load DuckDB WASM bundles -->
9
  <script src="https://cdn.jsdelivr.net/npm/@duckdb/[email protected]/dist/duckdb-browser-blocking.js"></script>
10
  <script src="https://cdn.jsdelivr.net/npm/@duckdb/[email protected]/dist/duckdb-browser.js"></script>
11
+ <!-- Add loading indicator styles -->
12
  <style>
13
  body {
14
  font-family: 'Source Sans Pro', system-ui, -apple-system, sans-serif;
 
78
  display: block;
79
  }
80
 
81
+ /* Loading indicator styles */
82
+ .loading {
83
+ display: inline-block;
84
+ width: 20px;
85
+ height: 20px;
86
+ border: 3px solid rgba(0,0,0,.1);
87
+ border-radius: 50%;
88
+ border-top-color: #3b82f6;
89
+ animation: spin 1s ease-in-out infinite;
90
+ margin-right: 10px;
91
+ vertical-align: middle;
92
+ }
93
+
94
+ @keyframes spin {
95
+ to { transform: rotate(360deg); }
96
+ }
97
+
98
+ .error {
99
+ color: #dc2626;
100
+ padding: 1rem;
101
+ background: #fee2e2;
102
+ border-radius: 8px;
103
+ margin: 1rem 0;
104
+ }
105
+
106
+ .success {
107
+ color: #059669;
108
+ padding: 1rem;
109
+ background: #d1fae5;
110
+ border-radius: 8px;
111
+ margin: 1rem 0;
112
+ }
113
+
114
  @media (max-width: 768px) {
115
  body {
116
  padding: 1rem;
 
129
  </header>
130
 
131
  <div class="summary" id="total-annotations">
132
+ <div class="loading"></div>
133
+ <span>Loading total annotations...</span>
134
  </div>
135
 
136
  <div class="grid">
 
162
  // Import DuckDB
163
  import * as duckdb from 'https://cdn.jsdelivr.net/npm/@duckdb/[email protected]/+esm'
164
 
165
+ class DuckDBLoader {
166
+ constructor() {
167
+ this.db = null;
168
+ this.conn = null;
169
+ }
170
+
171
+ async initialize() {
172
+ try {
173
+ // Get the bundle from JSDelivr
174
+ const JSDELIVR_BUNDLES = duckdb.getJsDelivrBundles();
175
+
176
+ // Select a bundle based on browser checks
177
+ const bundle = await duckdb.selectBundle(JSDELIVR_BUNDLES);
178
+
179
+ // Create a worker URL
180
+ const worker_url = URL.createObjectURL(
181
+ new Blob([`importScripts("${bundle.mainWorker}");`], {type: 'text/javascript'})
182
+ );
 
183
 
184
+ // Initialize the database
185
+ const worker = new Worker(worker_url);
186
+ const logger = new duckdb.ConsoleLogger();
187
+ this.db = new duckdb.AsyncDuckDB(logger, worker);
188
+
189
+ // Instantiate with error handling
190
+ try {
191
+ await this.db.instantiate(bundle.mainModule, bundle.pthreadWorker);
192
+ } catch (error) {
193
+ throw new Error(`DuckDB instantiation failed: ${error.message}`);
194
+ }
195
+
196
+ URL.revokeObjectURL(worker_url);
197
+
198
+ // Create connection
199
+ this.conn = await this.db.connect();
200
+
201
+ // Initialize extensions
202
+ await this.initializeExtensions();
203
+
204
+ return true;
205
+ } catch (error) {
206
+ this.handleError('Initialization failed', error);
207
+ return false;
208
+ }
209
+ }
210
+
211
+ async initializeExtensions() {
212
+ try {
213
+ await this.conn.query(`INSTALL httpfs;`);
214
+ await this.conn.query(`LOAD httpfs;`);
215
+ } catch (error) {
216
+ throw new Error(`Failed to initialize extensions: ${error.message}`);
217
+ }
218
+ }
219
+
220
+ async queryTotalAnnotations() {
221
+ try {
222
+ const result = await this.conn.query(`
223
+ SELECT SUM(submitted) as total_annotations
224
+ FROM 'https://huggingface.co/datasets/davanstrien/progress/resolve/main/train/train.parquet'
225
+ `);
226
+
227
+ if (!result || !result.get || result.length === 0) {
228
+ throw new Error('Query returned no results');
229
+ }
230
+
231
+ const totalAnnotations = result.get(0).total_annotations;
232
+ if (totalAnnotations === null || totalAnnotations === undefined) {
233
+ throw new Error('No annotation count found in result');
234
+ }
235
+
236
+ return totalAnnotations;
237
+ } catch (error) {
238
+ throw new Error(`Failed to query annotations: ${error.message}`);
239
+ }
240
+ }
241
+
242
+ handleError(context, error) {
243
+ console.error(context, error);
244
+ const errorMessage = error.message || 'Unknown error occurred';
245
+ const errorDetails = error instanceof WebAssembly.Exception ?
246
+ '(WebAssembly Exception)' : '';
247
 
248
+ document.getElementById('total-annotations').innerHTML = `
249
+ <div class="error">
250
+ Error: ${context}: ${errorMessage} ${errorDetails}
251
+ </div>
252
+ `;
253
+ }
254
+
255
+ async cleanup() {
256
+ if (this.conn) {
257
+ await this.conn.close();
258
+ }
259
+ if (this.db) {
260
+ await this.db.terminate();
261
+ }
262
+ }
263
+ }
264
 
265
+ async function initializeApplication() {
266
+ const loader = new DuckDBLoader();
267
+
268
+ try {
269
+ // Initialize DuckDB
270
+ const initialized = await loader.initialize();
271
+ if (!initialized) {
272
+ return;
273
+ }
274
 
275
+ // Query total annotations
276
+ const totalAnnotations = await loader.queryTotalAnnotations();
 
277
 
278
+ // Update UI with success
279
+ document.getElementById('total-annotations').innerHTML = `
280
+ <div class="success">
281
+ Total annotations submitted: <strong>${totalAnnotations.toLocaleString()}</strong>
282
+ </div>
283
+ `;
284
 
285
  } catch (error) {
286
+ loader.handleError('Failed to load annotations', error);
287
+ } finally {
288
+ // Cleanup resources
289
+ await loader.cleanup();
290
  }
291
  }
292
 
293
+ // Start the application when the DOM is ready
294
+ if (document.readyState === 'loading') {
295
+ document.addEventListener('DOMContentLoaded', initializeApplication);
296
+ } else {
297
+ initializeApplication();
298
+ }
299
  </script>
300
  </body>
301
  </html>