File size: 11,380 Bytes
a2c64e7 | 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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | <!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vico - Hugging Face Upload</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.container {
background: white;
border-radius: 10px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
max-width: 600px;
width: 100%;
padding: 40px;
}
h1 {
color: #333;
margin-bottom: 10px;
font-size: 28px;
}
.subtitle {
color: #666;
margin-bottom: 30px;
font-size: 14px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
color: #333;
font-weight: 600;
font-size: 14px;
}
input[type="text"],
input[type="password"],
textarea {
width: 100%;
padding: 12px;
border: 2px solid #e0e0e0;
border-radius: 5px;
font-size: 14px;
transition: border-color 0.3s;
font-family: 'Courier New', monospace;
}
input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
outline: none;
border-color: #667eea;
}
input[type="file"] {
padding: 10px;
border: 2px dashed #667eea;
border-radius: 5px;
cursor: pointer;
}
.file-input-wrapper {
position: relative;
overflow: hidden;
}
button {
width: 100%;
padding: 12px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s, box-shadow 0.2s;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}
button:disabled {
opacity: 0.6;
cursor: not-allowed;
transform: none;
}
.loading {
display: none;
text-align: center;
margin: 20px 0;
}
.spinner {
border: 3px solid #f3f3f3;
border-top: 3px solid #667eea;
border-radius: 50%;
width: 30px;
height: 30px;
animation: spin 1s linear infinite;
margin: 0 auto 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.result {
display: none;
margin-top: 20px;
padding: 15px;
border-radius: 5px;
font-size: 14px;
}
.result.success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.result.error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.result-content {
margin-top: 10px;
background: rgba(255, 255, 255, 0.5);
padding: 10px;
border-radius: 3px;
overflow-x: auto;
font-family: 'Courier New', monospace;
font-size: 12px;
}
.file-info {
display: none;
background: #f5f5f5;
padding: 10px;
border-radius: 5px;
margin-bottom: 10px;
font-size: 13px;
color: #666;
}
.file-info.show {
display: block;
}
.helper-text {
font-size: 12px;
color: #999;
margin-top: 5px;
}
</style>
</head>
<body>
<div class="container">
<h1>π Vico</h1>
<p class="subtitle">Upload file ke Hugging Face Dataset</p>
<form id="uploadForm">
<!-- Hugging Face Token -->
<div class="form-group">
<label for="token">Hugging Face Token *</label>
<input
type="password"
id="token"
placeholder="hf_xxxxxxxxxxxxxxxxxxxxxxx"
required
>
<p class="helper-text">
Dapatkan di: <a href="https://huggingface.co/settings/tokens" target="_blank">
huggingface.co/settings/tokens</a>
</p>
</div>
<!-- Repository ID -->
<div class="form-group">
<label for="repoId">Repository ID *</label>
<input
type="text"
id="repoId"
placeholder="username/dataset-name"
required
>
<p class="helper-text">Format: username/dataset-name (lowercase)</p>
</div>
<!-- Subfolder -->
<div class="form-group">
<label for="subfolder">Subfolder (Opsional)</label>
<input
type="text"
id="subfolder"
placeholder="data, datasets, dll"
>
<p class="helper-text">Biarkan kosong untuk upload ke root</p>
</div>
<!-- File Upload -->
<div class="form-group">
<label for="file">Pilih File *</label>
<div class="file-input-wrapper">
<input
type="file"
id="file"
required
>
</div>
<div id="fileInfo" class="file-info">
<span id="fileName"></span>
(<span id="fileSize"></span>)
</div>
</div>
<!-- Submit Button -->
<button type="submit" id="submitBtn">Upload File</button>
<!-- Loading State -->
<div class="loading" id="loading">
<div class="spinner"></div>
<p>Mengupload...</p>
</div>
<!-- Result Message -->
<div class="result" id="result">
<div id="resultContent"></div>
</div>
</form>
</div>
<script>
const API_URL = 'http://localhost:3000/api/upload';
// File input handler
document.getElementById('file').addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const fileInfo = document.getElementById('fileInfo');
document.getElementById('fileName').textContent = file.name;
document.getElementById('fileSize').textContent = formatFileSize(file.size);
fileInfo.classList.add('show');
}
});
// Format file size
function formatFileSize(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
}
// Form submit handler
document.getElementById('uploadForm').addEventListener('submit', async function(e) {
e.preventDefault();
const file = document.getElementById('file').files[0];
const token = document.getElementById('token').value;
const repoId = document.getElementById('repoId').value;
const subfolder = document.getElementById('subfolder').value;
if (!file || !token || !repoId) {
alert('Harap isi semua field yang diperlukan');
return;
}
// Show loading state
const submitBtn = document.getElementById('submitBtn');
const loading = document.getElementById('loading');
const result = document.getElementById('result');
submitBtn.disabled = true;
loading.style.display = 'block';
result.style.display = 'none';
try {
// Create FormData
const formData = new FormData();
formData.append('file', file);
formData.append('repo_id', repoId);
formData.append('token', token);
if (subfolder) {
formData.append('subfolder', subfolder);
}
// Upload
const response = await fetch(API_URL, {
method: 'POST',
body: formData
});
const data = await response.json();
// Show result
if (data.success) {
result.classList.remove('error');
result.classList.add('success');
result.innerHTML = `
<strong>β
${data.message}</strong>
<div class="result-content">
<strong>File:</strong> ${data.data.file_name}<br>
<strong>Size:</strong> ${formatFileSize(data.data.file_size)}<br>
<strong>Repo:</strong> ${data.data.repo_id}<br>
<strong>URL:</strong> <a href="${data.data.url}" target="_blank">${data.data.url}</a><br>
<strong>Time:</strong> ${new Date(data.data.upload_timestamp).toLocaleString('id-ID')}
</div>
`;
} else {
result.classList.remove('success');
result.classList.add('error');
result.innerHTML = `
<strong>β ${data.error}</strong>
<div class="result-content">${JSON.stringify(data, null, 2)}</div>
`;
}
result.style.display = 'block';
} catch (error) {
result.classList.remove('success');
result.classList.add('error');
result.innerHTML = `
<strong>β Error: ${error.message}</strong>
<div class="result-content">
Pastikan API server berjalan di ${API_URL}
</div>
`;
result.style.display = 'block';
} finally {
submitBtn.disabled = false;
loading.style.display = 'none';
}
});
</script>
</body>
</html>
|