Spaces:
Running
Running
Commit
·
3e75ed6
1
Parent(s):
2448fe7
Update index.html
Browse files- index.html +18 -23
index.html
CHANGED
@@ -31,12 +31,12 @@
|
|
31 |
<div id="error"></div>
|
32 |
|
33 |
<script type="module">
|
34 |
-
import { createRepo,
|
35 |
|
36 |
const uploadButton = document.getElementById('uploadButton');
|
37 |
-
uploadButton.addEventListener('click',
|
38 |
|
39 |
-
async function
|
40 |
const fileInput = document.getElementById('fileUpload');
|
41 |
const files = Array.from(fileInput.files); // convert FileList to Array
|
42 |
const tokenInput = document.getElementById('tokenInput');
|
@@ -80,27 +80,22 @@
|
|
80 |
}
|
81 |
}
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
credentials: { accessToken: HF_ACCESS_TOKEN },
|
91 |
-
file: file,
|
92 |
-
commitTitle: `committing file: ${file.name}`,
|
93 |
-
});
|
94 |
|
95 |
-
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
}
|
104 |
}
|
105 |
|
106 |
// calculate elapsed time and speed
|
@@ -112,7 +107,7 @@
|
|
112 |
let time5GB = (5 * 1024 / speed) / 60;
|
113 |
let time10GB = (10 * 1024 / speed) / 60;
|
114 |
|
115 |
-
messageDiv.innerHTML = `All files uploaded successfully in ${elapsedTime.toFixed(2)} seconds, for all ${totalSize.toFixed(2)} MB in the ${files.length} files, speed ${speed.toFixed(2)} MB/s
|
116 |
processingMessage.textContent = "All files processed";
|
117 |
} else {
|
118 |
messageDiv.textContent = 'Please select files to upload';
|
|
|
31 |
<div id="error"></div>
|
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 |
+
async function upload() {
|
40 |
const fileInput = document.getElementById('fileUpload');
|
41 |
const files = Array.from(fileInput.files); // convert FileList to Array
|
42 |
const tokenInput = document.getElementById('tokenInput');
|
|
|
80 |
}
|
81 |
}
|
82 |
|
83 |
+
try {
|
84 |
+
// upload files
|
85 |
+
await uploadFiles({
|
86 |
+
repo: REPO_ID,
|
87 |
+
credentials: { accessToken: HF_ACCESS_TOKEN },
|
88 |
+
files: files.map(file => ({path: file.name, content: file}))
|
89 |
+
});
|
|
|
|
|
|
|
|
|
90 |
|
91 |
+
console.log(`All files uploaded successfully`);
|
92 |
|
93 |
+
// update progress bar
|
94 |
+
progressBar.value = 100;
|
95 |
+
} catch (error) {
|
96 |
+
console.error('Error uploading files', error);
|
97 |
+
errorDiv.textContent = 'Error uploading files';
|
98 |
+
return; // stop uploading further files on error
|
|
|
99 |
}
|
100 |
|
101 |
// calculate elapsed time and speed
|
|
|
107 |
let time5GB = (5 * 1024 / speed) / 60;
|
108 |
let time10GB = (10 * 1024 / speed) / 60;
|
109 |
|
110 |
+
messageDiv.innerHTML = `All files uploaded successfully in ${elapsedTime.toFixed(2)} seconds, for all ${totalSize.toFixed(2)} MB in the ${files.length} files, speed ${speed.toFixed(2)} MB/s.`;
|
111 |
processingMessage.textContent = "All files processed";
|
112 |
} else {
|
113 |
messageDiv.textContent = 'Please select files to upload';
|