Spaces:
Running
Running
Commit
·
e284d85
1
Parent(s):
b527adb
Update index.html
Browse files- index.html +32 -24
index.html
CHANGED
@@ -7,30 +7,38 @@
|
|
7 |
import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
|
8 |
|
9 |
async function upload() {
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
}
|
35 |
|
36 |
// Attach the function to the window object
|
|
|
7 |
import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
|
8 |
|
9 |
async function upload() {
|
10 |
+
try {
|
11 |
+
const fileInput = document.getElementById('fileInput');
|
12 |
+
const repoInput = document.getElementById('repoInput');
|
13 |
+
const accessTokenInput = document.getElementById('accessTokenInput');
|
14 |
+
|
15 |
+
const files = Array.from(fileInput.files); // Convert FileList to an Array
|
16 |
+
const repo = repoInput.value;
|
17 |
+
const accessToken = accessTokenInput.value;
|
18 |
+
|
19 |
+
console.log(`Uploading ${files.length} file(s) to ${repo} with access token ${accessToken.substr(0, 4)}...`);
|
20 |
+
|
21 |
+
// Prompt the user for a unique upload path for each file
|
22 |
+
const filesToUpload = await Promise.all(files.map(async (file) => {
|
23 |
+
const path = prompt(`Enter the upload path for ${file.name}`);
|
24 |
+
return {
|
25 |
+
path,
|
26 |
+
content: file,
|
27 |
+
};
|
28 |
+
}));
|
29 |
+
|
30 |
+
const result = await uploadFiles({
|
31 |
+
repo,
|
32 |
+
credentials: {
|
33 |
+
accessToken,
|
34 |
+
},
|
35 |
+
files: filesToUpload,
|
36 |
+
});
|
37 |
+
|
38 |
+
console.log('Upload successful:', result);
|
39 |
+
} catch (error) {
|
40 |
+
console.error('An error occurred:', error);
|
41 |
+
}
|
42 |
}
|
43 |
|
44 |
// Attach the function to the window object
|