pvanand commited on
Commit
19bfd93
1 Parent(s): 424154f

Update static/medium-report.html

Browse files
Files changed (1) hide show
  1. static/medium-report.html +131 -29
static/medium-report.html CHANGED
@@ -1,17 +1,15 @@
1
-
2
  <!DOCTYPE html>
3
  <html lang="en">
4
  <head>
5
  <meta charset="UTF-8">
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
- <title>Report Generator</title>
8
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
9
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
 
 
10
  <style>
11
- /* Main styles */
12
- body {
13
- margin: 0;
14
- padding: 0;
15
  text-rendering: optimizeLegibility;
16
  -webkit-font-smoothing: antialiased;
17
  color: rgba(0,0,0,0.8);
@@ -22,13 +20,6 @@
22
  line-height: 1.58;
23
  color: rgba(0, 0, 0, 0.8);
24
  background-color: #fff;
25
- margin: 0;
26
- padding: 0;
27
- }
28
-
29
-
30
-
31
- .container {
32
  max-width: 800px;
33
  margin: 0 auto;
34
  padding: 0 20px;
@@ -41,18 +32,15 @@
41
  letter-spacing: -0.022em;
42
  line-height: 1.2;
43
  }
44
-
45
  h1 {
46
  font-size: 40px;
47
  margin-bottom: 0.5em;
48
  }
49
-
50
  h2 {
51
  font-size: 32px;
52
  margin-top: 1.5em;
53
  margin-bottom: 0.5em;
54
  }
55
-
56
  h3 {
57
  font-size: 26px;
58
  margin-top: 1.5em;
@@ -185,29 +173,41 @@
185
  }
186
  }
187
  </style>
 
188
  </head>
189
  <body>
 
 
 
190
  <div class="container">
191
  <div id="input-container">
192
  <h1>Blog Post Generator</h1>
193
  <textarea id="description" rows="4" placeholder="Enter description">write a medium article on nvidia stock performance</textarea>
194
- <button onclick="generateReport()">Generate Report</button>
195
  </div>
196
  <div id="output-container">
197
  <div id="report-container"></div>
198
  <div id="sources-container"></div>
 
 
 
 
 
 
 
199
  </div>
200
  </div>
 
 
201
  <script>
202
  async function generateReport() {
203
  const description = document.getElementById('description').value;
204
  const reportContainer = document.getElementById('report-container');
205
  const sourcesContainer = document.getElementById('sources-container');
206
- reportContainer.innerHTML = 'Generating report...';
207
  sourcesContainer.innerHTML = '';
208
-
209
  try {
210
- const response = await fetch('https://iresearcher-api.elevatics.cloud/generate_report', {
211
  method: 'POST',
212
  headers: {
213
  'Content-Type': 'application/json',
@@ -216,7 +216,7 @@
216
  body: JSON.stringify({
217
  description: description,
218
  user_id: "",
219
- user_name: "multi-agent-research",
220
  internet: true,
221
  output_format: "report_table",
222
  data_format: "Structured data",
@@ -224,17 +224,14 @@
224
  output_as_md: true
225
  })
226
  });
227
-
228
  if (!response.ok) {
229
  throw new Error(`HTTP error! status: ${response.status}`);
230
  }
231
-
232
  const reader = response.body.getReader();
233
  const decoder = new TextDecoder();
234
  let markdown = '';
235
  let metadata = '';
236
  let isReadingMetadata = false;
237
-
238
  while (true) {
239
  const { value, done } = await reader.read();
240
  if (done) break;
@@ -256,12 +253,13 @@
256
  markdown += chunk;
257
  renderMarkdown(markdown);
258
  }
 
259
  }
 
260
  } catch (error) {
261
- reportContainer.innerHTML = `Error generating report: ${error.message}`;
262
  }
263
  }
264
-
265
  function renderMarkdown(markdown) {
266
  const reportContainer = document.getElementById('report-container');
267
  const reportContent = markdown.match(/<report>([\s\S]*)<\/report>/);
@@ -278,14 +276,12 @@
278
  newScript.textContent = script.textContent;
279
  script.parentNode.replaceChild(newScript, script);
280
  });
281
-
282
  // Make Plotly charts responsive
283
  const plots = reportContainer.querySelectorAll('.js-plotly-plot');
284
  plots.forEach(plot => {
285
  Plotly.Plots.resize(plot);
286
  });
287
  }
288
-
289
  function processMetadata(metadata) {
290
  const sourcesContainer = document.getElementById('sources-container');
291
  const metadataMatch = metadata.match(/all-text-with-urls: (.+)/);
@@ -335,7 +331,6 @@
335
  sourcesContainer.innerHTML = '<h2>Sources</h2><p>No source information available.</p>';
336
  }
337
  }
