pvanand commited on
Commit
9baeff5
·
verified ·
1 Parent(s): 188b361

Update templates/apps-hub/article-writer.html

Browse files
templates/apps-hub/article-writer.html CHANGED
@@ -199,11 +199,18 @@
199
  <div id="input-container">
200
  <h1>Blog Post Generator</h1>
201
  <textarea id="description" rows="4" placeholder="Enter description">write a medium article on nvidia stock performance</textarea>
202
- <button onclick="generateReport()">Generate Blog</button>
203
  </div>
204
  <div id="output-container">
205
  <div id="report-container"></div>
206
  <div id="sources-container"></div>
 
 
 
 
 
 
 
207
  </div>
208
  </div>
209
  </main>
@@ -216,7 +223,7 @@
216
  const description = document.getElementById('description').value;
217
  const reportContainer = document.getElementById('report-container');
218
  const sourcesContainer = document.getElementById('sources-container');
219
- reportContainer.innerHTML = ' Searching results...';
220
  sourcesContainer.innerHTML = '';
221
  try {
222
  const response = await fetch('https://pvanand-search-generate-prod.hf.space/generate_blog', {
@@ -232,8 +239,8 @@
232
  internet: true,
233
  output_format: "report_table",
234
  data_format: "Structured data",
235
- generate_charts: false,
236
- output_as_md: true
237
  })
238
  });
239
  if (!response.ok) {
@@ -265,7 +272,9 @@
265
  markdown += chunk;
266
  renderMarkdown(markdown);
267
  }
 
268
  }
 
269
  } catch (error) {
270
  reportContainer.innerHTML = `Error generating report: ${error.message}`;
271
  }
@@ -348,6 +357,128 @@
348
  Plotly.Plots.resize(plot);
349
  });
350
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  </script>
352
  </body>
353
  </html>
 
199
  <div id="input-container">
200
  <h1>Blog Post Generator</h1>
201
  <textarea id="description" rows="4" placeholder="Enter description">write a medium article on nvidia stock performance</textarea>
202
+ <button onclick="generateReport()">Generate Report</button>
203
  </div>
204
  <div id="output-container">
205
  <div id="report-container"></div>
206
  <div id="sources-container"></div>
207
+ <div class="button-container">
208
+ <button id="downloadBtn" onclick="downloadHTML()" style="display: none;" title="Download HTML Report">
209
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
210
+ <path d="M3 15v4c0 1.1.9 2 2 2h14a2 2 0 0 0 2-2v-4M17 9l-5 5-5-5M12 12.8V2.5"/>
211
+ </svg>
212
+ </button>
213
+ </div>
214
  </div>
215
  </div>
216
  </main>
 
223
  const description = document.getElementById('description').value;
224
  const reportContainer = document.getElementById('report-container');
225
  const sourcesContainer = document.getElementById('sources-container');
226
+ reportContainer.innerHTML = 'Generating report...';
227
  sourcesContainer.innerHTML = '';
228
  try {
229
  const response = await fetch('https://pvanand-search-generate-prod.hf.space/generate_blog', {
 
239
  internet: true,
240
  output_format: "report_table",
241
  data_format: "Structured data",
242
+ generate_charts: true,
243
+ output_as_md: false
244
  })
245
  });
246
  if (!response.ok) {
 
272
  markdown += chunk;
273
  renderMarkdown(markdown);
274
  }
275
+
276
  }
277
+ document.getElementById('downloadBtn').style.display = 'block';
278
  } catch (error) {
279
  reportContainer.innerHTML = `Error generating report: ${error.message}`;
280
  }
 
357
  Plotly.Plots.resize(plot);
358
  });
359
  });
