pvanand commited on
Commit
d219d14
·
verified ·
1 Parent(s): 927b777

Update static/iresearcher.html

Browse files
Files changed (1) hide show
  1. static/iresearcher.html +124 -116
static/iresearcher.html CHANGED
@@ -34,11 +34,11 @@ body {
34
  height: 30px;
35
  }
36
  #output-container {
37
- display: flex;
38
- flex-direction: column;
39
- gap: 20px;
40
  }
41
  #report-container, #sources-container {
 
 
42
  background-color: #ffffff;
43
  padding: 30px;
44
  border-radius: 8px;
@@ -47,6 +47,7 @@ body {
47
  word-wrap: break-word;
48
  word-break: break-word;
49
  }
 
50
  table {
51
  width: 100%;
52
  border-collapse: collapse;
@@ -138,25 +139,24 @@ button:hover {
138
  .source-item:hover .expand-indicator {
139
  background: linear-gradient(to bottom, rgba(249,249,249,0), rgba(249,249,249,0.9));
140
  }
 
 
 
 
141
  h2 {
142
  color: var(--accent-color);
143
  border-bottom: 2px solid var(--accent-color);
144
  padding-bottom: 10px;
145
  margin-top: 0;
146
  }
147
-
148
  @media (min-width: 768px) {
149
  #output-container {
150
- flex-direction: row;
151
  }
152
- #report-container {
153
- flex: 3;
154
- }
155
- #sources-container {
156
- flex: 2;
157
  }
158
  }
