Spaces:
Running
Running
Commit
·
9324a72
1
Parent(s):
4ce2f01
Update index.html
Browse files- index.html +26 -12
index.html
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<input type="file" id="fileInput" multiple>
|
2 |
<input type="text" id="repoInput" placeholder="Enter repo">
|
3 |
<input type="password" id="accessTokenInput" placeholder="Enter access token">
|
4 |
<button id="uploadButton">Upload</button>
|
@@ -6,27 +6,41 @@
|
|
6 |
<script type="module">
|
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 |
-
|
22 |
-
|
23 |
-
|
24 |
-
// Append the original filename and extension to the folder name
|
25 |
-
const path = `${folderName}/${file.name}`;
|
26 |
-
return {
|
27 |
-
path,
|
28 |
-
content: file,
|
29 |
-
};
|
30 |
}));
|
31 |
|
32 |
const result = await uploadFiles({
|
|
|
1 |
+
<input type="file" id="fileInput" webkitdirectory multiple>
|
2 |
<input type="text" id="repoInput" placeholder="Enter repo">
|
3 |
<input type="password" id="accessTokenInput" placeholder="Enter access token">
|
4 |
<button id="uploadButton">Upload</button>
|
|
|
6 |
<script type="module">
|
7 |
import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
|
8 |
|
9 |
+
function traverseFileTree(item, path) {
|
10 |
+
path = path || "";
|
11 |
+
return new Promise(resolve => {
|
12 |
+
if (item.isFile) {
|
13 |
+
// Get file
|
14 |
+
item.file(file => {
|
15 |
+
file.webkitRelativePath = path + file.name;
|
16 |
+
resolve(file);
|
17 |
+
});
|
18 |
+
} else if (item.isDirectory) {
|
19 |
+
// Get folder contents
|
20 |
+
item.createReader().readEntries(entries => {
|
21 |
+
Promise.all(entries.map(entry => traverseFileTree(entry, path + item.name + "/")))
|
22 |
+
.then(files => resolve([].concat(...files)));
|
23 |
+
});
|
24 |
+
}
|
25 |
+
});
|
26 |
+
}
|
27 |
+
|
28 |
async function upload() {
|
29 |
try {
|
30 |
const fileInput = document.getElementById('fileInput');
|
31 |
const repoInput = document.getElementById('repoInput');
|
32 |
const accessTokenInput = document.getElementById('accessTokenInput');
|
33 |
+
|
|
|
34 |
const repo = repoInput.value;
|
35 |
const accessToken = accessTokenInput.value;
|
36 |
|
37 |
+
const entries = Array.from(fileInput.files).map(file => file.webkitGetAsEntry());
|
38 |
+
const files = [].concat(...await Promise.all(entries.map(entry => traverseFileTree(entry))));
|
39 |
console.log(`Uploading ${files.length} file(s) to ${repo} with access token ${accessToken.substr(0, 4)}...`);
|
40 |
|
41 |
+
const filesToUpload = files.map(file => ({
|
42 |
+
path: file.webkitRelativePath,
|
43 |
+
content: file,
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
}));
|
45 |
|
46 |
const result = await uploadFiles({
|