Spaces:
Running
Running
File size: 29,483 Bytes
e4d6c26 |
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 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Model Trainer | Hugging Face Space</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.file-upload:hover {
background-color: #f0f0f0;
border-color: #d1d5db;
}
.progress-bar {
transition: width 0.3s ease-in-out;
}
.model-card:hover {
transform: translateY(-2px);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}
.animate-pulse {
animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
0%, 100% {
opacity: 1;
}
50% {
opacity: 0.5;
}
}
</style>
</head>
<body class="bg-gray-50 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-6xl">
<!-- Header -->
<header class="flex items-center justify-between mb-8">
<div class="flex items-center space-x-3">
<div class="bg-purple-600 p-2 rounded-lg">
<i class="fas fa-robot text-white text-2xl"></i>
</div>
<h1 class="text-2xl font-bold text-gray-800">Model Trainer</h1>
</div>
<div class="flex items-center space-x-4">
<button class="px-4 py-2 bg-gray-200 hover:bg-gray-300 rounded-lg text-gray-700 font-medium transition">
<i class="fas fa-question-circle mr-2"></i>Help
</button>
<button class="px-4 py-2 bg-purple-600 hover:bg-purple-700 rounded-lg text-white font-medium transition">
<i class="fas fa-user mr-2"></i>Sign In
</button>
</div>
</header>
<!-- Main Content -->
<main class="bg-white rounded-xl shadow-md overflow-hidden">
<!-- Model Selection Section -->
<section class="p-6 border-b border-gray-200">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Select Model</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- Model Cards -->
<div class="model-card bg-gray-50 p-4 rounded-lg border border-gray-200 cursor-pointer transition hover:border-purple-400" onclick="selectModel('gpt-3.5-turbo')">
<div class="flex items-center mb-3">
<div class="bg-blue-100 p-2 rounded-full mr-3">
<i class="fas fa-brain text-blue-600"></i>
</div>
<h3 class="font-medium text-gray-800">GPT-3.5 Turbo</h3>
</div>
<p class="text-sm text-gray-600 mb-3">Most capable GPT-3.5 model optimized for chat at 1/10th the cost of text-davinci-003.</p>
<div class="flex justify-between text-xs text-gray-500">
<span><i class="fas fa-memory mr-1"></i> 175B params</span>
<span><i class="fas fa-calendar mr-1"></i> Jun 2021</span>
</div>
</div>
<div class="model-card bg-gray-50 p-4 rounded-lg border border-gray-200 cursor-pointer transition hover:border-purple-400" onclick="selectModel('llama-2-7b')">
<div class="flex items-center mb-3">
<div class="bg-green-100 p-2 rounded-full mr-3">
<i class="fas fa-hippo text-green-600"></i>
</div>
<h3 class="font-medium text-gray-800">LLaMA 2 7B</h3>
</div>
<p class="text-sm text-gray-600 mb-3">Open source model from Meta with 7 billion parameters, fine-tuned for chat.</p>
<div class="flex justify-between text-xs text-gray-500">
<span><i class="fas fa-memory mr-1"></i> 7B params</span>
<span><i class="fas fa-calendar mr-1"></i> Jul 2023</span>
</div>
</div>
<div class="model-card bg-gray-50 p-4 rounded-lg border border-gray-200 cursor-pointer transition hover:border-purple-400" onclick="selectModel('mistral-7b')">
<div class="flex items-center mb-3">
<div class="bg-orange-100 p-2 rounded-full mr-3">
<i class="fas fa-wind text-orange-600"></i>
</div>
<h3 class="font-medium text-gray-800">Mistral 7B</h3>
</div>
<p class="text-sm text-gray-600 mb-3">Most capable 7B model to date, outperforming larger models on many benchmarks.</p>
<div class="flex justify-between text-xs text-gray-500">
<span><i class="fas fa-memory mr-1"></i> 7B params</span>
<span><i class="fas fa-calendar mr-1"></i> Sep 2023</span>
</div>
</div>
</div>
<!-- Dropdown for additional models -->
<div class="mt-4">
<label for="model-select" class="block text-sm font-medium text-gray-700 mb-1">Or select another model:</label>
<select id="model-select" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500">
<option value="">-- Select a model --</option>
<option value="gpt-4">GPT-4</option>
<option value="claude-2">Claude 2</option>
<option value="palm-2">PaLM 2</option>
<option value="falcon-40b">Falcon 40B</option>
<option value="bloom-176b">BLOOM 176B</option>
</select>
</div>
</section>
<!-- File Upload Section -->
<section class="p-6 border-b border-gray-200">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Upload Training Data</h2>
<div class="file-upload border-2 border-dashed border-gray-300 rounded-lg p-8 text-center cursor-pointer transition" id="drop-area">
<div class="flex flex-col items-center justify-center">
<i class="fas fa-cloud-upload-alt text-4xl text-gray-400 mb-3"></i>
<p class="text-gray-600 mb-1">Drag & drop files here or click to browse</p>
<p class="text-sm text-gray-500">Supported formats: PDF, TXT, DOCX, PPT, CSV (Max 10 files, 100MB total)</p>
<input type="file" id="file-input" class="hidden" multiple accept=".pdf,.txt,.docx,.ppt,.pptx,.csv,.xlsx">
<button id="browse-btn" class="mt-4 px-4 py-2 bg-purple-600 hover:bg-purple-700 rounded-lg text-white font-medium transition">
<i class="fas fa-folder-open mr-2"></i>Browse Files
</button>
</div>
</div>
<!-- Uploaded Files Preview -->
<div id="file-preview" class="mt-6 hidden">
<h3 class="font-medium text-gray-700 mb-3">Selected Files:</h3>
<div id="file-list" class="space-y-2"></div>
</div>
</section>
<!-- System Prompt Section -->
<section class="p-6 border-b border-gray-200">
<h2 class="text-xl font-semibold text-gray-800 mb-4">System Prompt</h2>
<div class="mb-4">
<label for="system-prompt" class="block text-sm font-medium text-gray-700 mb-1">Customize the model's behavior:</label>
<textarea id="system-prompt" rows="4" class="w-full p-3 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500" placeholder="Example: You are a helpful assistant specialized in legal documents. Provide detailed answers with references to the uploaded materials."></textarea>
</div>
<div class="flex flex-wrap gap-2">
<button onclick="insertPrompt('legal')" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded-full text-sm text-gray-700 transition">
<i class="fas fa-gavel mr-1"></i>Legal
</button>
<button onclick="insertPrompt('technical')" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded-full text-sm text-gray-700 transition">
<i class="fas fa-code mr-1"></i>Technical
</button>
<button onclick="insertPrompt('creative')" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded-full text-sm text-gray-700 transition">
<i class="fas fa-paint-brush mr-1"></i>Creative
</button>
<button onclick="insertPrompt('medical')" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded-full text-sm text-gray-700 transition">
<i class="fas fa-heartbeat mr-1"></i>Medical
</button>
<button onclick="insertPrompt('neutral')" class="px-3 py-1 bg-gray-100 hover:bg-gray-200 rounded-full text-sm text-gray-700 transition">
<i class="fas fa-balance-scale mr-1"></i>Neutral
</button>
</div>
</section>
<!-- Training Options Section -->
<section class="p-6">
<h2 class="text-xl font-semibold text-gray-800 mb-4">Training Options</h2>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Training Method:</label>
<select class="w-full p-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500">
<option>Fine-tuning</option>
<option>LoRA (Low-Rank Adaptation)</option>
<option>Prompt Tuning</option>
<option>Prefix Tuning</option>
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Epochs:</label>
<input type="number" min="1" max="10" value="3" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Learning Rate:</label>
<input type="number" step="0.0001" min="0.0001" max="0.01" value="0.001" class="w-full p-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Batch Size:</label>
<select class="w-full p-2 border border-gray-300 rounded-lg focus:ring-purple-500 focus:border-purple-500">
<option>8</option>
<option selected>16</option>
<option>32</option>
<option>64</option>
</select>
</div>
</div>
<!-- Start Training Button -->
<div class="mt-8">
<button id="train-btn" class="w-full py-3 bg-green-600 hover:bg-green-700 rounded-lg text-white font-bold text-lg transition flex items-center justify-center">
<i class="fas fa-play-circle mr-3"></i>Start Training
</button>
</div>
<!-- Training Progress -->
<div id="training-progress" class="mt-6 hidden">
<div class="flex justify-between mb-1">
<span class="text-sm font-medium text-gray-700">Training Progress</span>
<span id="progress-percent" class="text-sm font-medium text-gray-700">0%</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2.5">
<div id="progress-bar" class="progress-bar bg-green-600 h-2.5 rounded-full" style="width: 0%"></div>
</div>
<div id="training-status" class="mt-2 text-sm text-gray-600">Preparing to train...</div>
<div id="training-details" class="mt-4 hidden">
<div class="grid grid-cols-2 gap-4">
<div class="bg-gray-50 p-3 rounded-lg">
<div class="text-xs text-gray-500 mb-1">Current Epoch</div>
<div id="current-epoch" class="font-medium">1/3</div>
</div>
<div class="bg-gray-50 p-3 rounded-lg">
<div class="text-xs text-gray-500 mb-1">Loss</div>
<div id="current-loss" class="font-medium">0.00</div>
</div>
</div>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="mt-8 text-center text-gray-500 text-sm">
<p>© 2023 Model Trainer. Not affiliated with Hugging Face.</p>
<p class="mt-1">This is a demo interface. Actual training would require backend integration.</p>
</footer>
</div>
<script>
// Selected model tracking
let selectedModel = null;
// DOM elements
const dropArea = document.getElementById('drop-area');
const fileInput = document.getElementById('file-input');
const browseBtn = document.getElementById('browse-btn');
const filePreview = document.getElementById('file-preview');
const fileList = document.getElementById('file-list');
const trainBtn = document.getElementById('train-btn');
const trainingProgress = document.getElementById('training-progress');
const progressBar = document.getElementById('progress-bar');
const progressPercent = document.getElementById('progress-percent');
const trainingStatus = document.getElementById('training-status');
const trainingDetails = document.getElementById('training-details');
const systemPrompt = document.getElementById('system-prompt');
// Model selection
function selectModel(model) {
selectedModel = model;
// Update UI to show selected model
document.querySelectorAll('.model-card').forEach(card => {
card.classList.remove('border-purple-500', 'ring-2', 'ring-purple-200');
});
const selectedCard = document.querySelector(`.model-card[onclick="selectModel('${model}')"]`);
if (selectedCard) {
selectedCard.classList.add('border-purple-500', 'ring-2', 'ring-purple-200');
}
// Also update dropdown if needed
document.getElementById('model-select').value = model;
console.log(`Selected model: ${model}`);
}
// File upload handling
browseBtn.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', handleFiles);
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false);
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false);
});
function highlight() {
dropArea.classList.add('border-purple-500', 'bg-purple-50');
}
function unhighlight() {
dropArea.classList.remove('border-purple-500', 'bg-purple-50');
}
dropArea.addEventListener('drop', handleDrop, false);
function handleDrop(e) {
const dt = e.dataTransfer;
const files = dt.files;
handleFiles({ target: { files } });
}
function handleFiles(e) {
const files = e.target.files;
if (files.length === 0) return;
fileList.innerHTML = '';
for (let i = 0; i < files.length; i++) {
const file = files[i];
if (file.size > 100 * 1024 * 1024) { // 100MB limit
alert(`File ${file.name} is too large (max 100MB)`);
continue;
}
const fileItem = document.createElement('div');
fileItem.className = 'flex items-center justify-between p-3 bg-gray-50 rounded-lg';
fileItem.innerHTML = `
<div class="flex items-center">
<div class="mr-3 text-purple-600">
${getFileIcon(file)}
</div>
<div>
<div class="text-sm font-medium text-gray-800">${file.name}</div>
<div class="text-xs text-gray-500">${formatFileSize(file.size)}</div>
</div>
</div>
<button onclick="removeFile(this)" class="text-gray-400 hover:text-red-500">
<i class="fas fa-times"></i>
</button>
`;
fileList.appendChild(fileItem);
}
filePreview.classList.remove('hidden');
}
function getFileIcon(file) {
const extension = file.name.split('.').pop().toLowerCase();
const icons = {
pdf: 'file-pdf',
txt: 'file-alt',
docx: 'file-word',
ppt: 'file-powerpoint',
pptx: 'file-powerpoint',
csv: 'file-csv',
xlsx: 'file-excel'
};
const icon = icons[extension] || 'file';
return `<i class="fas fa-${icon}"></i>`;
}
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 parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function removeFile(button) {
const fileItem = button.closest('div');
fileItem.remove();
if (fileList.children.length === 0) {
filePreview.classList.add('hidden');
}
}
// System prompt templates
function insertPrompt(type) {
const prompts = {
legal: 'You are a legal expert assistant. Analyze legal documents precisely and provide accurate interpretations based on the relevant laws and precedents. Always cite your sources when possible.',
technical: 'You are a technical expert assistant. Explain complex technical concepts clearly and provide accurate, detailed answers. When discussing code, use proper formatting and include examples when helpful.',
creative: 'You are a creative writing assistant. Help brainstorm ideas, develop stories, and refine writing with a focus on creativity and originality. Provide suggestions that enhance the narrative and style.',
medical: 'You are a medical information assistant. Provide accurate health information based on current medical knowledge. Always clarify that you are not a substitute for professional medical advice.',
neutral: 'You are a helpful, harmless, and honest assistant. Provide balanced, factual information without bias. If you don\'t know something, say so rather than speculate.'
};
systemPrompt.value = prompts[type] || '';
}
// Training simulation
trainBtn.addEventListener('click', startTraining);
function startTraining() {
if (!selectedModel) {
alert('Please select a model first');
return;
}
if (fileList.children.length === 0) {
alert('Please upload at least one file');
return;
}
if (!systemPrompt.value.trim()) {
alert('Please provide a system prompt');
return;
}
// Disable the button and show progress
trainBtn.disabled = true;
trainBtn.innerHTML = '<i class="fas fa-cog fa-spin mr-3"></i>Training in progress...';
trainBtn.classList.remove('bg-green-600', 'hover:bg-green-700');
trainBtn.classList.add('bg-gray-500');
trainingProgress.classList.remove('hidden');
trainingDetails.classList.remove('hidden');
// Simulate training progress
let progress = 0;
let epochs = 3;
let currentEpoch = 1;
const interval = setInterval(() => {
progress += Math.random() * 5;
if (progress > 100) progress = 100;
progressBar.style.width = `${progress}%`;
progressPercent.textContent = `${Math.round(progress)}%`;
// Update status messages
if (progress < 30) {
trainingStatus.textContent = 'Processing training data...';
} else if (progress < 60) {
trainingStatus.textContent = 'Training model parameters...';
} else if (progress < 90) {
trainingStatus.textContent = 'Optimizing model performance...';
} else {
trainingStatus.textContent = 'Finalizing training...';
}
// Update epoch and loss
if (progress >= 33 && currentEpoch === 1) {
currentEpoch = 2;
document.getElementById('current-epoch').textContent = '2/3';
document.getElementById('current-loss').textContent = (0.5 + Math.random() * 0.3).toFixed(2);
} else if (progress >= 66 && currentEpoch === 2) {
currentEpoch = 3;
document.getElementById('current-epoch').textContent = '3/3';
document.getElementById('current-loss').textContent = (0.2 + Math.random() * 0.2).toFixed(2);
}
// When complete
if (progress === 100) {
clearInterval(interval);
trainingStatus.textContent = 'Training complete! Model is ready for use.';
trainBtn.innerHTML = '<i class="fas fa-check-circle mr-3"></i>Training Complete';
// Show success message and model card
setTimeout(() => {
const successAlert = document.createElement('div');
successAlert.className = 'mt-4 p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg';
successAlert.innerHTML = `
<div class="flex items-center">
<i class="fas fa-check-circle mr-2 text-green-600"></i>
<strong>Success!</strong> Model "${selectedModel}" has been successfully trained on your data.
</div>
<div class="mt-2 text-sm">
You can now use this model with your custom system prompt.
</div>
`;
trainingProgress.appendChild(successAlert);
// Create model card
const modelCard = document.createElement('div');
modelCard.className = 'mt-6 bg-white p-6 rounded-lg shadow border border-gray-200';
modelCard.innerHTML = `
<h3 class="text-lg font-bold mb-4">Model Card</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<h4 class="font-semibold mb-2">Model Details</h4>
<ul class="space-y-2 text-sm">
<li><strong>Base Model:</strong> ${selectedModel}</li>
<li><strong>Training Method:</strong> Fine-tuning</li>
<li><strong>Epochs:</strong> 3</li>
<li><strong>Learning Rate:</strong> 0.001</li>
<li><strong>Final Loss:</strong> ${(0.1 + Math.random() * 0.1).toFixed(4)}</li>
</ul>
</div>
<div>
<h4 class="font-semibold mb-2">Training Data</h4>
<ul class="space-y-2 text-sm">
${Array.from(fileList.children).map(item =>
`<li>${item.querySelector('.text-gray-800').textContent}</li>`
).join('')}
</ul>
</div>
<div class="md:col-span-2">
<h4 class="font-semibold mb-2">System Prompt</h4>
<div class="bg-gray-50 p-3 rounded text-sm">
${systemPrompt.value}
</div>
</div>
<div class="md:col-span-2">
<h4 class="font-semibold mb-2">Intended Use & Limitations</h4>
<div class="text-sm space-y-2">
<p>This model is specialized for: ${systemPrompt.value.substring(0, 50)}...</p>
<p><strong>Limitations:</strong> Performance may vary based on training data quality. Not suitable for high-risk applications.</p>
</div>
</div>
</div>
<div class="mt-6 flex justify-end">
<button onclick="saveModelToProfile()" class="px-4 py-2 bg-purple-600 hover:bg-purple-700 rounded-lg text-white font-medium transition">
<i class="fas fa-save mr-2"></i>Save to Profile
</button>
</div>
`;
trainingProgress.appendChild(modelCard);
}, 500);
}
}, 300);
}
// Save model to profile
function saveModelToProfile() {
alert(`Model "${selectedModel}" has been saved to your profile with its model card.`);
// In a real implementation, this would make an API call to save the model
}
// Initialize model select dropdown
document.getElementById('model-select').addEventListener('change', function() {
if (this.value) {
selectModel(this.value);
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=BathSalt-1/modelmaker" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html> |