159
-
160
  @media (max-width: 767px) {
161
  body {
162
  padding: 10px;
@@ -165,11 +165,9 @@ h2 {
165
  #input-container, #report-container, #sources-container {
166
  padding: 15px;
167
  }
168
-
169
  .search-container {
170
  width: 360px;
171
  }
172
-
173
  .title {
174
  width: 300px;
175
  font-weight: 500;
@@ -177,7 +175,6 @@ h2 {
177
  }
178
 
179
  }
180
-
181
  .centered-container {
182
  display: flex;
183
  flex-direction: column;
@@ -185,12 +182,10 @@ h2 {
185
  justify-content: center;
186
  height: 100vh;
187
  }
188
-
189
  .search-container {
190
  display: flex;
191
  margin-top: 20px;
192
  }
193
-
194
  .search-container input {
195
  width: 500px;
196
  padding: 10px 20px;
@@ -200,7 +195,6 @@ h2 {
200
  outline: none;
201
  color: #0e1f4b;
202
  }
203
-
204
  .search-container button {
205
  width: 50px;
206
  padding: 10px;
@@ -213,17 +207,14 @@ h2 {
213
  justify-content: center;
214
  border-radius: 0 15px 15px 0;
215
  }
216
-
217
  .search-container button:hover {
218
  opacity: 0.5;
219
  }
220
-
221
  .search-container button svg {
222
  width: 24px;
223
  height: 24px;
224
 
225
  }
226
-
227
  ::placeholder {
228
  font-style: italic;
229
  font: 1em sans-serif;
@@ -231,7 +222,6 @@ h2 {
231
  opacity: 0.5;
232
 
233
  }
234
-
235
  .title {
236
  font-weight: 700;
237
  font-size: 64px;
@@ -243,16 +233,13 @@ h2 {
243
  margin: 0;
244
  padding: 0 0 0.5rem;
245
  }
246
-
247
  .generate-btn {
248
  white-space: nowrap;
249
  }
250
-
251
  .download-btn {
252
  background-color: #30764c;
253
  margin-top: 10px;
254
  }
255
-
256
  .download-btn:hover {
257
  background-color: #2c8d55;
258
  }
@@ -309,7 +296,6 @@ h2 {
309
  reportContainer.innerHTML = 'Generating report...';
310
  sourcesContainer.innerHTML = '';
311
  downloadBtn.style.display = 'none';
312
-
313
  try {
314
  const response = await fetch('https://iresearcher-api.elevatics.cloud/generate_report', {
315
  method: 'POST',
@@ -328,22 +314,20 @@ h2 {
328
  output_as_md: true
329
  })
330
  });
331
-
332
  if (!response.ok) {
333
  throw new Error(`HTTP error! status: ${response.status}`);
334
  }
335
-
336
  const reader = response.body.getReader();
337
  const decoder = new TextDecoder();
338
  let markdown = '';
339
  let metadata = '';
340
  let isReadingMetadata = false;
341
-
342
  while (true) {
343
  const { value, done } = await reader.read();
344
  if (done) break;
345
 
346
  const chunk = decoder.decode(value, { stream: true });
 
347
 
348
  if (chunk.includes('<report-metadata>')) {
349
  isReadingMetadata = true;
@@ -361,13 +345,11 @@ h2 {
361
  renderMarkdown(markdown);
362
  }
363
  }
364
-
365
  downloadBtn.style.display = 'inline-block';
366
  } catch (error) {
367
  reportContainer.innerHTML = `Error generating report: ${error.message}`;
368
  }
369
  }
370
-
371
  function renderMarkdown(markdown) {
372
  const reportContainer = document.getElementById('report-container');
373
  const previousHeight = reportContainer.scrollHeight;
@@ -390,15 +372,12 @@ function renderMarkdown(markdown) {
390
  newScript.textContent = script.textContent;
391
  script.parentNode.replaceChild(newScript, script);
392
  });
393
-
394
  const plots = reportContainer.querySelectorAll('.js-plotly-plot');
395
  plots.forEach(plot => {
396
  Plotly.Plots.resize(plot);
397
  });
398
-
399
  scrollToNewContent(previousHeight);
400
  }
401
-
402
  function processMetadata(metadata) {
403
  const sourcesContainer = document.getElementById('sources-container');
404
  const metadataMatch = metadata.match(/all-text-with-urls: (.+)/);
@@ -454,7 +433,6 @@ function processMetadata(metadata) {
454
  sourcesContainer.innerHTML = '<h2>Sources</h2><p>No source information available.</p>';
455
  }
456
  }
457
-
458
  function scrollToNewContent(previousHeight) {
459
  const reportContainer = document.getElementById('report-container');
460
  const newHeight = reportContainer.scrollHeight;
@@ -473,30 +451,75 @@ function scrollToNewContent(previousHeight) {
473
  }
474
  }
475
  }
476
-
477
  function scrollToTop() {
478
  window.scrollTo({
479
  top: 0,
480
  behavior: 'smooth'
481
  });
482
  }
483
-
484
  function sanitizeFileName(name) {
485
  return name.replace(/[^a-z0-9\s]/gi, '').toLowerCase().replace(/\s+/g, '_').substring(0, 50) || 'generated_report';
486
  }
487
-
488
- async function downloadHTML() {
489
- try {
490
- const response = await fetch('styles.css');
491
- let css = await response.text();
492
-
493
- css += `
494
- body.report-body {
495
- max-width: 804px;
496
- margin: 0 auto;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
497
  }
498
  .source-item {
499
  margin-bottom: 20px;
 
 
 
 
 
 
 
 
 
 
 
 
500
  }
501
  .source-content {
502
  margin-top: 10px;
@@ -507,80 +530,65 @@ async function downloadHTML() {
507
  .source-full {
508
  display: block;
509
  }
 
 
 
 
 
 
 
 
 
510
  `;
511
 
512
- const htmlContent = document.implementation.createHTMLDocument('Report');
513
-
514
- htmlContent.documentElement.lang = 'en';
515
- const head = htmlContent.head;
516
- const body = htmlContent.body;
517
- body.className = 'report-body';
518
-
519
- const meta = htmlContent.createElement('meta');
520
- meta.charset = 'UTF-8';
521
- head.appendChild(meta);
522
-
523
- const viewport = htmlContent.createElement('meta');
524
- viewport.name = 'viewport';
525
- viewport.content = 'width=device-width, initial-scale=1.0';
526
- head.appendChild(viewport);
527
-
528
- const title = htmlContent.createElement('title');
529
- title.textContent = 'Generated Report';
530
- head.appendChild(title);
531
-
532
- const style = htmlContent.createElement('style');
533
- style.textContent = css;
534
- head.appendChild(style);
535
-
536
- const markedScript = htmlContent.createElement('script');
537
- markedScript.src = 'https://cdn.jsdelivr.net/npm/marked/marked.min.js';
538
- head.appendChild(markedScript);
539
-
540
- const plotlyScript = htmlContent.createElement('script');
541
- plotlyScript.src = 'https://cdn.plot.ly/plotly-latest.min.js';
542
- head.appendChild(plotlyScript);
543
-
544
- const reportContainer = document.getElementById('report-container');
545
- body.innerHTML = reportContainer.innerHTML;
546
-
547
- const sourcesContainer = document.getElementById('sources-container');
548
- const sourcesDiv = htmlContent.createElement('div');
549
- sourcesDiv.innerHTML = sourcesContainer.innerHTML;
550
-
551
- const sourceItems = sourcesDiv.querySelectorAll('.source-item');
552
- sourceItems.forEach(item => {
553
- item.classList.add('expanded');
554
- const snippetDiv = item.querySelector('.source-snippet');
555
- const fullDiv = item.querySelector('.source-full');
556
- if (snippetDiv) snippetDiv.style.display = 'none';
557
- if (fullDiv) fullDiv.style.display = 'block';
558
- });
559
-
560
- body.appendChild(sourcesDiv);
561
-
562
- const fileName = sanitizeFileName(body.querySelector('h1, h2, h3')?.textContent || reportContainer.textContent.substring(0, 20));
563
-
564
- const blob = new Blob([htmlContent.documentElement.outerHTML], { type: 'text/html' });
565
- const url = URL.createObjectURL(blob);
566
- const a = document.createElement('a');
567
- a.href = url;
568
- a.download = `${fileName}.html`;
569
- document.body.appendChild(a);
570
- a.click();
571
- document.body.removeChild(a);
572
- URL.revokeObjectURL(url);
573
- } catch (error) {
574
- console.error('Error downloading HTML:', error);
575
  }
576
- }
577
 
578
- window.addEventListener('resize', function() {
579
- const plots = document.querySelectorAll('.js-plotly-plot');
580
- plots.forEach(plot => {
581
- Plotly.Plots.resize(plot);
582
- });
583
  });
584
- </script>
 
 
 
 
 
 
 
585
  </body>
586
  </html>
 
34
  height: 30px;
35
  }
36
  #output-container {
37
+ display: block;
 
 
38
  }
39
  #report-container, #sources-container {
40
+ max-width: 800px;
41
+ margin: 0 auto 30px;
42
  background-color: #ffffff;
43
  padding: 30px;
44
  border-radius: 8px;
 
47
  word-wrap: break-word;
48
  word-break: break-word;
49
  }
50
+
51
  table {
52
  width: 100%;
53
  border-collapse: collapse;
 
139
  .source-item:hover .expand-indicator {
140
  background: linear-gradient(to bottom, rgba(249,249,249,0), rgba(249,249,249,0.9));
141
  }
142
+ h1 {
143
+ color: var(--accent-color);
144
+ }
145
+
146
  h2 {
147
  color: var(--accent-color);
148
  border-bottom: 2px solid var(--accent-color);
149
  padding-bottom: 10px;
150
  margin-top: 0;
151
  }
 
152
  @media (min-width: 768px) {
153
  #output-container {
154
+ display: block;
155
  }
156
+ #report-container, #sources-container {
157
+ flex: none;
 
 
 
158
  }
159
  }
 
160
  @media (max-width: 767px) {
161
  body {
162
  padding: 10px;
 
165
  #input-container, #report-container, #sources-container {
166
  padding: 15px;
167
  }
 
168
  .search-container {
169
  width: 360px;
170
  }
 
171
  .title {
172
  width: 300px;
173
  font-weight: 500;
 
175
  }
176
 
177
  }
 
178
  .centered-container {
179
  display: flex;
180
  flex-direction: column;
 
182
  justify-content: center;
183
  height: 100vh;
184
  }
 
185
  .search-container {
186
  display: flex;
187
  margin-top: 20px;
188
  }
 
189
  .search-container input {
190
  width: 500px;
191
  padding: 10px 20px;
 
195
  outline: none;
196
  color: #0e1f4b;
197
  }
 
198
  .search-container button {
199
  width: 50px;
200
  padding: 10px;
 
207
  justify-content: center;
208
  border-radius: 0 15px 15px 0;
209
  }
 
210
  .search-container button:hover {
211
  opacity: 0.5;
212
  }
 
213
  .search-container button svg {
214
  width: 24px;
215
  height: 24px;
216
 
217
  }
 
218
  ::placeholder {
219
  font-style: italic;
220
  font: 1em sans-serif;
 
222
  opacity: 0.5;
223
 
224
  }
 
225
  .title {
226
  font-weight: 700;
227
  font-size: 64px;
 
233
  margin: 0;
234
  padding: 0 0 0.5rem;
235
  }
 
236
  .generate-btn {
237
  white-space: nowrap;
238
  }
 
239
  .download-btn {
240
  background-color: #30764c;
241
  margin-top: 10px;
242
  }
 
243
  .download-btn:hover {
244
  background-color: #2c8d55;
245
  }
 
296
  reportContainer.innerHTML = 'Generating report...';
297
  sourcesContainer.innerHTML = '';
298
  downloadBtn.style.display = 'none';
 
299
  try {
300
  const response = await fetch('https://iresearcher-api.elevatics.cloud/generate_report', {
301
  method: 'POST',
 
314
  output_as_md: true
315
  })
316
  });
 
