pvanand commited on
Commit
783eaf7
·
verified ·
1 Parent(s): 35c7794

Update static/iresearcher.html

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