338
-
339
  // Make Plotly charts responsive on window resize
340
  window.addEventListener('resize', function() {
341
  const plots = document.querySelectorAll('.js-plotly-plot');
@@ -343,6 +338,113 @@
343
  Plotly.Plots.resize(plot);
344
  });
345
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  </script>
347
  </body>
348
  </html>
 
 
1
  <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Blog Writer</title>
7
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
8
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
10
+ <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
11
  <style>
12
+ .container {
 
 
 
13
  text-rendering: optimizeLegibility;
14
  -webkit-font-smoothing: antialiased;
15
  color: rgba(0,0,0,0.8);
 
20
  line-height: 1.58;
21
  color: rgba(0, 0, 0, 0.8);
22
  background-color: #fff;
 
 
 
 
 
 
 
23
  max-width: 800px;
24
  margin: 0 auto;
25
  padding: 0 20px;
 
32
  letter-spacing: -0.022em;
33
  line-height: 1.2;
34
  }
 
35
  h1 {
36
  font-size: 40px;
37
  margin-bottom: 0.5em;
38
  }
 
39
  h2 {
40
  font-size: 32px;
41
  margin-top: 1.5em;
42
  margin-bottom: 0.5em;
43
  }
 
44
  h3 {
45
  font-size: 26px;
46
  margin-top: 1.5em;
 
173
  }
174
  }
175
  </style>
176
+ <link rel="stylesheet" href="/css/ai-sidebar.css">
177
  </head>
178
  <body>
179
+ <div id="app" class="ai-sidebar__container">
180
+ <sidebar-component></sidebar-component>
181
+ <main class="ai-sidebar__content">
182
  <div class="container">
183
  <div id="input-container">
184
  <h1>Blog Post Generator</h1>
185
  <textarea id="description" rows="4" placeholder="Enter description">write a medium article on nvidia stock performance</textarea>
186
+ <button onclick="generateReport()">Generate Blog</button>
187
  </div>
188
  <div id="output-container">
189
  <div id="report-container"></div>
190
  <div id="sources-container"></div>
191
+ <div class="button-container">
192
+ <button id="downloadBtn" onclick="downloadHTML()" style="display: none;" title="Download HTML Blog">
193
+ <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">
194
+ <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"/>
195
+ </svg>
196
+ </button>
197
+ </div>
198
  </div>
199
  </div>
200
+ </main>
201
+ </div>
202
  <script>
203
  async function generateReport() {
204
  const description = document.getElementById('description').value;
205
  const reportContainer = document.getElementById('report-container');
206
  const sourcesContainer = document.getElementById('sources-container');
207
+ reportContainer.innerHTML = 'Searching results...';
208
  sourcesContainer.innerHTML = '';
 
209
  try {
210
+ const response = await fetch('https://iresearcher-api.elevatics.cloud/generate_blog', {
211
  method: 'POST',
212
  headers: {
213
  'Content-Type': 'application/json',
 
216
  body: JSON.stringify({
217
  description: description,
218
  user_id: "",
219
+ user_name: "multi-agent-research-generate-blog",
220
  internet: true,
221
  output_format: "report_table",
222
  data_format: "Structured data",
 
224
  output_as_md: true
225
  })
226
  });
 
227
  if (!response.ok) {
228
  throw new Error(`HTTP error! status: ${response.status}`);
229
  }
 
230
  const reader = response.body.getReader();
231
  const decoder = new TextDecoder();
232
  let markdown = '';
233
  let metadata = '';
234
  let isReadingMetadata = false;
 
235
  while (true) {
236
  const { value, done } = await reader.read();
237
  if (done) break;
 
253
  markdown += chunk;
254
  renderMarkdown(markdown);
255
  }
256
+
257
  }
258
+ document.getElementById('downloadBtn').style.display = 'block';
259
  } catch (error) {
260
+ reportContainer.innerHTML = `Error generating blog: ${error.message}`;
261
  }
262
  }
 
263
  function renderMarkdown(markdown) {
264
  const reportContainer = document.getElementById('report-container');
265
  const reportContent = markdown.match(/<report>([\s\S]*)<\/report>/);
 
276
  newScript.textContent = script.textContent;
277
  script.parentNode.replaceChild(newScript, script);
278
  });
 
279
  // Make Plotly charts responsive
280
  const plots = reportContainer.querySelectorAll('.js-plotly-plot');
281
  plots.forEach(plot => {
282
  Plotly.Plots.resize(plot);
283
  });
284
  }
 
285
  function processMetadata(metadata) {
286
  const sourcesContainer = document.getElementById('sources-container');
287
  const metadataMatch = metadata.match(/all-text-with-urls: (.+)/);
 
331
  sourcesContainer.innerHTML = '<h2>Sources</h2><p>No source information available.</p>';
332
  }
