prithivMLmods commited on
Commit
eac8670
·
verified ·
1 Parent(s): 2a185a4

update app

Browse files
Files changed (1) hide show
  1. 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
- let avatarDataUrl = null;
 
1334
  if (p?.avatarUrl) {
1335
- const fullUrl = p.avatarUrl.startsWith('http') ? p.avatarUrl : `https://huggingface.co${p.avatarUrl}`;
1336
  try {
1337
- let res = await fetch(fullUrl);
1338
- if (!res.ok) throw new Error();
1339
- let blob = await res.blob();
1340
- avatarDataUrl = await new Promise((resolve) => {
1341
- const reader = new FileReader();
1342
- reader.onload = () => resolve(reader.result);
1343
- reader.onerror = () => resolve(null);
1344
- reader.readAsDataURL(blob);
1345
- });
1346
- } catch(e) {
1347
- try {
1348
- let res = await fetch(`https://corsproxy.io/?${encodeURIComponent(fullUrl)}`);
1349
- if (res.ok) {
1350
- let blob = await res.blob();
1351
- avatarDataUrl = await new Promise((resolve) => {
1352
- const reader = new FileReader();
1353
- reader.onload = () => resolve(reader.result);
1354
- reader.onerror = () => resolve(null);
1355
- reader.readAsDataURL(blob);
1356
- });
1357
- }
1358
- } catch(err) {}
 
 
 
 
1359
  }
1360
  }
1361
 
1362
- let textX = 14;
1363
- if (avatarDataUrl) {
1364
- try {
1365
- let imgFormat = avatarDataUrl.substring("data:image/".length, avatarDataUrl.indexOf(";")).toUpperCase();
1366
- if (imgFormat === 'SVG+XML' || imgFormat.includes('SVG')) imgFormat = 'PNG'; // SVGs are tricky, force to PNG if converted
1367
- doc.addImage(avatarDataUrl, imgFormat, 14, 15, 24, 24);
1368
- textX = 42;
1369
- } catch(e) {
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(`Followers: ${p?.numFollowers ?? 0} | Organizations: ${Array.isArray(p?.orgs) ? p.orgs.length : 0}`, 14, 48);
1385
-
1386
- const totalModels = state.models.length;
1387
- const totalDatasets = state.datasets.length;
1388
- const totalSpaces = state.spaces.length;
1389
-
1390
- const totalModelDl = state.models.reduce((s, m) => s + getLifetimeDownloads(m), 0);
1391
- const totalDatasetDl = state.datasets.reduce((s, d) => s + getLifetimeDownloads(d), 0);
1392
- const totalLikes = [...state.models, ...state.datasets, ...state.spaces].reduce((s, i) => s + getItemLikes(i), 0);
1393
-
1394
- doc.text(`Total Models: ${totalModels} (Downloads: ${formatNumFull(totalModelDl)})`, 14, 56);
1395
- doc.text(`Total Datasets: ${totalDatasets} (Downloads: ${formatNumFull(totalDatasetDl)})`, 14, 64);
1396
- doc.text(`Total Spaces: ${totalSpaces}`, 14, 72);
1397
- doc.text(`Total Likes Received: ${formatNumFull(totalLikes)}`, 14, 80);
1398
-
1399
- const totalDlMonthly = state.models.reduce((s, m) => s + getMonthlyDownloads(m), 0) + state.datasets.reduce((s, d) => s + getMonthlyDownloads(d), 0);
1400
- doc.text(`Downloads Last 30 Days: ${formatNumFull(totalDlMonthly)}`, 14, 88);
1401
-
1402
- const totalPrivate = [...state.models, ...state.datasets, ...state.spaces].filter(i => i.private).length;
1403
- doc.text(`Total Private Repositories: ${totalPrivate}`, 14, 96);
1404
- let startY = 106;
 
 
 
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
- } catch (err) {
1483
- console.error('PDF Generation failed:', err);
1484
- btn.innerHTML = '<i class="fas fa-times"></i> Failed';
1485
- } finally {
1486
- setTimeout(() => {
1487
- btn.innerHTML = orig;
1488
- btn.disabled = false;
1489
- }, 2000);
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) {