multimodalart HF Staff commited on
Commit
e284d85
·
1 Parent(s): b527adb

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- const fileInput = document.getElementById('fileInput');
11
- const repoInput = document.getElementById('repoInput');
12
- const accessTokenInput = document.getElementById('accessTokenInput');
13
-
14
- const files = Array.from(fileInput.files); // Convert FileList to an Array
15
- const repo = repoInput.value;
16
- const accessToken = accessTokenInput.value;
17
-
18
- // Prompt the user for a unique upload path for each file
19
- const filesToUpload = await Promise.all(files.map(async (file) => {
20
- const path = prompt(`Enter the upload path for ${file.name}`);
21
- return {
22
- path,
23
- content: file,
24
- };
25
- }));
26
-
27
- await uploadFiles({
28
- repo,
29
- credentials: {
30
- accessToken,
31
- },
32
- files: filesToUpload,
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