360
+
361
+ function sanitizeFileName(name) {
362
+ // Keep only alphanumeric characters and spaces
363
+ name = name.replace(/[^a-z0-9\s]/gi, '');
364
+ // Convert to lowercase
365
+ name = name.toLowerCase();
366
+ // Replace spaces with underscores
367
+ name = name.replace(/\s+/g, '_');
368
+ // Limit the length to 50 characters
369
+ name = name.substring(0, 50);
370
+ // If the name is empty after sanitization, use a default name
371
+ return name || 'generated_report';
372
+ }
373
+ async function downloadHTML() {
374
+ try {
375
+ // Get styles from current document
376
+ let css = '';
377
+ const styleTags = document.getElementsByTagName('style');
378
+ for (let styleTag of styleTags) {
379
+ css += styleTag.innerHTML;
380
+ }
381
+
382
+ // Add additional styles for expanded sources and body max-width
383
+ css += `
384
+ body.report-body {
385
+ max-width: 804px;
386
+ margin: 0 auto;
387
+ }
388
+ .source-item {
389
+ margin-bottom: 20px;
390
+ }
391
+ .source-content {
392
+ margin-top: 10px;
393
+ }
394
+ .source-snippet, .expand-indicator {
395
+ display: none;
396
+ }
397
+ .source-full {
398
+ display: block;
399
+ }
400
+ `;
401
+
402
+ // Clone the document
403
+ const htmlContent = document.implementation.createHTMLDocument('Report');
404
+
405
+ // Set up the basic structure
406
+ htmlContent.documentElement.lang = 'en';
407
+ const head = htmlContent.head;
408
+ const body = htmlContent.body;
409
+ body.className = 'report-body';
410
+
411
+ // Add meta tags
412
+ const meta = htmlContent.createElement('meta');
413
+ meta.charset = 'UTF-8';
414
+ head.appendChild(meta);
415
+
416
+ const viewport = htmlContent.createElement('meta');
417
+ viewport.name = 'viewport';
418
+ viewport.content = 'width=device-width, initial-scale=1.0';
419
+ head.appendChild(viewport);
420
+
421
+ // Copy the report content
422
+ const reportContainer = document.getElementById('report-container');
423
+ body.innerHTML = reportContainer.innerHTML;
424
+
425
+ // Generate file name from content
426
+ let fileName = 'generatedreport';
427
+ const headings = body.querySelector('h1, h2, h3');
428
+ if (headings) {
429
+ fileName = sanitizeFileName(headings.textContent);
430
+ }
431
+
432
+ // Add title
433
+ const title = htmlContent.createElement('title');
434
+ title.textContent = fileName;
435
+ head.appendChild(title);
436
+
437
+ // Add style
438
+ const style = htmlContent.createElement('style');
439
+ style.textContent = css;
440
+ head.appendChild(style);
441
+
442
+ // Add necessary scripts
443
+ const markedScript = htmlContent.createElement('script');
444
+ markedScript.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';
445
+ head.appendChild(markedScript);
446
+
447
+ const plotlyScript = htmlContent.createElement('script');
448
+ plotlyScript.src = 'https://cdn.plot.ly/plotly-latest.min.js';
449
+ head.appendChild(plotlyScript);
450
+
451
+ // Copy and modify the sources content
452
+ const sourcesContainer = document.getElementById('sources-container');
453
+ const sourcesDiv = htmlContent.createElement('div');
454
+ sourcesDiv.innerHTML = sourcesContainer.innerHTML;
455
+
456
+ // Expand all sources
457
+ const sourceItems = sourcesDiv.querySelectorAll('.source-item');
458
+ sourceItems.forEach(item => {
459
+ item.classList.add('expanded');
460
+ const snippetDiv = item.querySelector('.source-snippet');
461
+ const fullDiv = item.querySelector('.source-full');
462
+ if (snippetDiv) snippetDiv.style.display = 'none';
463
+ if (fullDiv) fullDiv.style.display = 'block';
464
+ });
465
+
466
+ body.appendChild(sourcesDiv);
467
+
468
+ // Create blob and download
469
+ const blob = new Blob([htmlContent.documentElement.outerHTML], { type: 'text/html' });
470
+ const url = URL.createObjectURL(blob);
471
+ const a = document.createElement('a');
472
+ a.href = url;
473
+ a.download = `${fileName}.html`;
474
+ document.body.appendChild(a);
475
+ a.click();
476
+ document.body.removeChild(a);
477
+ URL.revokeObjectURL(url);
478
+ } catch (error) {
479
+ console.error('Error downloading HTML:', error);
480
+ }
481
+ }
482
  </script>
483
  </body>
484
  </html>