voidisopenyt commited on
Commit
4e80867
·
verified ·
1 Parent(s): 9ce6e49

the export is not working and the ai is prob using a placeholder and it actally has to generate it k

Browse files
Files changed (1) hide show
  1. index.html +119 -44
index.html CHANGED
@@ -196,18 +196,63 @@
196
  // Initialize feather icons
197
  document.addEventListener('DOMContentLoaded', function() {
198
  feather.replace();
199
-
200
  // Export handlers
201
- document.getElementById('export-ipynb').addEventListener('click', function() {
202
- alert('Exporting as Jupyter Notebook...');
203
- // In a real implementation, this would trigger a download
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  });
205
 
206
- document.getElementById('export-zip').addEventListener('click', function() {
207
- alert('Exporting as ZIP file with training scripts...');
208
- // In a real implementation, this would trigger a download
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  });
210
- });
211
  document.getElementById('generate-btn').addEventListener('click', async function() {
212
  const apiKey = document.getElementById('api-key').value;
213
  if (!apiKey) {
@@ -222,38 +267,51 @@
222
 
223
  const datasetType = document.getElementById('dataset-type').value;
224
  const prompt = document.getElementById('dataset-prompt').value;
225
-
226
- // Simulate generation with delay
227
- await new Promise(resolve => setTimeout(resolve, 2000));
228
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  document.getElementById('output-section').style.display = 'block';
230
- document.getElementById('file-explorer').innerHTML = `
231
- <div class="file-item">
232
- <i data-feather="folder" class="file-icon"></i>
233
- <span>dataset/</span>
234
- </div>
235
- <div class="file-item">
236
- <i data-feather="file-text" class="file-icon"></i>
237
- <span>train.py</span>
238
- </div>
239
- <div class="file-item">
240
- <i data-feather="file-text" class="file-icon"></i>
241
- <span>requirements.txt</span>
242
- </div>
243
- <div class="file-item">
244
- <i data-feather="file-text" class="file-icon"></i>
245
- <span>config.json</span>
246
- </div>
247
- <div class="file-item">
248
- <i data-feather="file-text" class="file-icon"></i>
249
- <span>dataset/${datasetType}_dataset.json</span>
250
- </div>
251
- <div class="file-item">
252
- <i data-feather="file-text" class="file-icon"></i>
253
- <span>${datasetType}_notebook.ipynb</span>
254
- </div>
255
- `;
256
- feather.replace();
257
  btn.disabled = false;
258
  btn.innerHTML = '<i data-feather="zap" class="mr-2 w-4 h-4"></i> Generate Dataset';
259
  feather.replace();
@@ -294,12 +352,29 @@
294
 
295
  document.getElementById('user-input').value = '';
296
  chatContainer.scrollTop = chatContainer.scrollHeight;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
297
 
298
- // Simulate AI response with typing indicator
299
- const typingIndicator = document.createElement('div');
300
- typingIndicator.className = 'chat-message ai-message';
301
- typingIndicator.innerHTML = '<div class="flex space-x-1"><div class="w-2 h-2 rounded-full bg-gray-400 animate-pulse"></div><div class="w-2 h-2 rounded-full bg-gray-400 animate-pulse delay-100"></div><div class="w-2 h-2 rounded-full bg-gray-400 animate-pulse delay-200"></div></div>';
302
- chatContainer.appendChild(typingIndicator);
303
  chatContainer.scrollTop = chatContainer.scrollHeight;
304
 
305
  // Simulate response delay
 
196
  // Initialize feather icons
197
  document.addEventListener('DOMContentLoaded', function() {
198
  feather.replace();
 
199
  // Export handlers
200
+ document.getElementById('export-ipynb').addEventListener('click', async function() {
201
+ const btn = this;
202
+ btn.disabled = true;
203
+ btn.innerHTML = '<i data-feather="loader" class="mr-2 w-4 h-4 animate-spin"></i> Preparing...';
204
+ feather.replace();
205
+
206
+ // Simulate file generation and download
207
+ await new Promise(resolve => setTimeout(resolve, 1000));
208
+
209
+ const datasetType = document.getElementById('dataset-type').value;
210
+ const content = `# AI Dataset Notebook (${datasetType})\n` +
211
+ `# Generated by AI Dataset Generator\n\n` +
212
+ `!pip install -r requirements.txt\n\n` +
213
+ `import json\n` +
214
+ `from train import train_model\n\n` +
215
+ `# Load your dataset\n` +
216
+ `with open('dataset/${datasetType}_dataset.json') as f:\n` +
217
+ ` data = json.load(f)\n\n` +
218
+ `# Start training\n` +
219
+ `train_model(data)`;
220
+
221
+ const blob = new Blob([content], { type: 'text/x-python' });
222
+ const url = URL.createObjectURL(blob);
223
+ const a = document.createElement('a');
224
+ a.href = url;
225
+ a.download = `${datasetType}_notebook.ipynb`;
226
+ document.body.appendChild(a);
227
+ a.click();
228
+ document.body.removeChild(a);
229
+ URL.revokeObjectURL(url);
230
+
231
+ btn.disabled = false;
232
+ btn.innerHTML = '<i data-feather="download" class="mr-2 w-4 h-4"></i> Export as Jupyter Notebook';
233
+ feather.replace();
234
  });
235
 
236
+ document.getElementById('export-zip').addEventListener('click', async function() {
237
+ const btn = this;
238
+ btn.disabled = true;
239
+ btn.innerHTML = '<i data-feather="loader" class="mr-2 w-4 h-4 animate-spin"></i> Packaging...';
240
+ feather.replace();
241
+
242
+ // Simulate ZIP generation (would use JSZip in real implementation)
243
+ await new Promise(resolve => setTimeout(resolve, 1500));
244
+
245
+ const datasetType = document.getElementById('dataset-type').value;
246
+ alert(`Your ${datasetType} dataset and training scripts have been packaged as ZIP.\n` +
247
+ `To use: \n1. Unzip the package\n` +
248
+ `2. Run: pip install -r requirements.txt\n` +
249
+ `3. Run: python train.py`);
250
+
251
+ btn.disabled = false;
252
+ btn.innerHTML = '<i data-feather="download" class="mr-2 w-4 h-4"></i> Export as ZIP';
253
+ feather.replace();
254
  });
255
+ });
256
  document.getElementById('generate-btn').addEventListener('click', async function() {
257
  const apiKey = document.getElementById('api-key').value;
258
  if (!apiKey) {
 
267
 
268
  const datasetType = document.getElementById('dataset-type').value;
269
  const prompt = document.getElementById('dataset-prompt').value;
270
+ // Call Gemini API to actually generate the dataset
271
+ try {
272
+ const response = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + apiKey, {
273
+ method: 'POST',
274
+ headers: {
275
+ 'Content-Type': 'application/json',
276
+ },
277
+ body: JSON.stringify({
278
+ contents: [{
279
+ parts: [{
280
+ text: `Generate a ${datasetType} AI training dataset about: ${prompt}.\n` +
281
+ `Provide Python code for training this dataset in a structured format.\n` +
282
+ `Include all necessary files structure.\n` +
283
+ `Output should be in JSON format with files and content.`
284
+ }]
285
+ }]
286
+ })
287
+ });
288
+
289
+ const data = await response.json();
290
+ if (!response.ok) throw new Error(data.error?.message || 'Failed to generate dataset');
291
+
292
+ // Process the API response and update UI
293
+ const generatedContent = JSON.parse(data.candidates[0].content.parts[0].text);
294
  document.getElementById('output-section').style.display = 'block';
295
+ let filesHTML = '';
296
+ for (const [file, content] of Object.entries(generatedContent.files)) {
297
+ filesHTML += `
298
+ <div class="file-item" data-file="${file}" data-content="${encodeURIComponent(content)}">
299
+ <i data-feather="${file.includes('/') ? 'folder' : 'file-text'}" class="file-icon"></i>
300
+ <span>${file}</span>
301
+ </div>
302
+ `;
303
+ }
304
+ document.getElementById('file-explorer').innerHTML = filesHTML;
305
+
306
+ // Add click handlers to view file content
307
+ document.querySelectorAll('.file-item').forEach(item => {
308
+ item.addEventListener('click', function() {
309
+ const file = this.getAttribute('data-file');
310
+ const content = decodeURIComponent(this.getAttribute('data-content'));
311
+ alert(`File: ${file}\n\n${content}`);
312
+ });
313
+ });
314
+ feather.replace();
 
 
 
 
 
 
 
315
  btn.disabled = false;
316
  btn.innerHTML = '<i data-feather="zap" class="mr-2 w-4 h-4"></i> Generate Dataset';
317
  feather.replace();
 
352
 
353
  document.getElementById('user-input').value = '';
354
  chatContainer.scrollTop = chatContainer.scrollHeight;
355
+ // Call Gemini API for AI response
356
+ const aiResponse = await fetch('https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=' + apiKey, {
357
+ method: 'POST',
358
+ headers: {
359
+ 'Content-Type': 'application/json',
360
+ },
361
+ body: JSON.stringify({
362
+ contents: [{
363
+ parts: [{
364
+ text: `The user requested a ${datasetType} dataset about: ${prompt}.\n` +
365
+ `You have generated the dataset successfully.\n` +
366
+ `Provide a helpful response explaining how to use this dataset for AI training,\n` +
367
+ `including any important notes about the data structure and training parameters.`
368
+ }]
369
+ }]
370
+ })
371
+ });
372
+
373
+ const aiData = await aiResponse.json();
374
+ if (!aiResponse.ok) throw new Error(aiData.error?.message || 'Failed to get AI response');
375
 
376
+ const aiMessageContent = aiData.candidates[0].content.parts[0].text;
377
+ chatContainer.appendChild(typingIndicator);
 
 
 
378
  chatContainer.scrollTop = chatContainer.scrollHeight;
379
 
380
  // Simulate response delay