update app
Browse files- index.html +69 -74
index.html
CHANGED
|
@@ -1330,78 +1330,74 @@
|
|
| 1330 |
const p = state.profile;
|
| 1331 |
const fullname = p?.fullname || p?.name || u;
|
| 1332 |
|
| 1333 |
-
|
|
|
|
| 1334 |
if (p?.avatarUrl) {
|
| 1335 |
-
const fullUrl = p.avatarUrl.startsWith('http') ? p.avatarUrl : `https://huggingface.co${p.avatarUrl}`;
|
| 1336 |
try {
|
| 1337 |
-
|
| 1338 |
-
|
| 1339 |
-
|
| 1340 |
-
|
| 1341 |
-
const
|
| 1342 |
-
|
| 1343 |
-
|
| 1344 |
-
|
| 1345 |
-
|
| 1346 |
-
|
| 1347 |
-
|
| 1348 |
-
|
| 1349 |
-
|
| 1350 |
-
|
| 1351 |
-
|
| 1352 |
-
|
| 1353 |
-
|
| 1354 |
-
|
| 1355 |
-
|
| 1356 |
-
|
| 1357 |
-
|
| 1358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1359 |
}
|
| 1360 |
}
|
| 1361 |
|
| 1362 |
-
|
| 1363 |
-
if (
|
| 1364 |
-
|
| 1365 |
-
|
| 1366 |
-
|
| 1367 |
-
|
| 1368 |
-
|
| 1369 |
-
|
| 1370 |
-
console.error("Image add failed:", e);
|
| 1371 |
-
}
|
| 1372 |
}
|
| 1373 |
|
| 1374 |
-
doc.setFontSize(22);
|
| 1375 |
-
doc.text(fullname, textX, 22);
|
| 1376 |
-
|
| 1377 |
-
doc.setFontSize(14);
|
| 1378 |
-
doc.text(`@${u}`, textX, 30);
|
| 1379 |
-
|
| 1380 |
-
doc.setFontSize(10);
|
| 1381 |
-
doc.text(`HuggingFace Activity Report`, textX, 36);
|
| 1382 |
-
|
| 1383 |
doc.setFontSize(12);
|
| 1384 |
-
doc.text(`
|
| 1385 |
-
|
| 1386 |
-
|
| 1387 |
-
|
| 1388 |
-
|
| 1389 |
-
|
| 1390 |
-
|
| 1391 |
-
|
| 1392 |
-
|
| 1393 |
-
|
| 1394 |
-
|
| 1395 |
-
|
| 1396 |
-
|
| 1397 |
-
|
| 1398 |
-
|
| 1399 |
-
|
| 1400 |
-
|
| 1401 |
-
|
| 1402 |
-
|
| 1403 |
-
|
| 1404 |
-
|
|
|
|
|
|
|
|
|
|
| 1405 |
|
| 1406 |
const pipelineCounts = {};
|
| 1407 |
state.models.forEach(m => {
|
|
@@ -1479,16 +1475,15 @@
|
|
| 1479 |
|
| 1480 |
doc.save(`hf-report-${u}-${new Date().toISOString().slice(0,10)}.pdf`);
|
| 1481 |
btn.innerHTML = '<i class="fas fa-check"></i> Downloaded';
|
| 1482 |
-
|
| 1483 |
-
|
| 1484 |
-
|
| 1485 |
-
|
| 1486 |
-
|
| 1487 |
-
|
| 1488 |
-
|
| 1489 |
-
|
| 1490 |
-
|
| 1491 |
-
}, 100);
|
| 1492 |
}
|
| 1493 |
|
| 1494 |
function setActiveTab(tab) {
|
|
|
|
| 1330 |
const p = state.profile;
|
| 1331 |
const fullname = p?.fullname || p?.name || u;
|
| 1332 |
|
| 1333 |
+
// Try to load and process avatar
|
| 1334 |
+
let avatarBase64 = null;
|
| 1335 |
if (p?.avatarUrl) {
|
|
|
|
| 1336 |
try {
|
| 1337 |
+
const fullUrl = p.avatarUrl.startsWith('http') ? p.avatarUrl : `https://huggingface.co${p.avatarUrl}`;
|
| 1338 |
+
const res = await fetch(fullUrl);
|
| 1339 |
+
if (res.ok) {
|
| 1340 |
+
const blob = await res.blob();
|
| 1341 |
+
const objectUrl = URL.createObjectURL(blob);
|
| 1342 |
+
|
| 1343 |
+
const img = new Image();
|
| 1344 |
+
await new Promise((resolve, reject) => {
|
| 1345 |
+
img.onload = resolve;
|
| 1346 |
+
img.onerror = reject;
|
| 1347 |
+
img.src = objectUrl;
|
| 1348 |
+
});
|
| 1349 |
+
|
| 1350 |
+
const canvas = document.createElement('canvas');
|
| 1351 |
+
canvas.width = 64;
|
| 1352 |
+
canvas.height = 64;
|
| 1353 |
+
const ctx = canvas.getContext('2d');
|
| 1354 |
+
ctx.fillStyle = '#ffffff'; // White bg for transparency safety
|
| 1355 |
+
ctx.fillRect(0, 0, 64, 64);
|
| 1356 |
+
ctx.drawImage(img, 0, 0, 64, 64);
|
| 1357 |
+
avatarBase64 = canvas.toDataURL('image/jpeg', 0.95);
|
| 1358 |
+
|
| 1359 |
+
URL.revokeObjectURL(objectUrl);
|
| 1360 |
+
}
|
| 1361 |
+
} catch (e) {
|
| 1362 |
+
console.warn('Could not fetch avatar for PDF:', e);
|
| 1363 |
}
|
| 1364 |
}
|
| 1365 |
|
| 1366 |
+
// Header
|
| 1367 |
+
if (avatarBase64) {
|
| 1368 |
+
doc.addImage(avatarBase64, 'JPEG', 14, 12, 16, 16);
|
| 1369 |
+
doc.setFontSize(22);
|
| 1370 |
+
doc.text(`HuggingFace Activity Report: ${fullname}`, 34, 24);
|
| 1371 |
+
} else {
|
| 1372 |
+
doc.setFontSize(22);
|
| 1373 |
+
doc.text(`HuggingFace Activity Report: ${fullname}`, 14, 24);
|
|
|
|
|
|
|
| 1374 |
}
|
| 1375 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1376 |
doc.setFontSize(12);
|
| 1377 |
+
doc.text(`Username: @${u}`, 14, 34);
|
| 1378 |
+
doc.text(`Followers: ${p?.numFollowers ?? 0} | Organizations: ${Array.isArray(p?.orgs) ? p.orgs.length : 0}`, 14, 42);
|
| 1379 |
+
|
| 1380 |
+
const totalModels = state.models.length;
|
| 1381 |
+
const totalDatasets = state.datasets.length;
|
| 1382 |
+
const totalSpaces = state.spaces.length;
|
| 1383 |
+
|
| 1384 |
+
const totalModelDl = state.models.reduce((s, m) => s + getLifetimeDownloads(m), 0);
|
| 1385 |
+
const totalDatasetDl = state.datasets.reduce((s, d) => s + getLifetimeDownloads(d), 0);
|
| 1386 |
+
const totalLikes = [...state.models, ...state.datasets, ...state.spaces].reduce((s, i) => s + getItemLikes(i), 0);
|
| 1387 |
+
|
| 1388 |
+
doc.text(`Total Models: ${totalModels} (Downloads: ${formatNumFull(totalModelDl)})`, 14, 46);
|
| 1389 |
+
doc.text(`Total Datasets: ${totalDatasets} (Downloads: ${formatNumFull(totalDatasetDl)})`, 14, 54);
|
| 1390 |
+
doc.text(`Total Spaces: ${totalSpaces}`, 14, 62);
|
| 1391 |
+
doc.text(`Total Likes Received: ${formatNumFull(totalLikes)}`, 14, 70);
|
| 1392 |
+
|
| 1393 |
+
let startY = 80;
|
| 1394 |
+
|
| 1395 |
+
const totalDlMonthly = state.models.reduce((s, m) => s + getMonthlyDownloads(m), 0) + state.datasets.reduce((s, d) => s + getMonthlyDownloads(d), 0);
|
| 1396 |
+
doc.text(`Downloads Last 30 Days: ${formatNumFull(totalDlMonthly)}`, 14, 78);
|
| 1397 |
+
|
| 1398 |
+
const totalPrivate = [...state.models, ...state.datasets, ...state.spaces].filter(i => i.private).length;
|
| 1399 |
+
doc.text(`Total Private Repositories: ${totalPrivate}`, 14, 86);
|
| 1400 |
+
startY = 96;
|
| 1401 |
|
| 1402 |
const pipelineCounts = {};
|
| 1403 |
state.models.forEach(m => {
|
|
|
|
| 1475 |
|
| 1476 |
doc.save(`hf-report-${u}-${new Date().toISOString().slice(0,10)}.pdf`);
|
| 1477 |
btn.innerHTML = '<i class="fas fa-check"></i> Downloaded';
|
| 1478 |
+
} catch (err) {
|
| 1479 |
+
console.error('PDF Generation failed:', err);
|
| 1480 |
+
btn.innerHTML = '<i class="fas fa-times"></i> Failed';
|
| 1481 |
+
} finally {
|
| 1482 |
+
setTimeout(() => {
|
| 1483 |
+
btn.innerHTML = orig;
|
| 1484 |
+
btn.disabled = false;
|
| 1485 |
+
}, 2000);
|
| 1486 |
+
}
|
|
|
|
| 1487 |
}
|
| 1488 |
|
| 1489 |
function setActiveTab(tab) {
|