Spaces:
Running
Running
the buttons to generate the fiels dont work
Browse files- index.html +134 -82
index.html
CHANGED
|
@@ -230,8 +230,22 @@ const btn = this;
|
|
| 230 |
`# Start training\n` +
|
| 231 |
`train_model(data)`;
|
| 232 |
|
| 233 |
-
const blob = new Blob([content], { type: 'text/x-python'
|
| 234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
const a = document.createElement('a');
|
| 236 |
a.href = url;
|
| 237 |
a.download = `${datasetType}_notebook.ipynb`;
|
|
@@ -283,8 +297,37 @@ const btn = this;
|
|
| 283 |
|
| 284 |
const datasetType = document.getElementById('dataset-type').value;
|
| 285 |
const prompt = document.getElementById('dataset-prompt').value;
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + apiKey, {
|
| 289 |
method: 'POST',
|
| 290 |
headers: {
|
|
@@ -296,7 +339,8 @@ const btn = this;
|
|
| 296 |
text: `Generate a ${datasetType} AI training dataset about: ${prompt}.\n` +
|
| 297 |
`Provide Python code for training this dataset in a structured format.\n` +
|
| 298 |
`Include all necessary files structure.\n` +
|
| 299 |
-
`Output should be in JSON format with files and content.`
|
|
|
|
| 300 |
}]
|
| 301 |
}]
|
| 302 |
})
|
|
@@ -305,87 +349,95 @@ const btn = this;
|
|
| 305 |
const data = await response.json();
|
| 306 |
if (!response.ok) throw new Error(data.error?.message || 'Failed to generate dataset');
|
| 307 |
|
| 308 |
-
// Process the API response
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
filesHTML += `
|
| 330 |
-
<div class="file-item" data-file="${file}" data-content="${encodeURIComponent(content)}">
|
| 331 |
-
<i data-feather="${file.includes('/') ? 'folder' : 'file-text'}" class="file-icon"></i>
|
| 332 |
-
<span>${file}</span>
|
| 333 |
-
<span class="ml-auto text-xs text-green-500">✓ Generated</span>
|
| 334 |
-
</div>
|
| 335 |
-
`;
|
| 336 |
-
}
|
| 337 |
-
document.getElementById('file-explorer').innerHTML = filesHTML;
|
| 338 |
-
feather.replace();
|
| 339 |
-
|
| 340 |
-
// Add completion message
|
| 341 |
-
const completionMessage = document.createElement('div');
|
| 342 |
-
completionMessage.className = 'p-3 bg-green-50 text-green-700 rounded-lg mb-4 text-sm';
|
| 343 |
-
completionMessage.innerHTML = `
|
| 344 |
-
<div class="flex items-center">
|
| 345 |
-
<i data-feather="check-circle" class="mr-2"></i>
|
| 346 |
-
Dataset generation completed successfully!
|
| 347 |
</div>
|
| 348 |
`;
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 352 |
}
|
| 353 |
-
}
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
});
|
| 363 |
-
});
|
| 364 |
-
feather.replace();
|
| 365 |
-
btn.disabled = false;
|
| 366 |
-
btn.innerHTML = '<i data-feather="zap" class="mr-2 w-4 h-4"></i> Generate Dataset';
|
| 367 |
-
feather.replace();
|
| 368 |
-
|
| 369 |
-
// Add to chat
|
| 370 |
-
const chatContainer = document.getElementById('chat-container');
|
| 371 |
-
const userMessage = document.createElement('div');
|
| 372 |
-
userMessage.className = 'chat-message user-message';
|
| 373 |
-
userMessage.innerHTML = `I want to generate a <strong>${datasetType}</strong> dataset about: <em>${prompt}</em>`;
|
| 374 |
-
chatContainer.appendChild(userMessage);
|
| 375 |
-
|
| 376 |
-
const aiMessage = document.createElement('div');
|
| 377 |
-
aiMessage.className = 'chat-message ai-message';
|
| 378 |
-
aiMessage.innerHTML = `
|
| 379 |
-
<div class="flex items-start mb-2">
|
| 380 |
-
<i data-feather="check-circle" class="text-green-500 mr-2 w-4 h-4"></i>
|
| 381 |
-
<span>Successfully generated ${datasetType} dataset!</span>
|
| 382 |
-
</div>
|
| 383 |
-
<p>You can now explore the generated files and export them for training.</p>
|
| 384 |
-
`;
|
| 385 |
-
chatContainer.appendChild(aiMessage);
|
| 386 |
-
feather.replace();
|
| 387 |
-
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 388 |
-
});
|
| 389 |
document.getElementById('send-message').addEventListener('click', async function() {
|
| 390 |
const apiKey = document.getElementById('api-key').value;
|
| 391 |
if (!apiKey) {
|
|
|
|
| 230 |
`# Start training\n` +
|
| 231 |
`train_model(data)`;
|
| 232 |
|
| 233 |
+
const blob = new Blob([content], { type: 'text/x-python'
|
| 234 |
+
});
|
| 235 |
+
|
| 236 |
+
// Helper function to download individual files
|
| 237 |
+
function downloadFile(filename, content) {
|
| 238 |
+
const blob = new Blob([decodeURIComponent(content)], { type: 'text/plain' });
|
| 239 |
+
const url = URL.createObjectURL(blob);
|
| 240 |
+
const a = document.createElement('a');
|
| 241 |
+
a.href = url;
|
| 242 |
+
a.download = filename;
|
| 243 |
+
document.body.appendChild(a);
|
| 244 |
+
a.click();
|
| 245 |
+
document.body.removeChild(a);
|
| 246 |
+
URL.revokeObjectURL(url);
|
| 247 |
+
}
|
| 248 |
+
const url = URL.createObjectURL(blob);
|
| 249 |
const a = document.createElement('a');
|
| 250 |
a.href = url;
|
| 251 |
a.download = `${datasetType}_notebook.ipynb`;
|
|
|
|
| 297 |
|
| 298 |
const datasetType = document.getElementById('dataset-type').value;
|
| 299 |
const prompt = document.getElementById('dataset-prompt').value;
|
| 300 |
+
|
| 301 |
+
// Show output section immediately with loading state
|
| 302 |
+
document.getElementById('output-section').style.display = 'block';
|
| 303 |
+
document.getElementById('file-explorer').innerHTML = `
|
| 304 |
+
<div class="file-item">
|
| 305 |
+
<i data-feather="loader" class="file-icon animate-spin"></i>
|
| 306 |
+
<span>Generating files...</span>
|
| 307 |
+
</div>
|
| 308 |
+
`;
|
| 309 |
+
feather.replace();
|
| 310 |
+
|
| 311 |
try {
|
| 312 |
+
// Show progress bar
|
| 313 |
+
const progressBar = document.createElement('div');
|
| 314 |
+
progressBar.className = 'w-full bg-gray-200 rounded-full h-2.5 mb-4';
|
| 315 |
+
progressBar.innerHTML = `
|
| 316 |
+
<div id="generation-progress" class="bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div>
|
| 317 |
+
`;
|
| 318 |
+
document.getElementById('output-section').prepend(progressBar);
|
| 319 |
+
|
| 320 |
+
// Simulate progress updates
|
| 321 |
+
let progress = 0;
|
| 322 |
+
const progressInterval = setInterval(() => {
|
| 323 |
+
progress += 5;
|
| 324 |
+
document.getElementById('generation-progress').style.width = `${progress}%`;
|
| 325 |
+
if (progress >= 100) {
|
| 326 |
+
clearInterval(progressInterval);
|
| 327 |
+
}
|
| 328 |
+
}, 150);
|
| 329 |
+
|
| 330 |
+
// Call Gemini API to generate the dataset
|
| 331 |
const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + apiKey, {
|
| 332 |
method: 'POST',
|
| 333 |
headers: {
|
|
|
|
| 339 |
text: `Generate a ${datasetType} AI training dataset about: ${prompt}.\n` +
|
| 340 |
`Provide Python code for training this dataset in a structured format.\n` +
|
| 341 |
`Include all necessary files structure.\n` +
|
| 342 |
+
`Output should be in JSON format with files and content.\n` +
|
| 343 |
+
`Example format: {"files": {"train.py": "python code...", "dataset.json": "json content..."}}`
|
| 344 |
}]
|
| 345 |
}]
|
| 346 |
})
|
|
|
|
| 349 |
const data = await response.json();
|
| 350 |
if (!response.ok) throw new Error(data.error?.message || 'Failed to generate dataset');
|
| 351 |
|
| 352 |
+
// Process the API response
|
| 353 |
+
let generatedContent;
|
| 354 |
+
try {
|
| 355 |
+
if (data.candidates && data.candidates[0].content.parts[0].text) {
|
| 356 |
+
generatedContent = JSON.parse(data.candidates[0].content.parts[0].text);
|
| 357 |
+
} else {
|
| 358 |
+
throw new Error('Invalid API response format');
|
| 359 |
+
}
|
| 360 |
+
} catch (e) {
|
| 361 |
+
console.error('Error parsing response:', e);
|
| 362 |
+
throw new Error('Failed to parse generated content');
|
| 363 |
+
}
|
| 364 |
+
// Build files list
|
| 365 |
+
let filesHTML = '';
|
| 366 |
+
if (generatedContent && generatedContent.files) {
|
| 367 |
+
for (const [file, content] of Object.entries(generatedContent.files)) {
|
| 368 |
+
filesHTML += `
|
| 369 |
+
<div class="file-item" data-file="${file}" data-content="${encodeURIComponent(content)}">
|
| 370 |
+
<i data-feather="${file.endsWith('/') ? 'folder' : 'file-text'}" class="file-icon"></i>
|
| 371 |
+
<span>${file}</span>
|
| 372 |
+
<span class="ml-auto text-xs text-green-500">✓ Generated</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
</div>
|
| 374 |
`;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
// Update UI with generated files
|
| 378 |
+
document.getElementById('file-explorer').innerHTML = filesHTML;
|
| 379 |
+
|
| 380 |
+
// Add file click handlers
|
| 381 |
+
document.querySelectorAll('.file-item').forEach(item => {
|
| 382 |
+
item.addEventListener('click', function() {
|
| 383 |
+
const file = this.getAttribute('data-file');
|
| 384 |
+
const content = decodeURIComponent(this.getAttribute('data-content'));
|
| 385 |
+
|
| 386 |
+
// Create a modal to show file content
|
| 387 |
+
const modal = document.createElement('div');
|
| 388 |
+
modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4';
|
| 389 |
+
modal.innerHTML = `
|
| 390 |
+
<div class="bg-white rounded-lg w-full max-w-2xl max-h-[80vh] overflow-hidden flex flex-col">
|
| 391 |
+
<div class="p-4 border-b flex justify-between items-center">
|
| 392 |
+
<h3 class="font-medium">${file}</h3>
|
| 393 |
+
<button class="text-gray-500 hover:text-gray-700" onclick="this.parentElement.parentElement.parentElement.remove()">
|
| 394 |
+
<i data-feather="x"></i>
|
| 395 |
+
</button>
|
| 396 |
+
</div>
|
| 397 |
+
<pre class="p-4 bg-gray-50 text-sm overflow-auto flex-1">${content}</pre>
|
| 398 |
+
<div class="p-4 border-t flex justify-end">
|
| 399 |
+
<button class="bg-indigo-600 text-white px-4 py-2 rounded"
|
| 400 |
+
onclick="downloadFile('${file}', '${encodeURIComponent(content)}')">
|
| 401 |
+
<i data-feather="download" class="mr-2"></i> Download
|
| 402 |
+
</button>
|
| 403 |
+
</div>
|
| 404 |
+
</div>
|
| 405 |
+
`;
|
| 406 |
+
document.body.appendChild(modal);
|
| 407 |
+
feather.replace();
|
| 408 |
+
});
|
| 409 |
+
});
|
| 410 |
+
|
| 411 |
+
// Add to chat
|
| 412 |
+
const chatContainer = document.getElementById('chat-container');
|
| 413 |
+
const userMessage = document.createElement('div');
|
| 414 |
+
userMessage.className = 'chat-message user-message';
|
| 415 |
+
userMessage.innerHTML = `I want to generate a <strong>${datasetType}</strong> dataset about: <em>${prompt}</em>`;
|
| 416 |
+
chatContainer.appendChild(userMessage);
|
| 417 |
+
|
| 418 |
+
const aiMessage = document.createElement('div');
|
| 419 |
+
aiMessage.className = 'chat-message ai-message';
|
| 420 |
+
aiMessage.innerHTML = `
|
| 421 |
+
<div class="flex items-start mb-2">
|
| 422 |
+
<i data-feather="check-circle" class="text-green-500 mr-2 w-4 h-4"></i>
|
| 423 |
+
<span>Successfully generated ${datasetType} dataset!</span>
|
| 424 |
+
</div>
|
| 425 |
+
<p>You can now explore the generated files and export them for training.</p>
|
| 426 |
+
`;
|
| 427 |
+
chatContainer.appendChild(aiMessage);
|
| 428 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 429 |
+
} else {
|
| 430 |
+
throw new Error('No files were generated');
|
| 431 |
}
|
| 432 |
+
} catch (error) {
|
| 433 |
+
console.error('Generation error:', error);
|
| 434 |
+
alert(`Error generating dataset: ${error.message}`);
|
| 435 |
+
} finally {
|
| 436 |
+
btn.disabled = false;
|
| 437 |
+
btn.innerHTML = '<i data-feather="zap" class="mr-2 w-4 h-4"></i> Generate Dataset';
|
| 438 |
+
feather.replace();
|
| 439 |
+
}
|
| 440 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
document.getElementById('send-message').addEventListener('click', async function() {
|
| 442 |
const apiKey = document.getElementById('api-key').value;
|
| 443 |
if (!apiKey) {
|