File size: 1,476 Bytes
9cc9e49
7cf7ce2
 
b527adb
6f058fb
7cf7ce2
 
6f058fb
9cc9e49
7cf7ce2
 
 
 
 
 
 
6f058fb
9cc9e49
 
 
 
 
 
 
 
6f058fb
9cc9e49
 
7cf7ce2
 
 
9cc9e49
e7f5f1e
 
b527adb
 
 
 
 
 
9cc9e49
1
2
3
4
5
6
7
8
9
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
37
38
39
40
41
42
<input type="file" id="fileInput" multiple>
<input type="text" id="repoInput" placeholder="Enter repo">
<input type="password" id="accessTokenInput" placeholder="Enter access token">
<button id="uploadButton">Upload</button>

<script type="module">
    import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";

    async function upload() {
        const fileInput = document.getElementById('fileInput');
        const repoInput = document.getElementById('repoInput');
        const accessTokenInput = document.getElementById('accessTokenInput');
        
        const files = Array.from(fileInput.files); // Convert FileList to an Array
        const repo = repoInput.value;
        const accessToken = accessTokenInput.value;

        // Prompt the user for a unique upload path for each file
        const filesToUpload = await Promise.all(files.map(async (file) => {
            const path = prompt(`Enter the upload path for ${file.name}`);
            return {
                path,
                content: file,
            };
        }));

        await uploadFiles({
            repo,
            credentials: {
                accessToken,
            },
            files: filesToUpload,
        });
    }

    // Attach the function to the window object
    window.upload = upload;

    // Attach the event listener to the button
    document.getElementById('uploadButton').addEventListener('click', upload);
</script>