-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
1543 lines (1323 loc) · 55.1 KB
/
app.py
File metadata and controls
1543 lines (1323 loc) · 55.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
PaperTrack-Agent - Streamlit UI
A futuristic, tech-inspired interface for paper research
"""
import streamlit as st
import json
import time
from pathlib import Path
from datetime import datetime, timedelta
import plotly.express as px
import plotly.graph_objects as go
from typing import Dict, List, Any
import sys
# Add src to path
sys.path.insert(0, str(Path(__file__).parent / "src"))
# Page config - must be first
st.set_page_config(
page_title="PaperTrack Agent",
page_icon="🔬",
layout="wide",
initial_sidebar_state="expanded",
)
# Custom CSS for tech/cyberpunk style
st.markdown("""
<style>
/* Main background */
.stApp {
background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 50%, #16213e 100%);
}
/* Sidebar */
[data-testid="stSidebar"] {
background: linear-gradient(180deg, #0f0f23 0%, #1a1a2e 100%);
border-right: 1px solid #00d4ff33;
}
/* Headers */
h1, h2, h3 {
background: linear-gradient(90deg, #00d4ff, #7b2cbf, #ff006e);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
font-weight: 700;
}
/* Cards */
.cyber-card {
background: linear-gradient(145deg, #1a1a2e 0%, #0f0f23 100%);
border: 1px solid #00d4ff33;
border-radius: 15px;
padding: 20px;
margin: 10px 0;
box-shadow: 0 0 20px rgba(0, 212, 255, 0.1);
transition: all 0.3s ease;
}
.cyber-card:hover {
border-color: #00d4ff;
box-shadow: 0 0 30px rgba(0, 212, 255, 0.3);
transform: translateY(-2px);
}
/* Glowing text */
.glow-text {
color: #00d4ff;
text-shadow: 0 0 10px #00d4ff, 0 0 20px #00d4ff, 0 0 30px #00d4ff;
}
/* Progress bar */
.stProgress > div > div {
background: linear-gradient(90deg, #00d4ff, #7b2cbf, #ff006e);
}
/* Buttons */
.stButton > button {
background: linear-gradient(90deg, #00d4ff, #7b2cbf);
color: white;
border: none;
border-radius: 25px;
padding: 10px 30px;
font-weight: 600;
transition: all 0.3s ease;
box-shadow: 0 0 15px rgba(0, 212, 255, 0.3);
}
.stButton > button:hover {
transform: scale(1.05);
box-shadow: 0 0 25px rgba(0, 212, 255, 0.5);
}
/* Input fields */
.stTextInput > div > div > input,
.stSelectbox > div > div > select {
background: #1a1a2e;
border: 1px solid #00d4ff33;
color: #e0e0e0;
border-radius: 10px;
}
/* Metrics */
[data-testid="stMetricValue"] {
color: #00d4ff;
font-size: 2rem;
text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}
/* Expander */
.streamlit-expanderHeader {
background: #1a1a2e;
border: 1px solid #00d4ff33;
border-radius: 10px;
}
/* Agent status badge */
.agent-badge {
display: inline-block;
padding: 5px 15px;
border-radius: 20px;
font-size: 0.8rem;
font-weight: 600;
margin: 5px;
}
.agent-active {
background: linear-gradient(90deg, #00ff88, #00d4ff);
color: #0a0a0a;
animation: pulse 2s infinite;
}
.agent-idle {
background: #333;
color: #888;
}
.agent-complete {
background: linear-gradient(90deg, #7b2cbf, #ff006e);
color: white;
}
@keyframes pulse {
0%, 100% { box-shadow: 0 0 5px #00ff88; }
50% { box-shadow: 0 0 20px #00ff88; }
}
/* Animated border */
.animated-border {
position: relative;
background: #1a1a2e;
border-radius: 15px;
padding: 20px;
}
.animated-border::before {
content: '';
position: absolute;
top: -2px; left: -2px; right: -2px; bottom: -2px;
background: linear-gradient(45deg, #00d4ff, #7b2cbf, #ff006e, #00d4ff);
border-radius: 17px;
z-index: -1;
animation: borderRotate 3s linear infinite;
background-size: 400% 400%;
}
@keyframes borderRotate {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
/* Paper card */
.paper-card {
background: linear-gradient(145deg, #1f1f3a 0%, #151528 100%);
border-left: 4px solid #00d4ff;
padding: 15px 20px;
margin: 10px 0;
border-radius: 0 10px 10px 0;
transition: all 0.3s ease;
}
.paper-card:hover {
border-left-color: #ff006e;
transform: translateX(5px);
}
/* Insight card */
.insight-card {
background: linear-gradient(145deg, #1f1f3a 0%, #151528 100%);
border: 1px solid #7b2cbf55;
border-radius: 15px;
padding: 20px;
margin: 15px 0;
transition: all 0.3s ease;
}
.insight-card:hover {
border-color: #7b2cbf;
box-shadow: 0 0 25px rgba(123, 44, 191, 0.3);
}
/* Trend badge */
.trend-badge {
display: inline-block;
padding: 3px 12px;
border-radius: 15px;
font-size: 0.75rem;
font-weight: 600;
margin: 3px;
}
.trend-hot {
background: linear-gradient(90deg, #ff006e, #ff4444);
color: white;
}
.trend-rising {
background: linear-gradient(90deg, #00d4ff, #00ff88);
color: #0a0a0a;
}
.trend-stable {
background: #444;
color: #aaa;
}
/* Method comparison card */
.method-card {
background: linear-gradient(145deg, #1a2a3a 0%, #0f1a2a 100%);
border: 1px solid #00d4ff33;
border-radius: 12px;
padding: 15px;
margin: 10px 0;
}
/* Stats grid */
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 15px;
margin: 20px 0;
}
.stat-item {
background: linear-gradient(145deg, #1a1a2e 0%, #0f0f23 100%);
border: 1px solid #00d4ff22;
border-radius: 10px;
padding: 15px;
text-align: center;
}
.stat-value {
font-size: 1.8rem;
font-weight: 700;
color: #00d4ff;
}
.stat-label {
font-size: 0.85rem;
color: #888;
margin-top: 5px;
}
/* Timeline */
.timeline-item {
position: relative;
padding-left: 30px;
padding-bottom: 20px;
border-left: 2px solid #00d4ff33;
}
.timeline-item::before {
content: '';
position: absolute;
left: -6px;
top: 0;
width: 10px;
height: 10px;
border-radius: 50%;
background: #00d4ff;
box-shadow: 0 0 10px #00d4ff;
}
</style>
""", unsafe_allow_html=True)
def create_header():
"""Create animated header"""
st.markdown("""
<div style="text-align: center; padding: 20px;">
<h1 style="font-size: 3rem; margin-bottom: 0;">
🔬 PaperTrack Agent
</h1>
<p style="color: #888; font-size: 1.2rem;">
AI-Powered Research Paper Analysis System
</p>
<div style="display: flex; justify-content: center; gap: 20px; margin-top: 20px;">
<span class="agent-badge agent-idle">🎯 Field Tracker</span>
<span class="agent-badge agent-idle">📥 Paper Retrieval</span>
<span class="agent-badge agent-idle">📖 Paper Reader</span>
<span class="agent-badge agent-idle">💻 Code Extractor</span>
<span class="agent-badge agent-idle">📊 Analyzer</span>
</div>
</div>
""", unsafe_allow_html=True)
def create_phase_progress(current_phase: int, total_phases: int = 5):
"""Create phase progress indicator"""
phases = ["Discovery", "Analysis", "Comparison", "Innovation", "Writing"]
cols = st.columns(5)
for i, (col, phase_name) in enumerate(zip(cols, phases)):
with col:
if i + 1 < current_phase:
status = "✅"
color = "#00ff88"
elif i + 1 == current_phase:
status = "🔄"
color = "#00d4ff"
else:
status = "⏳"
color = "#444"
st.markdown(f"""
<div style="text-align: center;">
<div style="
width: 50px; height: 50px;
border-radius: 50%;
background: {color}22;
border: 2px solid {color};
display: flex; align-items: center; justify-content: center;
margin: 0 auto; font-size: 1.5rem;
">{status}</div>
<p style="color: {color}; margin-top: 10px; font-size: 0.9rem;">{phase_name}</p>
</div>
""", unsafe_allow_html=True)
def create_agent_status_panel(agent_states: Dict[str, str]):
"""Create real-time agent status panel"""
st.markdown("### 🤖 Agent Status")
cols = st.columns(5)
agents = [
("Field Tracker", "🎯"),
("Paper Retrieval", "📥"),
("Paper Reader", "📖"),
("Code Extractor", "💻"),
("Analyzer", "📊"),
]
for col, (agent_name, icon) in zip(cols, agents):
with col:
status = agent_states.get(agent_name, "idle")
if status == "running":
badge_class = "agent-active"
status_text = "Running..."
elif status == "complete":
badge_class = "agent-complete"
status_text = "Complete"
else:
badge_class = "agent-idle"
status_text = "Idle"
st.markdown(f"""
<div class="cyber-card" style="text-align: center; padding: 15px;">
<div style="font-size: 2rem;">{icon}</div>
<div style="color: #ddd; margin: 10px 0;">{agent_name}</div>
<span class="agent-badge {badge_class}">{status_text}</span>
</div>
""", unsafe_allow_html=True)
def create_paper_card(paper: Dict[str, Any], index: int, paper_analyses: Dict[str, Any] = None):
"""Create a styled paper card with expandable details"""
title = paper.get("title", "Unknown Title")
authors = paper.get("authors", [])
if isinstance(authors, list):
authors_str = ", ".join(str(a) for a in authors[:3]) + ("..." if len(authors) > 3 else "")
else:
authors_str = str(authors)
abstract = paper.get("abstract", "No abstract available")
arxiv_id = paper.get("arxiv_id", "")
published = paper.get("published", paper.get("published_date", ""))
pdf_path = paper.get("pdf_path", "")
pdf_url = paper.get("pdf_url", f"https://arxiv.org/pdf/{arxiv_id}")
# Get detailed analysis if available
analysis = None
if paper_analyses:
for field_analyses in paper_analyses.values():
if isinstance(field_analyses, list):
for a in field_analyses:
if a.get("arxiv_id") == arxiv_id:
analysis = a
break
# Also check if paper itself has analysis data
if not analysis and paper.get("structure"):
analysis = paper
# Create expandable card
with st.expander(f"📄 #{index + 1} - {title[:80]}{'...' if len(title) > 80 else ''}", expanded=False):
# Header info
st.markdown(f"""
<div style="margin-bottom: 15px;">
<h4 style="color: #00d4ff; margin: 0 0 10px 0;">{title}</h4>
<p style="color: #888; font-size: 0.9rem; margin: 5px 0;">👥 {authors_str}</p>
<div style="margin-top: 8px;">
<span style="color: #666; font-size: 0.85rem;">📅 {published[:10] if published else 'N/A'}</span>
<span style="color: #666; font-size: 0.85rem; margin-left: 15px;">🔗 {arxiv_id}</span>
</div>
</div>
""", unsafe_allow_html=True)
# Action buttons
col1, col2, col3 = st.columns(3)
with col1:
st.link_button("📥 View PDF (arXiv)", pdf_url, use_container_width=True)
with col2:
if pdf_path and Path(pdf_path).exists():
st.success("✅ PDF Downloaded")
else:
st.warning("⚠️ PDF Not Downloaded")
with col3:
abs_url = f"https://arxiv.org/abs/{arxiv_id}"
st.link_button("🔗 arXiv Page", abs_url, use_container_width=True)
st.markdown("---")
# Tabs for different sections
detail_tabs = st.tabs(["📝 Abstract", "🔬 Methods", "📊 Results", "💡 Contributions"])
with detail_tabs[0]:
st.markdown("#### Abstract")
st.markdown(f"<div style='color: #ccc; line-height: 1.6;'>{abstract}</div>", unsafe_allow_html=True)
with detail_tabs[1]:
if analysis and analysis.get("structure"):
structure = analysis.get("structure", {})
# Introduction
intro = structure.get("introduction", "")
if intro:
st.markdown("#### Introduction")
st.markdown(f"<div style='color: #aaa; line-height: 1.6;'>{intro[:1000]}{'...' if len(intro) > 1000 else ''}</div>", unsafe_allow_html=True)
# Methodology
methodology = structure.get("methodology", "")
if methodology:
st.markdown("#### Methodology")
st.markdown(f"<div style='color: #aaa; line-height: 1.6;'>{methodology}</div>", unsafe_allow_html=True)
# Technical details - algorithms
tech = analysis.get("technical_details", {})
algorithms = tech.get("algorithms", [])
if algorithms:
st.markdown("#### Algorithms")
for algo in algorithms:
if isinstance(algo, dict):
st.markdown(f"""
<div class="method-card" style="margin: 10px 0; padding: 12px; background: #1a2a3a; border-radius: 8px; border-left: 3px solid #00d4ff;">
<strong style="color: #00d4ff;">{algo.get('name', 'Algorithm')}</strong>
<p style="color: #aaa; margin: 8px 0; font-size: 0.9rem;">{algo.get('description', '')}</p>
<p style="color: #7b2cbf; font-size: 0.85rem;"><em>Novelty: {algo.get('novelty', 'N/A')}</em></p>
</div>
""", unsafe_allow_html=True)
else:
st.info("No detailed methodology analysis available. Run the full pipeline to generate analysis.")
with detail_tabs[2]:
if analysis and analysis.get("structure"):
structure = analysis.get("structure", {})
# Experiments
experiments = structure.get("experiments", "")
if experiments:
st.markdown("#### Experiments")
st.markdown(f"<div style='color: #aaa; line-height: 1.6;'>{experiments}</div>", unsafe_allow_html=True)
# Results
results = structure.get("results", "")
if results:
st.markdown("#### Results")
st.markdown(f"<div style='color: #aaa; line-height: 1.6;'>{results}</div>", unsafe_allow_html=True)
# Metrics
tech = analysis.get("technical_details", {})
metrics = tech.get("metrics", [])
if metrics:
st.markdown("#### Performance Metrics")
for metric in metrics:
if isinstance(metric, dict):
st.markdown(f"- **{metric.get('name', 'Metric')}**: {metric.get('value', 'N/A')} - {metric.get('comparison', '')}")
# Baselines
baselines = tech.get("baselines", [])
if baselines:
st.markdown("#### Baselines Compared")
st.markdown(", ".join(str(b) for b in baselines))
else:
st.info("No detailed results analysis available. Run the full pipeline to generate analysis.")
with detail_tabs[3]:
if analysis and analysis.get("structure"):
structure = analysis.get("structure", {})
# Key contributions
contributions = structure.get("key_contributions", [])
if contributions:
st.markdown("#### Key Contributions")
for i, contrib in enumerate(contributions, 1):
st.markdown(f"""
<div style="margin: 10px 0; padding: 10px; background: #1f1f3a; border-radius: 8px; border-left: 3px solid #7b2cbf;">
<span style="color: #7b2cbf; font-weight: bold;">{i}.</span>
<span style="color: #ddd;"> {contrib}</span>
</div>
""", unsafe_allow_html=True)
# Keywords
keywords = structure.get("keywords", [])
if keywords:
st.markdown("#### Keywords")
kw_html = " ".join([f'<span style="background: #00d4ff22; border: 1px solid #00d4ff; padding: 3px 10px; border-radius: 15px; margin: 3px; display: inline-block; color: #00d4ff; font-size: 0.85rem;">{kw}</span>' for kw in keywords])
st.markdown(f"<div style='margin: 10px 0;'>{kw_html}</div>", unsafe_allow_html=True)
# Conclusion
conclusion = structure.get("conclusion", "")
if conclusion:
st.markdown("#### Conclusion")
st.markdown(f"<div style='color: #aaa; line-height: 1.6;'>{conclusion}</div>", unsafe_allow_html=True)
else:
st.info("No detailed contribution analysis available. Run the full pipeline to generate analysis.")
def create_metrics_dashboard(state: Dict[str, Any]):
"""Create metrics dashboard with animations"""
col1, col2, col3, col4 = st.columns(4)
with col1:
tracked = sum(len(v.get("papers", [])) for v in state.get("tracked_papers", {}).values() if isinstance(v, dict))
st.metric("📚 Papers Tracked", tracked)
with col2:
downloaded = sum(
sum(1 for p in papers if p.get("download_status") == "success")
for papers in state.get("retrieved_papers", {}).values()
if isinstance(papers, list)
)
st.metric("📥 Downloaded", downloaded)
with col3:
analyzed = sum(
sum(1 for p in papers if p.get("read_status") == "success")
for papers in state.get("paper_analyses", {}).values()
if isinstance(papers, list)
)
st.metric("🔍 Analyzed", analyzed)
with col4:
ideas = len(state.get("research_gaps", {}).get("research_ideas", []))
st.metric("💡 Ideas Generated", ideas)
def create_trend_chart(trend_data: Dict[str, Any]):
"""Create interactive trend visualization"""
if not trend_data or "error" in trend_data:
st.info("No trend data available yet. Run the analysis to generate trends.")
return
# Get keywords data
keywords = trend_data.get("keywords", {})
hot_keywords = keywords.get("hot_keywords", [])
if hot_keywords:
# Create keyword frequency chart
st.markdown("#### 🔥 Hot Keywords")
kw_names = [kw.get("keyword", "Unknown")[:20] for kw in hot_keywords[:10]]
kw_counts = [kw.get("count", kw.get("frequency", 1)) for kw in hot_keywords[:10]]
fig = go.Figure(go.Bar(
x=kw_counts,
y=kw_names,
orientation='h',
marker=dict(
color=kw_counts,
colorscale=[[0, '#00d4ff'], [0.5, '#7b2cbf'], [1, '#ff006e']],
),
))
fig.update_layout(
template="plotly_dark",
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
height=400,
margin=dict(l=10, r=10, t=30, b=10),
yaxis=dict(autorange="reversed"),
xaxis_title="Frequency",
)
st.plotly_chart(fig, use_container_width=True)
# Display keywords as badges
st.markdown("#### 📈 Trending Topics")
badge_html = ""
for i, kw in enumerate(hot_keywords[:15]):
name = kw.get("keyword", "Unknown")
if i < 3:
badge_class = "trend-hot"
elif i < 8:
badge_class = "trend-rising"
else:
badge_class = "trend-stable"
badge_html += f'<span class="trend-badge {badge_class}">{name}</span>'
st.markdown(f'<div style="margin: 15px 0;">{badge_html}</div>', unsafe_allow_html=True)
# Technology evolution
tech_evolution = trend_data.get("technology_evolution", {})
if tech_evolution:
st.markdown("#### 🚀 Technology Evolution")
col1, col2 = st.columns(2)
with col1:
emerging = tech_evolution.get("emerging_technologies", [])
if emerging:
st.markdown("**Emerging Technologies:**")
for tech in emerging[:5]:
if isinstance(tech, dict):
st.markdown(f"- 🌟 {tech.get('name', tech)}")
else:
st.markdown(f"- 🌟 {tech}")
with col2:
mature = tech_evolution.get("mature_technologies", [])
if mature:
st.markdown("**Mature Technologies:**")
for tech in mature[:5]:
if isinstance(tech, dict):
st.markdown(f"- ✅ {tech.get('name', tech)}")
else:
st.markdown(f"- ✅ {tech}")
# Research directions
directions = trend_data.get("future_directions", trend_data.get("research_directions", []))
if directions:
st.markdown("#### 🔮 Future Research Directions")
for i, direction in enumerate(directions[:5]):
if isinstance(direction, dict):
text = direction.get("direction", direction.get("description", str(direction)))
else:
text = str(direction)
st.markdown(f"""
<div class="timeline-item">
<strong style="color: #00d4ff;">Direction {i+1}</strong>
<p style="color: #aaa; margin: 5px 0;">{text}</p>
</div>
""", unsafe_allow_html=True)
def create_radar_chart(papers: List[Dict[str, Any]]):
"""Create paper comparison radar chart"""
if not papers:
st.info("No papers available for comparison")
return
categories = ['Novelty', 'Methodology', 'Results', 'Reproducibility', 'Impact']
fig = go.Figure()
colors = ['#00d4ff', '#7b2cbf', '#ff006e', '#00ff88', '#ffaa00']
for i, paper in enumerate(papers[:5]):
title = paper.get("structure", {}).get("title", paper.get("title", f"Paper {i+1}"))
if len(title) > 30:
title = title[:30] + "..."
# Generate scores based on paper content analysis
structure = paper.get("structure", {})
technical = paper.get("technical_details", {})
# Calculate scores (simplified scoring)
novelty = min(5, 3 + len(structure.get("key_contributions", [])) * 0.5)
methodology = min(5, 3 + len(technical.get("algorithms", [])) * 0.3)
results = min(5, 3 + len(technical.get("metrics", [])) * 0.4)
reproducibility = 4 if technical.get("implementation", {}).get("code_available") else 2.5
impact = min(5, 3 + len(technical.get("datasets", [])) * 0.3)
values = [novelty, methodology, results, reproducibility, impact]
values.append(values[0]) # Close the radar
fig.add_trace(go.Scatterpolar(
r=values,
theta=categories + [categories[0]],
fill='toself',
name=title,
opacity=0.7,
line=dict(color=colors[i % len(colors)]),
))
fig.update_layout(
polar=dict(
radialaxis=dict(visible=True, range=[0, 5]),
bgcolor='rgba(0,0,0,0)',
),
template="plotly_dark",
paper_bgcolor='rgba(0,0,0,0)',
title="Paper Quality Comparison",
showlegend=True,
legend=dict(
orientation="h",
yanchor="bottom",
y=-0.3,
xanchor="center",
x=0.5
),
height=450,
)
st.plotly_chart(fig, use_container_width=True)
def create_analysis_view(state: Dict[str, Any]):
"""Create comprehensive analysis view"""
comp = state.get("comparative_analysis", {})
if not comp or isinstance(comp, str):
st.info("No comparative analysis available yet. Run the full pipeline to generate analysis.")
return
# Method Comparison Section
st.markdown("### 🔬 Method Comparison")
method_comp = comp.get("method_comparison", {})
col1, col2 = st.columns(2)
with col1:
# Common approaches
common = method_comp.get("common_approaches", [])
if common:
st.markdown("#### Common Approaches")
for approach in common[:6]:
st.markdown(f"""
<div class="method-card">
<span style="color: #00d4ff;">✓</span>
<span style="color: #ddd; margin-left: 10px;">{approach}</span>
</div>
""", unsafe_allow_html=True)
with col2:
# Unique methods
unique = method_comp.get("unique_methods", [])
if unique:
st.markdown("#### Unique Methods")
for method in unique[:6]:
if isinstance(method, dict):
paper = method.get("paper", "Unknown")[:25]
method_text = method.get("method", "N/A")
novelty = method.get("novelty", "")
st.markdown(f"""
<div class="method-card">
<div style="color: #7b2cbf; font-weight: 600;">{paper}</div>
<div style="color: #ddd; margin: 5px 0;">{method_text}</div>
<div style="color: #888; font-size: 0.85rem;">💡 {novelty}</div>
</div>
""", unsafe_allow_html=True)
# Strengths & Weaknesses
st.markdown("---")
st.markdown("### 💪 Strengths & Weaknesses Analysis")
sw_analysis = method_comp.get("strengths_weaknesses", [])
if sw_analysis:
for item in sw_analysis[:4]:
if isinstance(item, dict):
paper = item.get("paper", "Unknown Paper")
strengths = item.get("strengths", [])
weaknesses = item.get("weaknesses", [])
with st.expander(f"📄 {paper[:50]}"):
col1, col2 = st.columns(2)
with col1:
st.markdown("**✅ Strengths:**")
for s in strengths[:4]:
st.markdown(f"- {s}")
with col2:
st.markdown("**⚠️ Weaknesses:**")
for w in weaknesses[:4]:
st.markdown(f"- {w}")
# Results Comparison
st.markdown("---")
st.markdown("### 📊 Results Comparison")
result_comp = comp.get("result_comparison", {})
col1, col2, col3 = st.columns(3)
with col1:
datasets = result_comp.get("common_datasets", [])
if datasets:
st.markdown("**📁 Common Datasets:**")
for ds in datasets[:5]:
st.markdown(f"- {ds}")
with col2:
metrics = result_comp.get("common_metrics", [])
if metrics:
st.markdown("**📏 Common Metrics:**")
for m in metrics[:5]:
st.markdown(f"- {m}")
with col3:
best = result_comp.get("best_performing", {})
if best:
st.markdown("**🏆 Best Performing:**")
st.markdown(f"**{best.get('paper', 'N/A')}**")
st.markdown(f"_{best.get('reason', '')}_")
# Insights
insights = result_comp.get("result_insights", [])
if insights:
st.markdown("#### 💡 Key Insights")
for insight in insights[:5]:
st.info(insight)
# Research Themes
st.markdown("---")
st.markdown("### 🎯 Research Themes")
themes = comp.get("research_themes", {})
main_themes = themes.get("main_themes", [])
if main_themes:
cols = st.columns(min(3, len(main_themes)))
for i, theme in enumerate(main_themes[:3]):
with cols[i]:
if isinstance(theme, dict):
st.markdown(f"""
<div class="insight-card">
<h4 style="color: #00d4ff; margin: 0;">{theme.get('theme', 'Theme')}</h4>
<p style="color: #aaa; font-size: 0.9rem; margin: 10px 0;">
{theme.get('description', '')[:150]}
</p>
<div style="margin-top: 10px;">
<strong style="color: #888;">Related Papers:</strong>
<div style="color: #666; font-size: 0.85rem;">
{', '.join(str(p)[:20] for p in theme.get('papers', [])[:3])}
</div>
</div>
</div>
""", unsafe_allow_html=True)
def create_insights_view(state: Dict[str, Any]):
"""Create research insights and gaps view"""
gaps = state.get("research_gaps", {})
if not gaps:
st.info("No research insights available yet. Run the full pipeline including Phase 4 to generate insights.")
# Show placeholder with what will be available
st.markdown("""
<div class="cyber-card">
<h3 style="color: #7b2cbf;">🔮 What you'll discover:</h3>
<ul style="color: #aaa;">
<li>Identified research gaps in the field</li>
<li>Novel research ideas and directions</li>
<li>Unexplored combinations of methods</li>
<li>Potential high-impact research opportunities</li>
</ul>
</div>
""", unsafe_allow_html=True)
return
# Research Ideas
ideas = gaps.get("research_ideas", [])
if ideas:
st.markdown("### 💡 Generated Research Ideas")
for i, idea in enumerate(ideas[:5]):
if isinstance(idea, dict):
title = idea.get("title", f"Research Idea {i+1}")
motivation = idea.get("motivation", "")
approach = idea.get("approach", "")
contribution = idea.get("expected_contribution", "")
feasibility = idea.get("feasibility", "Medium")
# Feasibility color
feas_color = {"High": "#00ff88", "Medium": "#ffaa00", "Low": "#ff4444"}.get(feasibility, "#888")
st.markdown(f"""
<div class="insight-card">
<div style="display: flex; justify-content: space-between; align-items: start;">
<h4 style="color: #00d4ff; margin: 0;">💡 {title}</h4>
<span style="
background: {feas_color}22;
border: 1px solid {feas_color};
color: {feas_color};
padding: 3px 10px;
border-radius: 10px;
font-size: 0.8rem;
">{feasibility} Feasibility</span>
</div>
<div style="margin-top: 15px;">
<p style="color: #888; margin-bottom: 5px;"><strong>Motivation:</strong></p>
<p style="color: #aaa;">{motivation}</p>
</div>
<div style="margin-top: 10px;">
<p style="color: #888; margin-bottom: 5px;"><strong>Approach:</strong></p>
<p style="color: #aaa;">{approach}</p>
</div>
<div style="margin-top: 10px;">
<p style="color: #888; margin-bottom: 5px;"><strong>Expected Contribution:</strong></p>
<p style="color: #ddd;">{contribution}</p>
</div>
</div>
""", unsafe_allow_html=True)
# Research Gaps
identified_gaps = gaps.get("gaps", gaps.get("identified_gaps", []))
if identified_gaps:
st.markdown("---")
st.markdown("### 🔍 Identified Research Gaps")
for gap in identified_gaps[:6]:
if isinstance(gap, dict):
area = gap.get("area", gap.get("gap", "Unknown Area"))
description = gap.get("description", "")
importance = gap.get("importance", "Medium")
imp_color = {"High": "#ff006e", "Medium": "#7b2cbf", "Low": "#444"}.get(importance, "#444")
st.markdown(f"""
<div class="method-card" style="border-left: 4px solid {imp_color};">
<div style="display: flex; justify-content: space-between;">
<strong style="color: #ddd;">{area}</strong>
<span style="color: {imp_color}; font-size: 0.85rem;">{importance} Priority</span>
</div>
<p style="color: #888; margin-top: 8px; font-size: 0.9rem;">{description}</p>
</div>
""", unsafe_allow_html=True)
else:
st.markdown(f"- {gap}")
# Unexplored Combinations
combinations = gaps.get("unexplored_combinations", [])
if combinations:
st.markdown("---")
st.markdown("### 🧬 Unexplored Method Combinations")
cols = st.columns(2)
for i, combo in enumerate(combinations[:4]):
with cols[i % 2]:
if isinstance(combo, dict):
methods = combo.get("methods", [])
potential = combo.get("potential", "")
st.markdown(f"""
<div class="cyber-card" style="padding: 15px;">
<div style="color: #00d4ff; font-weight: 600;">
{' + '.join(methods[:3])}
</div>
<p style="color: #888; font-size: 0.9rem; margin-top: 8px;">{potential}</p>
</div>
""", unsafe_allow_html=True)
def run_pipeline_with_ui(research_fields: List[str], time_range: str, max_papers: int, custom_days: int = None):
"""Run pipeline with real-time UI updates"""
from src.agents import (
FieldTrackerAgent,
PaperRetrievalAgent,
PaperReaderAgent,
CodeExtractorAgent,
ComparativeAnalysisAgent,
TrendAnalyzerAgent,
ResearchGapFinderAgent,
)
# Determine actual time range
actual_time_range = time_range
if time_range == "custom" and custom_days:
actual_time_range = f"last_{custom_days}_days"
# Initialize state
state = {
"research_fields": research_fields,
"time_range": actual_time_range,
"max_papers_per_field": max_papers,
"tracked_papers": {},
"retrieved_papers": {},
"paper_analyses": {},
"code_extractions": {},
"comparative_analysis": {},
"trend_analysis": {},
"citation_network": {},