317
  if (!response.ok) {
318
  throw new Error(`HTTP error! status: ${response.status}`);
319
  }
 
320
  const reader = response.body.getReader();
321
  const decoder = new TextDecoder();
322
  let markdown = '';
323
  let metadata = '';
324
  let isReadingMetadata = false;
 
325
  while (true) {
326
  const { value, done } = await reader.read();
327
  if (done) break;
328
 
329
  const chunk = decoder.decode(value, { stream: true });
330
+ console.log(chunk);
331
 
332
  if (chunk.includes('<report-metadata>')) {
333
  isReadingMetadata = true;
 
345
  renderMarkdown(markdown);
346
  }
347
  }
 
348
  downloadBtn.style.display = 'inline-block';
349
  } catch (error) {
350
  reportContainer.innerHTML = `Error generating report: ${error.message}`;
351
  }
352
  }
 
353
  function renderMarkdown(markdown) {
354
  const reportContainer = document.getElementById('report-container');
355
  const previousHeight = reportContainer.scrollHeight;
 
372
  newScript.textContent = script.textContent;
373
  script.parentNode.replaceChild(newScript, script);
374
  });
 
375
  const plots = reportContainer.querySelectorAll('.js-plotly-plot');
376
  plots.forEach(plot => {
377
  Plotly.Plots.resize(plot);
378
  });
 
