pvanand commited on
Commit
f16ddf2
·
verified ·
1 Parent(s): 19bfd93

Create iresearcher.html

Browse files
Files changed (1) hide show
  1. static/iresearcher.html +587 -0
static/iresearcher.html ADDED
@@ -0,0 +1,587 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ <link rel="stylesheet" href="styles.css">
11
+ <style>
12
+
13
+ :root {
14
+ --accent-color: #003366; /* Navy blue */
15
+ }
16
+ body {
17
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
18
+ line-height: 1.6;
19
+ margin: 0 auto;
20
+ padding: 20px;
21
+ background-color: #f0f2f5;
22
+ color: #333;
23
+ max-width: 1366px;
24
+ width: 100%;
25
+ }
26
+ #input-container {
27
+ margin-bottom: 20px;
28
+ background-color: #ffffff;
29
+ padding: 20px;
30
+ border-radius: 8px;
31
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
32
+ }
33
+ .button-container {
34
+ justify-content: space-between;
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;
46
+ box-shadow: 0 2px 4px rgba(0,0,0,0.1);
47
+ overflow-wrap: break-word;
48
+ word-wrap: break-word;
49
+ word-break: break-word;
50
+ }
51
+ table {
52
+ width: 100%;
53
+ border-collapse: collapse;
54
+ margin-bottom: 20px;
55
+ }
56
+ table, th, td {
57
+ border: 1px solid #ddd;
58
+ }
59
+ th, td {
60
+ padding: 10px;
61
+ text-align: left;
62
+ }
63
+ textarea {
64
+ width: 100%;
65
+ padding: 12px;
66
+ margin-bottom: 15px;
67
+ border: 1px solid #ccc;
68
+ border-radius: 4px;
69
+ font-size: 16px;
70
+ resize: vertical;
71
+ box-sizing: border-box;
72
+ }
73
+ button {
74
+ padding: 12px 24px;
75
+ background-color: var(--accent-color);
76
+ color: white;
77
+ border: none;
78
+ border-radius: 4px;
79
+ cursor: pointer;
80
+ font-size: 16px;
81
+ transition: background-color 0.3s;
82
+ }
83
+ button:hover {
84
+ background-color: #002244;
85
+ }
86
+ .source-item {
87
+ margin-bottom: 20px;
88
+ padding: 15px;
89
+ background-color: #f9f9f9;
90
+ border: 1px solid #e0e0e0;
91
+ border-radius: 8px;
92
+ position: relative;
93
+ cursor: pointer;
94
+ transition: box-shadow 0.3s;
95
+ }
96
+ .source-item:hover {
97
+ box-shadow: 0 4px 8px rgba(0,0,0,0.1);
98
+ }
99
+ .source-url {
100
+ color: var(--accent-color);
101
+ text-decoration: none;
102
+ word-break: break-all;
103
+ font-weight: bold;
104
+ display: block;
105
+ margin-bottom: 10px;
106
+ cursor: pointer;
107
+ }
108
+ .source-content {
109
+ margin-top: 10px;
110
+ position: relative;
111
+ overflow: hidden;
112
+ }
113
+ .source-snippet {
114
+ max-height: 150px;
115
+ overflow: hidden;
116
+ }
117
+ .source-full {
118
+ display: none;
119
+ }
120
+ .expand-indicator {
121
+ position: absolute;
122
+ bottom: 0;
123
+ left: 0;
124
+ right: 0;
125
+ height: 30px;
126
+ background: linear-gradient(to bottom, rgba(249,249,249,0), rgba(249,249,249,1));
127
+ display: flex;
128
+ align-items: center;
129
+ justify-content: center;
130
+ }
131
+ .expand-indicator::after {
132
+ content: '▼';
133
+ font-size: 14px;
134
+ color: #666;
135
+ }
136
+ .expanded .expand-indicator::after {
137
+ content: '▲';
138
+ }
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;
164
+ width: 95%;
165
+ }
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;
177
+ font-size: 50px !important
178
+ }
179
+
180
+ }
181
+
182
+ .centered-container {
183
+ display: flex;
184
+ flex-direction: column;
185
+ align-items: center;
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;
198
+ font-size: 16px;
199
+ border: 1px solid #bfcceb;
200
+ border-radius: 15px 0 0 15px;
201
+ outline: none;
202
+ color: #0e1f4b;
203
+ }
204
+
205
+ .search-container button {
206
+ width: 50px;
207
+ padding: 10px;
208
+ background: #ffffff;
209
+ border: none;
210
+ cursor: pointer;
211
+ transition: opacity 0.3s ease;
212
+ display: flex;
213
+ align-items: center;
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;
231
+ color: #7088c1;
232
+ opacity: 0.5;
233
+
234
+ }
235
+
236
+ .title {
237
+ font-weight: 700;
238
+ font-size: 64px;
239
+ background: linear-gradient(45deg, #3b82f6, #10b981);
240
+ -webkit-background-clip: text;
241
+ background-clip: text;
242
+ color: transparent;
243
+ text-align: center;
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
+ }
260
+ </style>
261
+ </head>
262
+ <body>
263
+ <div id="main-container">
264
+ <div id="initial-view" class="centered-container">
265
+ <h1 class="title">iResearcher</h1>
266
+ <div class="search-container">
267
+ <input type="text" id="description" placeholder="Your question/topic...">
268
+ <button onclick="generateReport()">
269
+ <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="url(#gradient)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
270
+ <defs>
271
+ <linearGradient id="gradient" x1="0%" y1="0%" x2="100%" y2="100%">
272
+ <stop offset="0%" stop-color="#3b82f6" />
273
+ <stop offset="100%" stop-color="#10b981" />
274
+ </linearGradient>
275
+ </defs>
276
+ <circle cx="11" cy="11" r="8"></circle>
277
+ <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
278
+ </svg>
279
+ </button>
280
+ </div>
281
+ </div>
282
+
283
+ <!-- This will be shown when a report is generated -->
284
+ <div id="report-view" style="display: none;">
285
+ <div id="input-container" style="display: none;">
286
+ <textarea id="description-textarea" rows="1" placeholder="Your question/topics"></textarea>
287
+ </div>
288
+ <div id="output-container">
289
+ <div id="report-container"></div>
290
+ <div id="sources-container"></div>
291
+ </div>
292
+ <div class="button-container">
293
+ <button id="downloadBtn" onclick="downloadHTML()" style="display: none;" title="Download HTML Report">
294
+ <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">
295
+ <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"/>
296
+ </svg>
297
+ </button>
298
+ </div>
299
+ </div>
300
+ </div>
301
+ <script>
302
+ async function generateReport() {
303
+ const description = document.getElementById('description').value || document.getElementById('description-textarea').value;
304
+ document.getElementById('initial-view').style.display = 'none';
305
+ document.getElementById('report-view').style.display = 'block';
306
+ document.getElementById('description-textarea').value = description;
307
+ const reportContainer = document.getElementById('report-container');
308
+ const sourcesContainer = document.getElementById('sources-container');
309
+ const downloadBtn = document.getElementById('downloadBtn');
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',
317
+ headers: {
318
+ 'Content-Type': 'application/json',
319
+ 'Accept': 'text/plain'
320
+ },
321
+ body: JSON.stringify({
322
+ description: description,
323
+ user_id: "",
324
+ user_name: "multi-agent-research",
325
+ internet: true,
326
+ output_format: "report_table",
327
+ data_format: "Structured data",
328
+ generate_charts: true,
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;
346
+
347
+ const chunk = decoder.decode(value, { stream: true });
348
+
349
+ if (chunk.includes('<report-metadata>')) {
350
+ isReadingMetadata = true;
351
+ metadata = '';
352
+ }
353
+
354
+ if (isReadingMetadata) {
355
+ metadata += chunk;
356
+ if (chunk.includes('</report-metadata>')) {
357
+ isReadingMetadata = false;
358
+ processMetadata(metadata);
359
+ }
360
+ } else {
361
+ markdown += chunk;
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;
375
+ const reportContent = markdown.match(/<report>([\s\S]*)<\/report>/);
376
+
377
+ if (reportContent) {
378
+ reportContainer.innerHTML = marked.parse(reportContent[1]);
379
+ } else {
380
+ reportContainer.innerHTML = marked.parse(markdown);
381
+ }
382
+
383
+ const links = reportContainer.getElementsByTagName('a');
384
+ Array.from(links).forEach(link => {
385
+ link.setAttribute('target', '_blank');
386
+ });
387
+
388
+ const scripts = reportContainer.getElementsByTagName('script');
389
+ Array.from(scripts).forEach(script => {
390
+ const newScript = document.createElement('script');
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: (.+)/);
406
+
407
+ if (metadataMatch) {
408
+ const metadataObj = JSON.parse(metadataMatch[1]);
409
+
410
+ sourcesContainer.innerHTML = '<h2>Sources</h2>';
411
+ metadataObj.forEach(([content, url]) => {
412
+ if (content.trim() !== "") {
413
+ const sourceItem = document.createElement('div');
414
+ sourceItem.className = 'source-item';
415
+ const snippet = content.length > 400 ? content.substring(0, 400) + '...' : content;
416
+ sourceItem.innerHTML = `
417
+ <a href="${url}" target="_blank" rel="noopener noreferrer" class="source-url">${url}</a>
418
+ <div class="source-content">
419
+ <div class="source-snippet">${marked.parse(snippet)}</div>
420
+ <div class="source-full">${marked.parse(content)}</div>
421
+ <div class="expand-indicator"></div>
422
+ </div>
423
+ `;
424
+ sourcesContainer.appendChild(sourceItem);
425
+
426
+ const sourceLinks = sourceItem.querySelectorAll('.source-content a');
427
+ sourceLinks.forEach(link => {
428
+ link.setAttribute('target', '_blank');
429
+ link.setAttribute('rel', 'noopener noreferrer');
430
+ });
431
+
432
+ const sourceUrl = sourceItem.querySelector('.source-url');
433
+ const sourceContent = sourceItem.querySelector('.source-content');
434
+ const snippetDiv = sourceItem.querySelector('.source-snippet');
435
+ const fullDiv = sourceItem.querySelector('.source-full');
436
+
437
+ sourceContent.addEventListener('click', function(e) {
438
+ if (!sourceItem.classList.contains('expanded')) {
439
+ sourceItem.classList.add('expanded');
440
+ snippetDiv.style.display = 'none';
441
+ fullDiv.style.display = 'block';
442
+ } else if (e.clientY > sourceContent.getBoundingClientRect().bottom - 30) {
443
+ sourceItem.classList.remove('expanded');
444
+ snippetDiv.style.display = 'block';
445
+ fullDiv.style.display = 'none';
446
+ }
447
+ });
448
+
449
+ sourceUrl.addEventListener('click', function(e) {
450
+ e.stopPropagation();
451
+ });
452
+ }
453
+ });
454
+ } else {
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;
462
+ const scrollDifference = newHeight - previousHeight;
463
+
464
+ if (scrollDifference > 0) {
465
+ const viewportHeight = window.innerHeight;
466
+ const currentScrollPosition = window.pageYOffset;
467
+ const contentBottom = reportContainer.offsetTop + newHeight;
468
+
469
+ if (contentBottom > currentScrollPosition + viewportHeight - 200) {
470
+ window.scrollBy({
471
+ top: scrollDifference,
472
+ behavior: 'smooth'
473
+ });
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;
504
+ }
505
+ .source-snippet, .expand-indicator {
506
+ display: none;
507
+ }
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>