multimodalart HF Staff commited on
Commit
adcc53f
·
1 Parent(s): 657ac04

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +11 -2
index.html CHANGED
@@ -32,15 +32,18 @@
32
 
33
  <script type="module">
34
  import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
35
-
36
  const uploadButton = document.getElementById('uploadButton');
37
  uploadButton.addEventListener('click', upload);
38
 
39
  // Override global fetch
40
  const originalFetch = window.fetch;
 
 
41
 
42
  window.fetch = function(url, init) {
43
  if (typeof url === 'string' && init && init.method === 'PUT') {
 
44
  return new Promise((resolve, reject) => {
45
  const xhr = new XMLHttpRequest();
46
  xhr.open(init.method, url);
@@ -63,9 +66,15 @@
63
 
64
  xhr.upload.onprogress = (event) => {
65
  if (event.lengthComputable) {
66
- const progress = event.loaded / event.total;
 
67
  const progressBar = document.getElementById('progressBar');
68
  progressBar.value = progress * 100;
 
 
 
 
 
69
  }
70
  };
71
 
 
32
 
33
  <script type="module">
34
  import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
35
+
36
  const uploadButton = document.getElementById('uploadButton');
37
  uploadButton.addEventListener('click', upload);
38
 
39
  // Override global fetch
40
  const originalFetch = window.fetch;
41
+ let uploadStartTime;
42
+ let uploadedBytes = 0;
43
 
44
  window.fetch = function(url, init) {
45
  if (typeof url === 'string' && init && init.method === 'PUT') {
46
+ uploadStartTime = uploadStartTime || Date.now();
47
  return new Promise((resolve, reject) => {
48
  const xhr = new XMLHttpRequest();
49
  xhr.open(init.method, url);
 
66
 
67
  xhr.upload.onprogress = (event) => {
68
  if (event.lengthComputable) {
69
+ uploadedBytes += event.loaded;
70
+ const progress = uploadedBytes / event.total;
71
  const progressBar = document.getElementById('progressBar');
72
  progressBar.value = progress * 100;
73
+
74
+ const speedDiv = document.getElementById('uploadSpeed');
75
+ const elapsedTime = (Date.now() - uploadStartTime) / 1000; // in seconds
76
+ const speed = uploadedBytes / elapsedTime; // in bytes per second
77
+ speedDiv.textContent = `Upload speed: ${(speed / 1024 / 1024).toFixed(2)} MB/s`;
78
  }
79
  };
80