Spaces:
Running
Running
File size: 24,050 Bytes
ab3dc55 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 6c1e825 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 2bd76bd a92bd4c 2bd76bd a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 a92bd4c 9ce6e49 6c1e825 4e80867 12c7772 4e80867 9ce6e49 6c1e825 4e80867 9ce6e49 4e80867 9ce6e49 a92bd4c 9ce6e49 a92bd4c 12c7772 4e80867 12c7772 4e80867 12c7772 2bd76bd 4e80867 12c7772 6c1e825 12c7772 6c1e825 12c7772 9ce6e49 6c1e825 a92bd4c 9ce6e49 a92bd4c 4e80867 6c1e825 4e80867 9ce6e49 4e80867 9ce6e49 6c1e825 9ce6e49 a92bd4c | 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 | <!doctype html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>AI Database Generator</title>
<link rel="stylesheet" href="style.css" />
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<style>
:root {
--primary: #6366f1;
--primary-dark: #4f46e5;
}
body {
font-family: 'Inter', sans-serif;
background-color: #f9fafb;
}
.sidebar {
width: 350px;
height: 100vh;
position: fixed;
right: 0;
top: 0;
background: white;
padding: 1.5rem;
border-left: 1px solid #e5e7eb;
overflow-y: auto;
box-shadow: -2px 0 10px rgba(0,0,0,0.05);
}
.main-content {
margin-right: 370px;
padding: 2rem;
}
.chat-message {
margin-bottom: 1rem;
padding: 0.75rem 1rem;
border-radius: 0.5rem;
font-size: 0.9rem;
line-height: 1.5;
}
.user-message {
background: #eef2ff;
color: var(--primary-dark);
}
.ai-message {
background: #f8fafc;
border: 1px solid #e5e7eb;
}
.api-key-input {
margin-bottom: 1.5rem;
padding: 1rem;
background: #f8fafc;
border-radius: 0.5rem;
}
.card {
background: white;
border-radius: 0.75rem;
padding: 1.5rem;
margin-bottom: 1.5rem;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
border: 1px solid #e5e7eb;
}
button {
background: var(--primary);
color: white;
padding: 0.5rem 1rem;
border-radius: 0.375rem;
font-weight: 500;
transition: all 0.2s;
border: none;
cursor: pointer;
}
button:hover {
background: var(--primary-dark);
}
input, textarea, select {
width: 100%;
padding: 0.5rem 0.75rem;
border-radius: 0.375rem;
border: 1px solid #e5e7eb;
margin-bottom: 1rem;
}
.file-explorer {
border: 1px dashed #e5e7eb;
border-radius: 0.5rem;
padding: 1rem;
background: #f8fafc;
min-height: 200px;
}
.file-item {
display: flex;
align-items: center;
padding: 0.5rem;
border-radius: 0.25rem;
margin-bottom: 0.25rem;
}
.file-item:hover {
background: #eef2ff;
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-3px); }
}
.animate-bounce {
animation: bounce 0.6s infinite;
}
.file-icon {
margin-right: 0.5rem;
color: #6b7280;
}
</style>
</head>
<body>
<div class="sidebar">
<h2>AI Assistant</h2>
<div class="api-key-input">
<label for="api-key">Enter Gemini API Key:</label>
<input type="password" id="api-key" placeholder="Your Gemini API key">
<button id="save-key">Save</button>
</div>
<div id="chat-container">
<div class="chat-message ai-message">
Hello! I'm here to help you build your AI training dataset. What would you like to generate today?
</div>
</div>
<div class="chat-input">
<input type="text" id="user-input" placeholder="Ask me anything...">
<button id="send-message">Send</button>
</div>
</div>
<div class="main-content">
<h1 class="text-3xl font-bold text-gray-800 mb-6">AI Dataset Generator</h1>
<div class="card">
<h2 class="text-xl font-semibold mb-4">Configuration</h2>
<div class="form-group">
<label class="block text-sm font-medium text-gray-700 mb-1">Dataset Type:</label>
<select id="dataset-type" class="focus:ring-indigo-500 focus:border-indigo-500">
<option value="conversational">Conversational</option>
<option value="qna">Q&A</option>
<option value="code">Code Examples</option>
<option value="database">AI Database</option>
</select>
</div>
<div class="form-group">
<label class="block text-sm font-medium text-gray-700 mb-1">Prompt:</label>
<textarea id="dataset-prompt" rows="4" class="focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Describe what you want in your dataset..."></textarea>
</div>
<button id="generate-btn" class="flex items-center">
<i data-feather="zap" class="mr-2 w-4 h-4"></i> Generate Dataset
</button>
</div>
<div class="card" id="output-section" style="display:none;">
<h2 class="text-xl font-semibold mb-4">Generated Output</h2>
<div class="file-explorer mb-4" id="file-explorer">
<div class="file-item">
<i data-feather="folder" class="file-icon"></i>
<span>dataset/</span>
</div>
<div class="file-item">
<i data-feather="file-text" class="file-icon"></i>
<span>train.py</span>
</div>
<div class="file-item">
<i data-feather="file-text" class="file-icon"></i>
<span>requirements.txt</span>
</div>
<div class="file-item">
<i data-feather="file-text" class="file-icon"></i>
<span>config.json</span>
</div>
<div class="file-item">
<i data-feather="file-text" class="file-icon"></i>
<span>dataset.json</span>
</div>
<div class="file-item">
<i data-feather="file-text" class="file-icon"></i>
<span>notebook.ipynb</span>
</div>
</div>
<div class="flex gap-2 mb-4">
<button id="export-ipynb" class="flex items-center">
<i data-feather="download" class="mr-2 w-4 h-4"></i> Export as Jupyter Notebook
</button>
<button id="export-zip" class="flex items-center">
<i data-feather="download" class="mr-2 w-4 h-4"></i> Export as ZIP
</button>
</div>
<div class="training-instructions bg-gray-50 p-4 rounded-lg">
<h3 class="font-medium text-gray-800 mb-2">Training Instructions</h3>
<div class="bg-gray-800 text-white p-3 rounded-md font-mono text-sm overflow-x-auto">
<p># Install dependencies</p>
<p class="text-green-400">pip install -r requirements.txt</p>
<p class="mt-2"># Start training</p>
<p class="text-green-400">python train.py</p>
</div>
</div>
</div>
</div>
<script>
// Initialize feather icons
document.addEventListener('DOMContentLoaded', function() {
feather.replace();
// Export handlers
document.getElementById('export-ipynb').addEventListener('click', async function() {
const apiKey = document.getElementById('api-key').value;
if (!apiKey) {
alert('Please enter your Gemini API key first');
return;
}
const btn = this;
btn.disabled = true;
btn.innerHTML = '<i data-feather="loader" class="mr-2 w-4 h-4 animate-spin"></i> Preparing...';
feather.replace();
// Simulate file generation and download
await new Promise(resolve => setTimeout(resolve, 1000));
const datasetType = document.getElementById('dataset-type').value;
const content = `# AI Dataset Notebook (${datasetType})\n` +
`# Generated by AI Dataset Generator\n\n` +
`!pip install -r requirements.txt\n\n` +
`import json\n` +
`from train import train_model\n\n` +
`# Load your dataset\n` +
`with open('dataset/${datasetType}_dataset.json') as f:\n` +
` data = json.load(f)\n\n` +
`# Start training\n` +
`train_model(data)`;
const blob = new Blob([content], { type: 'text/x-python'
});
// Helper function to download individual files
function downloadFile(filename, content) {
const blob = new Blob([decodeURIComponent(content)], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${datasetType}_notebook.ipynb`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
btn.disabled = false;
btn.innerHTML = '<i data-feather="download" class="mr-2 w-4 h-4"></i> Export as Jupyter Notebook';
feather.replace();
});
document.getElementById('export-zip').addEventListener('click', async function() {
const apiKey = document.getElementById('api-key').value;
if (!apiKey) {
alert('Please enter your Gemini API key first');
return;
}
const btn = this;
btn.disabled = true;
btn.innerHTML = '<i data-feather="loader" class="mr-2 w-4 h-4 animate-spin"></i> Packaging...';
feather.replace();
// Simulate ZIP generation (would use JSZip in real implementation)
await new Promise(resolve => setTimeout(resolve, 1500));
const datasetType = document.getElementById('dataset-type').value;
alert(`Your ${datasetType} dataset and training scripts have been packaged as ZIP.\n` +
`To use: \n1. Unzip the package\n` +
`2. Run: pip install -r requirements.txt\n` +
`3. Run: python train.py`);
btn.disabled = false;
btn.innerHTML = '<i data-feather="download" class="mr-2 w-4 h-4"></i> Export as ZIP';
feather.replace();
});
});
document.getElementById('generate-btn').addEventListener('click', async function() {
const apiKey = document.getElementById('api-key').value;
if (!apiKey) {
alert('Please enter your Gemini API key first');
return;
}
const btn = this;
btn.disabled = true;
btn.innerHTML = '<i data-feather="loader" class="mr-2 w-4 h-4 animate-spin"></i> Generating...';
feather.replace();
const datasetType = document.getElementById('dataset-type').value;
const prompt = document.getElementById('dataset-prompt').value;
// Show output section immediately with loading state
document.getElementById('output-section').style.display = 'block';
document.getElementById('file-explorer').innerHTML = `
<div class="file-item">
<i data-feather="loader" class="file-icon animate-spin"></i>
<span>Generating files...</span>
</div>
`;
feather.replace();
try {
// Show progress bar
const progressBar = document.createElement('div');
progressBar.className = 'w-full bg-gray-200 rounded-full h-2.5 mb-4';
progressBar.innerHTML = `
<div id="generation-progress" class="bg-indigo-600 h-2.5 rounded-full" style="width: 0%"></div>
`;
document.getElementById('output-section').prepend(progressBar);
// Simulate progress updates
let progress = 0;
const progressInterval = setInterval(() => {
progress += 5;
document.getElementById('generation-progress').style.width = `${progress}%`;
if (progress >= 100) {
clearInterval(progressInterval);
}
}, 150);
// Call Gemini API to generate the dataset
const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + apiKey, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
contents: [{
parts: [{
text: `Generate a ${datasetType} AI training dataset about: ${prompt}.\n` +
`Provide Python code for training this dataset in a structured format.\n` +
`Include all necessary files structure.\n` +
`Output should be in JSON format with files and content.\n` +
`For AI Database type, include SQL schema, sample queries and data generation scripts.\n` +
`Example format: {"files": {"train.py": "python code...", "dataset.json": "json content...", "schema.sql": "SQL schema..."}}`
}]
}]
})
});
const data = await response.json();
if (!response.ok) throw new Error(data.error?.message || 'Failed to generate dataset');
// Process the API response
let generatedContent;
try {
if (data.candidates && data.candidates[0].content.parts[0].text) {
generatedContent = JSON.parse(data.candidates[0].content.parts[0].text);
} else {
throw new Error('Invalid API response format');
}
} catch (e) {
console.error('Error parsing response:', e);
throw new Error('Failed to parse generated content');
}
// Build files list
let filesHTML = '';
if (generatedContent && generatedContent.files) {
for (const [file, content] of Object.entries(generatedContent.files)) {
filesHTML += `
<div class="file-item" data-file="${file}" data-content="${encodeURIComponent(content)}">
<i data-feather="${file.endsWith('/') ? 'folder' : 'file-text'}" class="file-icon"></i>
<span>${file}</span>
<span class="ml-auto text-xs text-green-500">✓ Generated</span>
</div>
`;
}
// Update UI with generated files
document.getElementById('file-explorer').innerHTML = filesHTML;
// Add file click handlers
document.querySelectorAll('.file-item').forEach(item => {
item.addEventListener('click', function() {
const file = this.getAttribute('data-file');
const content = decodeURIComponent(this.getAttribute('data-content'));
// Create a modal to show file content
const modal = document.createElement('div');
modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4';
modal.innerHTML = `
<div class="bg-white rounded-lg w-full max-w-2xl max-h-[80vh] overflow-hidden flex flex-col">
<div class="p-4 border-b flex justify-between items-center">
<h3 class="font-medium">${file}</h3>
<button class="text-gray-500 hover:text-gray-700" onclick="this.parentElement.parentElement.parentElement.remove()">
<i data-feather="x"></i>
</button>
</div>
<pre class="p-4 bg-gray-50 text-sm overflow-auto flex-1">${content}</pre>
<div class="p-4 border-t flex justify-end">
<button class="bg-indigo-600 text-white px-4 py-2 rounded"
onclick="downloadFile('${file}', '${encodeURIComponent(content)}')">
<i data-feather="download" class="mr-2"></i> Download
</button>
</div>
</div>
`;
document.body.appendChild(modal);
feather.replace();
});
});
// Add to chat
const chatContainer = document.getElementById('chat-container');
const userMessage = document.createElement('div');
userMessage.className = 'chat-message user-message';
userMessage.innerHTML = `I want to generate a <strong>${datasetType}</strong> dataset about: <em>${prompt}</em>`;
chatContainer.appendChild(userMessage);
const aiMessage = document.createElement('div');
aiMessage.className = 'chat-message ai-message';
aiMessage.innerHTML = `
<div class="flex items-start mb-2">
<i data-feather="check-circle" class="text-green-500 mr-2 w-4 h-4"></i>
<span>Successfully generated ${datasetType} dataset!</span>
</div>
<p>You can now explore the generated files and export them for training.</p>
`;
chatContainer.appendChild(aiMessage);
chatContainer.scrollTop = chatContainer.scrollHeight;
} else {
throw new Error('No files were generated');
}
} catch (error) {
console.error('Generation error:', error);
alert(`Error generating dataset: ${error.message}`);
} finally {
btn.disabled = false;
btn.innerHTML = '<i data-feather="zap" class="mr-2 w-4 h-4"></i> Generate Dataset';
feather.replace();
}
});
document.getElementById('send-message').addEventListener('click', async function() {
const apiKey = document.getElementById('api-key').value;
if (!apiKey) {
alert('Please enter your Gemini API key first');
return;
}
const input = document.getElementById('user-input').value;
if (!input) return;
const btn = this;
btn.disabled = true;
const chatContainer = document.getElementById('chat-container');
const userMessage = document.createElement('div');
userMessage.className = 'chat-message user-message';
userMessage.textContent = input;
chatContainer.appendChild(userMessage);
document.getElementById('user-input').value = '';
chatContainer.scrollTop = chatContainer.scrollHeight;
// Call Gemini API for AI response
// Show typing indicator
const typingIndicator = document.createElement('div');
typingIndicator.className = 'chat-message ai-message flex items-center';
typingIndicator.innerHTML = `
<div class="flex space-x-1">
<div class="w-2 h-2 bg-gray-400 rounded-full animate-bounce"></div>
<div class="w-2 h-2 bg-gray-400 rounded-full animate-bounce" style="animation-delay: 0.2s"></div>
<div class="w-2 h-2 bg-gray-400 rounded-full animate-bounce" style="animation-delay: 0.4s"></div>
</div>
<span class="ml-2 text-sm text-gray-500">Generating response...</span>
`;
chatContainer.appendChild(typingIndicator);
chatContainer.scrollTop = chatContainer.scrollHeight;
try {
const aiResponse = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + apiKey, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
contents: [{
parts: [{
text: `The user requested a ${datasetType} dataset about: ${prompt}.\n` +
`You have generated the dataset successfully.\n` +
`Provide a helpful response explaining how to use this dataset for AI training,\n` +
`including any important notes about the data structure and training parameters.`
}]
}]
})
});
const aiData = await aiResponse.json();
if (!aiResponse.ok) throw new Error(aiData.error?.message || 'Failed to get AI response');
const aiMessageContent = aiData.candidates[0].content.parts[0].text;
chatContainer.appendChild(typingIndicator);
chatContainer.scrollTop = chatContainer.scrollHeight;
// Simulate response delay
await new Promise(resolve => setTimeout(resolve, 1500));
chatContainer.removeChild(typingIndicator);
const aiMessage = document.createElement('div');
aiMessage.className = 'chat-message ai-message';
aiMessage.innerHTML = aiMessageContent;
chatContainer.appendChild(aiMessage);
feather.replace();
chatContainer.scrollTop = chatContainer.scrollHeight;
btn.disabled = false;
});
</script>
</body>
</html> |