379
  scrollToNewContent(previousHeight);
380
  }
 
381
  function processMetadata(metadata) {
382
  const sourcesContainer = document.getElementById('sources-container');
383
  const metadataMatch = metadata.match(/all-text-with-urls: (.+)/);
 
433
  sourcesContainer.innerHTML = '<h2>Sources</h2><p>No source information available.</p>';
434
  }
435
  }
 
436
  function scrollToNewContent(previousHeight) {
437
  const reportContainer = document.getElementById('report-container');
438
  const newHeight = reportContainer.scrollHeight;
 
451
  }
452
  }
453
  }
 
454
  function scrollToTop() {
455
  window.scrollTo({
456
  top: 0,
457
  behavior: 'smooth'
458
  });
459
  }
 
460
  function sanitizeFileName(name) {
461
  return name.replace(/[^a-z0-9\s]/gi, '').toLowerCase().replace(/\s+/g, '_').substring(0, 50) || 'generated_report';
462
  }
463
+ function downloadHTML() {
464
+ try {
465
+ var css = `
466
+ :root {
467
+ --accent-color: #003366;
468
+ }
469
+ body {
470
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
471
+ line-height: 1.6;
472
+ margin: 0 auto;
473
+ padding: 20px;
474
+ background-color: #f0f2f5;
475
+ color: #333;
476
+ max-width: 1366px;
477
+ }
478
+ #report-container, #sources-container {
479
+ max-width: 800px;
480
+ margin: 0 auto 30px;
481
+ background-color: #ffffff;
482
+ padding: 30px;
483
+ border-radius: 8px;
484
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
485
+ overflow-wrap: break-word;
486
+ word-wrap: break-word;
487
+ word-break: break-word;
488
+ }
489
+ table {
490
+ width: 100%;
491
+ border-collapse: collapse;
492
+ margin-bottom: 20px;
493
+ }
494
+ table, th, td {
495
+ border: 1px solid #ddd;
496
+ }
497
+ th, td {
498
+ padding: 10px;
499
+ text-align: left;
500
+ }
501
+ h1, h2, h3, h4, h5, h6 {
502
+ color: var(--accent-color);
503
+ }
504
+ h2 {
505
+ border-bottom: 2px solid var(--accent-color);
506
+ padding-bottom: 10px;
507
+ margin-top: 0;
508
  }
509
  .source-item {
510
  margin-bottom: 20px;
511
+ padding: 15px;
512
+ background-color: #f9f9f9;
513
+ border: 1px solid #e0e0e0;
514
+ border-radius: 8px;
515
+ }
516
+ .source-url {
517
+ color: var(--accent-color);
518
+ text-decoration: none;
519
+ word-break: break-all;
520
+ font-weight: bold;
521
+ display: block;
522
+ margin-bottom: 10px;
523
  }
524
  .source-content {
525
  margin-top: 10px;
 
530
  .source-full {
531
  display: block;
532
  }
533
+ @media (max-width: 767px) {
534
+ body {
535
+ padding: 10px;
536
+ width: 95%;
537
+ }
538
+ #report-container, #sources-container {
539
+ padding: 15px;
540
+ }
541
+ }
542
  `;
543
 
544
+ var htmlContent = '<!DOCTYPE html>\n<html lang="en">\n<head>\n' +
545
+ '<meta charset="UTF-8">\n' +
546
+ '<meta name="viewport" content="width=device-width, initial-scale=1.0">\n' +
547
+ '<title>Generated Report</title>\n' +
548
+ '<style>' + css + '</style>\n' +
549
+ '<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"><\/script>\n' +
550
+ '<script src="https://cdn.plot.ly/plotly-latest.min.js"><\/script>\n' +
551
+ '</head>\n<body>\n' +
552
+ '<div id="report-container">\n' + document.getElementById('report-container').innerHTML + '\n</div>\n' +
553
+ '<div id="sources-container">\n' + document.getElementById('sources-container').innerHTML + '\n</div>\n' +
554
+ '</body>\n</html>';
555
+
556
+ var fileName = sanitizeFileName(document.querySelector('#report-container h1, #report-container h2, #report-container h3')?.textContent || 'generated_report');
557
+ var blob = new Blob([htmlContent], { type: 'text/html' });
558
+ var url = URL.createObjectURL(blob);
559
+ var a = document.createElement('a');
560
+ a.href = url;
561
+ a.download = fileName + '.html';
562
+ document.body.appendChild(a);
563
+ a.click();
564
+ document.body.removeChild(a);
565
+ URL.revokeObjectURL(url);
566
+ } catch (error) {
567
+ console.error('Error downloading HTML:', error);
568
+ }
569
+ }
570
+ document.addEventListener('DOMContentLoaded', function() {
571
+ const descriptionInput = document.getElementById('description');
572
+ const initialView = document.getElementById('initial-view');
573
+
574
+ function handleEnterKey(event) {
575
+ if (event.key === 'Enter' &&
576
+ this.value.trim() !== '' &&
577
+ initialView.style.display !== 'none') {
578
+ event.preventDefault();
579
+ generateReport();
580
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  }
 
582
 
583
+ descriptionInput.addEventListener('keydown', handleEnterKey);
 
 
 
 
584
  });
585
+ window.addEventListener('resize', function() {
586
+ const plots = document.querySelectorAll('.js-plotly-plot');
587
+ plots.forEach(plot => {
588
+ Plotly.Plots.resize(plot);
589
+ });
590
+ });
591
+
592
+ </script>
593
  </body>
594
  </html>