333
  }
 
334
  // Make Plotly charts responsive on window resize
335
  window.addEventListener('resize', function() {
336
  const plots = document.querySelectorAll('.js-plotly-plot');
 
338
  Plotly.Plots.resize(plot);
339
  });
340
  });
341
+
342
+ function sanitizeFileName(name) {
343
+ // Keep only alphanumeric characters and spaces
344
+ name = name.replace(/[^a-z0-9\s]/gi, '');
345
+ // Convert to lowercase
346
+ name = name.toLowerCase();
347
+ // Replace spaces with underscores
348
+ name = name.replace(/\s+/g, '_');
349
+ // Limit the length to 50 characters
350
+ name = name.substring(0, 50);
351
+ // If the name is empty after sanitization, use a default name
352
+ return name || 'generated_report';
353
+ }
354
+ async function downloadHTML() {
355
+ try {
356
+ // Get styles from current document
357
+ let css = '';
358
+ const styleTags = document.getElementsByTagName('style');
359
+ for (let styleTag of styleTags) {
360
+ css += styleTag.innerHTML;
361
+ }
362
+ // Add additional styles for expanded sources and body max-width
363
+ css += `
364
+ body.report-body {
365
+ max-width: 804px;
366
+ margin: 0 auto;
367
+ }
368
+ .source-item {
369
+ margin-bottom: 20px;
370
+ }
371
+ .source-content {
372
+ margin-top: 10px;
373
+ }
374
+ .source-snippet, .expand-indicator {
375
+ display: none;
376
+ }
377
+ .source-full {
378
+ display: block;
379
+ }
380
+ `;
381
+ // Clone the document
382
+ const htmlContent = document.implementation.createHTMLDocument('Report');
383
+ // Set up the basic structure
384
+ htmlContent.documentElement.lang = 'en';
385
+ const head = htmlContent.head;
386
+ const body = htmlContent.body;
387
+ body.className = 'report-body';
388
+ // Add meta tags
389
+ const meta = htmlContent.createElement('meta');
390
+ meta.charset = 'UTF-8';
391
+ head.appendChild(meta);
392
+ const viewport = htmlContent.createElement('meta');
393
+ viewport.name = 'viewport';
394
+ viewport.content = 'width=device-width, initial-scale=1.0';
395
+ head.appendChild(viewport);
396
+ // Copy the report content
397
+ const reportContainer = document.getElementById('report-container');
398
+ body.innerHTML = reportContainer.innerHTML;
399
+ // Generate file name from content
400
+ let fileName = 'generatedreport';
401
+ const headings = body.querySelector('h1, h2, h3');
402
+ if (headings) {
403
+ fileName = sanitizeFileName(headings.textContent);
404
+ }
405
+ // Add title
406
+ const title = htmlContent.createElement('title');
407
+ title.textContent = fileName;
408
+ head.appendChild(title);
409
+ // Add style
410
+ const style = htmlContent.createElement('style');
411
+ style.textContent = css;
412
+ head.appendChild(style);
413
+ // Add necessary scripts
414
+ const markedScript = htmlContent.createElement('script');
415
+ markedScript.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';
416
+ head.appendChild(markedScript);
417
+ const plotlyScript = htmlContent.createElement('script');
418
+ plotlyScript.src = 'https://cdn.plot.ly/plotly-latest.min.js';
419
+ head.appendChild(plotlyScript);
420
+ // Copy and modify the sources content
421
+ const sourcesContainer = document.getElementById('sources-container');
422
+ const sourcesDiv = htmlContent.createElement('div');
423
+ sourcesDiv.innerHTML = sourcesContainer.innerHTML;
424
+ // Expand all sources
425
+ const sourceItems = sourcesDiv.querySelectorAll('.source-item');
426
+ sourceItems.forEach(item => {
427
+ item.classList.add('expanded');
428
+ const snippetDiv = item.querySelector('.source-snippet');
429
+ const fullDiv = item.querySelector('.source-full');
430
+ if (snippetDiv) snippetDiv.style.display = 'none';
431
+ if (fullDiv) fullDiv.style.display = 'block';
432
+ });
433
+ body.appendChild(sourcesDiv);
434
+ // Create blob and download
435
+ const blob = new Blob([htmlContent.documentElement.outerHTML], { type: 'text/html' });
436
+ const url = URL.createObjectURL(blob);
437
+ const a = document.createElement('a');
438
+ a.href = url;
439
+ a.download = `${fileName}.html`;
440
+ document.body.appendChild(a);
441
+ a.click();
442
+ document.body.removeChild(a);
443
+ URL.revokeObjectURL(url);
444
+ } catch (error) {
445
+ console.error('Error downloading HTML:', error);
446
+ }
447
+ }
448
  </script>
449
  </body>
450
  </html>