Spaces:
Running
Running
Commit
·
6d312fd
1
Parent(s):
9f613b3
Update index.html
Browse files- index.html +115 -16
index.html
CHANGED
@@ -1,19 +1,118 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
</html>
|
|
|
1 |
<!DOCTYPE html>
|
2 |
<html>
|
3 |
+
<head>
|
4 |
+
<style>
|
5 |
+
body {
|
6 |
+
font-family: Arial, sans-serif;
|
7 |
+
}
|
8 |
+
input, button, progress {
|
9 |
+
display: block;
|
10 |
+
margin-top: 10px;
|
11 |
+
}
|
12 |
+
#message {
|
13 |
+
margin-top: 20px;
|
14 |
+
color: blue;
|
15 |
+
}
|
16 |
+
#error {
|
17 |
+
color: red;
|
18 |
+
}
|
19 |
+
</style>
|
20 |
+
</head>
|
21 |
+
<body>
|
22 |
+
<label for="tokenInput">Hugging Face Token:</label>
|
23 |
+
<input type="password" id="tokenInput" name="tokenInput">
|
24 |
+
<label for="repoInput">Repository ID:</label>
|
25 |
+
<input type="text" id="repoInput" name="repoInput" placeholder="my-user/nlp-model">
|
26 |
+
<input type="file" id="fileUpload" multiple>
|
27 |
+
<button id="uploadButton">Upload Files</button>
|
28 |
+
<div id="processingMessage"></div>
|
29 |
+
<progress id="progressBar" value="0" max="100"></progress>
|
30 |
+
<div id="message"></div>
|
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');
|
43 |
+
const HF_ACCESS_TOKEN = tokenInput.value; // get the entered token
|
44 |
+
const repoInput = document.getElementById('repoInput');
|
45 |
+
const REPO_ID = repoInput.value; // get the entered repo id
|
46 |
+
const progressBar = document.getElementById('progressBar');
|
47 |
+
const messageDiv = document.getElementById('message');
|
48 |
+
const errorDiv = document.getElementById('error');
|
49 |
+
const processingMessage = document.getElementById('processingMessage');
|
50 |
+
progressBar.value = 0; // reset progress bar
|
51 |
+
messageDiv.textContent = ''; // clear previous messages
|
52 |
+
errorDiv.textContent = ''; // clear previous errors
|
53 |
+
processingMessage.textContent = ''; // clear previous processing message
|
54 |
+
|
55 |
+
if (files.length > 0) {
|
56 |
+
// calculate total size in MB
|
57 |
+
let totalSize = 0;
|
58 |
+
for (let file of files) {
|
59 |
+
totalSize += file.size;
|
60 |
+
}
|
61 |
+
totalSize = totalSize / (1024 * 1024); // convert to MB
|
62 |
+
|
63 |
+
// start time
|
64 |
+
const startTime = Date.now();
|
65 |
+
|
66 |
+
try {
|
67 |
+
// Attempt to create the repo
|
68 |
+
await createRepo({
|
69 |
+
repo: REPO_ID,
|
70 |
+
credentials: { accessToken: HF_ACCESS_TOKEN },
|
71 |
+
});
|
72 |
+
} catch (error) {
|
73 |
+
// If the repo already exists, we simply log and continue
|
74 |
+
if (error.message === 'You already created this model repo') {
|
75 |
+
console.log('Repository already exists, proceeding to upload files');
|
76 |
+
} else {
|
77 |
+
console.error('Error creating repository', error);
|
78 |
+
errorDiv.textContent = 'Error creating repository';
|
79 |
+
return; // stop if other errors occur during repository creation
|
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
|
102 |
+
const elapsedTime = (Date.now() - startTime) / 1000; // in seconds
|
103 |
+
let speed = totalSize / elapsedTime; // in MB/s
|
104 |
+
|
105 |
+
// Estimate time to upload larger files in minutes
|
106 |
+
let time1GB = (1024 / speed) / 60;
|
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.<br>To upload a 1GB model at this speed, it would take approximately ${time1GB.toFixed(2)} minutes.<br>To upload a 5GB model at this speed, it would take approximately ${time5GB.toFixed(2)} minutes.<br>To upload a 10GB model at this speed, it would take approximately ${time10GB.toFixed(2)} minutes.`;
|
111 |
+
processingMessage.textContent = "All files processed";
|
112 |
+
} else {
|
113 |
+
messageDiv.textContent = 'Please select files to upload';
|
114 |
+
}
|
115 |
+
}
|
116 |
+
</script>
|
117 |
+
</body>
|
118 |
</html>
|