Spaces:
Running
Running
Commit
·
59695de
1
Parent(s):
3e75ed6
Update index.html
Browse files- index.html +48 -68
index.html
CHANGED
|
@@ -33,86 +33,66 @@
|
|
| 33 |
<script type="module">
|
| 34 |
import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.8.3/+esm";
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 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 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
totalSize += file.size;
|
| 60 |
-
}
|
| 61 |
-
totalSize = totalSize / (1024 * 1024); // convert to MB
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
repo
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 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 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
|
|
|
| 90 |
|
| 91 |
-
|
|
|
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
}
|
| 96 |
-
|
| 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.`;
|
| 111 |
-
processingMessage.textContent = "All files processed";
|
| 112 |
-
} else {
|
| 113 |
-
messageDiv.textContent = 'Please select files to upload';
|
| 114 |
}
|
| 115 |
}
|
|
|
|
|
|
|
| 116 |
</script>
|
| 117 |
</body>
|
| 118 |
</html>
|
|
|
|
| 33 |
<script type="module">
|
| 34 |
import { createRepo, uploadFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.8.3/+esm";
|
| 35 |
|
| 36 |
+
class FileUploader {
|
| 37 |
+
constructor() {
|
| 38 |
+
this.uploadButton = document.getElementById('uploadButton');
|
| 39 |
+
this.uploadButton.addEventListener('click', () => this.upload());
|
| 40 |
+
}
|
| 41 |
|
| 42 |
+
async upload() {
|
| 43 |
+
const fileInput = document.getElementById('fileUpload');
|
| 44 |
+
const files = Array.from(fileInput.files);
|
| 45 |
+
const tokenInput = document.getElementById('tokenInput');
|
| 46 |
+
const HF_ACCESS_TOKEN = tokenInput.value;
|
| 47 |
+
const repoInput = document.getElementById('repoInput');
|
| 48 |
+
const REPO_ID = repoInput.value;
|
| 49 |
+
const progressBar = document.getElementById('progressBar');
|
| 50 |
+
const messageDiv = document.getElementById('message');
|
| 51 |
+
const errorDiv = document.getElementById('error');
|
| 52 |
+
const processingMessage = document.getElementById('processingMessage');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
progressBar.value = 0;
|
| 55 |
+
messageDiv.textContent = '';
|
| 56 |
+
errorDiv.textContent = '';
|
| 57 |
+
processingMessage.textContent = '';
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
if (files.length > 0) {
|
| 60 |
+
const totalSize = files.reduce((total, file) => total + file.size, 0) / (1024 * 1024);
|
| 61 |
+
const startTime = Date.now();
|
| 62 |
|
| 63 |
+
try {
|
| 64 |
+
await createRepo({ repo: REPO_ID, credentials: { accessToken: HF_ACCESS_TOKEN } });
|
| 65 |
+
} catch (error) {
|
| 66 |
+
if (error.message !== 'You already created this model repo') {
|
| 67 |
+
console.error('Error creating repository', error);
|
| 68 |
+
errorDiv.textContent = 'Error creating repository';
|
| 69 |
+
return;
|
| 70 |
+
}
|
|
|
|
| 71 |
console.log('Repository already exists, proceeding to upload files');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
}
|
|
|
|
| 73 |
|
| 74 |
+
try {
|
| 75 |
+
await uploadFiles({ repo: REPO_ID, credentials: { accessToken: HF_ACCESS_TOKEN }, files: files.map(file => ({ path: file.name, content: file })) });
|
| 76 |
+
console.log('All files uploaded successfully');
|
| 77 |
+
progressBar.value = 100;
|
| 78 |
+
} catch (error) {
|
| 79 |
+
console.error('Error uploading files', error);
|
| 80 |
+
errorDiv.textContent = 'Error uploading files';
|
| 81 |
+
return;
|
| 82 |
+
}
|
| 83 |
|
| 84 |
+
const elapsedTime = (Date.now() - startTime) / 1000;
|
| 85 |
+
const speed = totalSize / elapsedTime;
|
| 86 |
|
| 87 |
+
messageDiv.textContent = `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.`;
|
| 88 |
+
processingMessage.textContent = "All files processed";
|
| 89 |
+
} else {
|
| 90 |
+
messageDiv.textContent = 'Please select files to upload';
|
|
|
|
|
|
|
| 91 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
}
|
| 94 |
+
|
| 95 |
+
new FileUploader();
|
| 96 |
</script>
|
| 97 |
</body>
|
| 98 |
</html>
|