File size: 25,710 Bytes
240e5bc
 
 
5c29668
240e5bc
 
 
 
 
 
5c29668
 
240e5bc
 
 
 
5c29668
240e5bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5c29668
240e5bc
 
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
"""
Technical Mindmap Generator - Main Streamlit Application
Interactive web app for generating radial mindmaps from technical keywords

Features:
- Modern UI inspired by GPT, Claude, and Perplexity
- Sequential API calls for optimal data quality
- Interactive radial mindmaps with PyVis
- Query history and session management
- Real-time data from Tavily, Knowledge Graph, and Gemini APIs
"""

import streamlit as st
import sys
from pathlib import Path
import time

# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

# Import project modules
try:
    from config.settings import settings, display_settings_info
    from utils.api_handler import fetch_mindmap_data
    from utils.mindmap_generator import MindmapGenerator
except ImportError as e:
    st.error(f"Import Error: {e}")
    st.info("Make sure all project files are in the correct directories")
    st.stop()


# ============================================================================
# PAGE CONFIGURATION
# ============================================================================

st.set_page_config(
    page_title="Technical Mindmap Generator 🧠",
    page_icon="🧠",
    layout="wide",
    initial_sidebar_state="collapsed",
    menu_items={
        'Get Help': None,
        'Report a bug': None,
        'About': "# Technical Mindmap Generator\nPowered by Gemini, Tavily, and Knowledge Graph APIs"
    }
)


# ============================================================================
# CUSTOM CSS STYLING
# ============================================================================

st.markdown("""
<style>
    /* Import Google Fonts - Claude uses serif fonts */
    @import url('https://fonts.googleapis.com/css2?family=Merriweather:wght@300;400;700&family=Inter:wght@400;500;600;700&display=swap');
    
    /* ============================================================
       MAIN CONTAINER - Claude's Warm Aesthetic
    ============================================================ */
    .main {
        background: #faf9f5;
        padding: 2rem;
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    }

    /* Remove default padding */
    .block-container {
        padding-top: 2rem;
        padding-bottom: 3rem;
        max-width: 1000px;
    }

    /* ============================================================
       HEADER SECTION
    ============================================================ */
    h1 {
        color: #3d3929 !important;
        text-align: center !important;
        font-size: 3.2rem !important;
        font-weight: 700 !important;
        margin-bottom: 0.5rem !important;
        letter-spacing: -0.5px !important;
        font-family: 'Merriweather', serif !important;
    }

    /* Subtitle */
    .subtitle {
        color: #6b6656 !important;
        text-align: center !important;
        font-size: 1.2rem !important;
        margin-bottom: 3rem !important;
        font-weight: 400 !important;
        font-family: 'Inter', sans-serif !important;
        line-height: 1.6 !important;
    }

    /* ============================================================
       INPUT CONTAINER - Claude's Clean Design
    ============================================================ */
    .stTextInput > div > div > input {
        background: #ffffff !important;
        color: #3d3929 !important;
        border-radius: 12px !important;
        padding: 18px 24px !important;
        font-size: 16px !important;
        font-weight: 400 !important;
        border: 1.5px solid #ddd9cc !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06) !important;
        transition: all 0.2s ease !important;
        font-family: 'Inter', sans-serif !important;
    }

    .stTextInput > div > div > input:focus {
        border-color: #c15f3c !important;
        box-shadow: 0 0 0 3px rgba(193, 95, 60, 0.1),
                    0 1px 3px rgba(0, 0, 0, 0.06) !important;
        outline: none !important;
    }
    
    .stTextInput > div > div > input::placeholder {
        color: #9b9688;
        font-weight: 400;
    }

    /* ============================================================
       BUTTON STYLING - Claude's Orange
    ============================================================ */
    .stButton > button {
        background: #c15f3c !important;
        color: #ffffff !important;
        border-radius: 10px !important;
        padding: 14px 32px !important;
        font-size: 15px !important;
        font-weight: 600 !important;
        border: none !important;
        box-shadow: 0 2px 4px rgba(193, 95, 60, 0.2) !important;
        transition: all 0.2s ease !important;
        font-family: 'Inter', sans-serif !important;
        letter-spacing: 0.3px !important;
    }

    .stButton > button:hover {
        background: #a14a2f !important;
        box-shadow: 0 4px 8px rgba(193, 95, 60, 0.25) !important;
        transform: translateY(-1px) !important;
    }

    .stButton > button:active {
        transform: translateY(0) !important;
        box-shadow: 0 1px 2px rgba(193, 95, 60, 0.2) !important;
    }

    /* ============================================================
       MINDMAP CARD - Clean White Container
    ============================================================ */
    .mindmap-card {
        background: #ffffff;
        border-radius: 16px;
        padding: 2.5rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08),
                    0 1px 2px rgba(0, 0, 0, 0.04);
        margin: 2rem 0;
        border: 1px solid #ebe9e0;
    }

    .mindmap-card h3 {
        color: #3d3929 !important;
        font-weight: 700 !important;
        margin-bottom: 1rem !important;
        font-size: 1.6rem !important;
        font-family: 'Merriweather', serif !important;
    }
    
    .mindmap-card p {
        color: #6b6656;
        font-size: 1rem;
        margin-bottom: 1.5rem;
        line-height: 1.6;
    }

    /* ============================================================
       SUCCESS/INFO/ERROR MESSAGES - Claude Style
    ============================================================ */
    .stSuccess {
        background: #f0f8f5 !important;
        border-radius: 12px !important;
        padding: 1.2rem !important;
        border-left: 4px solid #4a9d7f !important;
        color: #3d3929 !important;
        font-family: 'Inter', sans-serif !important;
    }
    
    .stInfo {
        background: #f5f3ed !important;
        border-radius: 12px !important;
        padding: 1.2rem !important;
        border-left: 4px solid #c15f3c !important;
        color: #3d3929 !important;
        font-family: 'Inter', sans-serif !important;
    }

    .stError {
        background: #fef2f2 !important;
        border-radius: 12px !important;
        padding: 1.2rem !important;
        border-left: 4px solid #dc2626 !important;
        color: #3d3929 !important;
        font-family: 'Inter', sans-serif !important;
    }
    
    .stWarning {
        background: #fef9f3 !important;
        border-radius: 12px !important;
        padding: 1.2rem !important;
        border-left: 4px solid #ea9d3e !important;
        color: #3d3929 !important;
        font-family: 'Inter', sans-serif !important;
    }

    /* ============================================================
       SPINNER STYLING
    ============================================================ */
    .stSpinner > div {
        border-color: #c15f3c transparent #c15f3c transparent !important;
    }

    /* ============================================================
       INFO BOX - Claude's Warm Design
    ============================================================ */
    .info-box {
        background: #ffffff;
        border-left: 4px solid #c15f3c;
        border-radius: 12px;
        padding: 2rem;
        color: #3d3929;
        margin: 2.5rem 0;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
        border: 1px solid #ebe9e0;
        border-left: 4px solid #c15f3c;
    }

    .info-box h3 {
        color: #c15f3c !important;
        margin-bottom: 1.5rem !important;
        font-weight: 700 !important;
        font-family: 'Merriweather', serif !important;
    }

    .info-box ol {
        margin-left: 1.5rem;
        line-height: 1.8;
    }

    .info-box li {
        margin: 1rem 0;
        font-size: 1rem;
        color: #3d3929;
    }
    
    .info-box p {
        line-height: 1.7;
        font-size: 1rem;
        color: #3d3929;
    }
    
    .info-box strong {
        color: #3d3929;
        font-weight: 600;
    }
    
    .info-box em {
        color: #6b6656;
        font-style: italic;
    }

    /* ============================================================
       EXPANDER STYLING
    ============================================================ */
    .streamlit-expanderHeader {
        background: #f9f8f4 !important;
        border-radius: 10px !important;
        font-weight: 600 !important;
        padding: 1rem 1.5rem !important;
        border: 1px solid #ebe9e0 !important;
        color: #3d3929 !important;
        font-family: 'Inter', sans-serif !important;
    }
    
    .streamlit-expanderHeader:hover {
        background: #f5f3ed !important;
        border-color: #ddd9cc !important;
    }

    /* ============================================================
       METRICS - Claude Style
    ============================================================ */
    [data-testid="stMetricValue"] {
        font-size: 2rem !important;
        color: #c15f3c !important;
        font-weight: 700 !important;
        font-family: 'Inter', sans-serif !important;
    }
    
    [data-testid="stMetricLabel"] {
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        color: #6b6656 !important;
        text-transform: uppercase !important;
        letter-spacing: 0.5px !important;
    }

    /* ============================================================
       SIDEBAR - Warm Neutral
    ============================================================ */
    [data-testid="stSidebar"] {
        background: #eeece2;
        border-right: 1px solid #ddd9cc;
    }

    [data-testid="stSidebar"] .stButton > button {
        background: #ffffff !important;
        border: 1.5px solid #ddd9cc !important;
        color: #3d3929 !important;
        border-radius: 10px !important;
        padding: 10px 16px !important;
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        transition: all 0.2s ease !important;
        font-family: 'Inter', sans-serif !important;
    }

    [data-testid="stSidebar"] .stButton > button:hover {
        background: #f5f3ed !important;
        border-color: #c15f3c !important;
        color: #c15f3c !important;
    }
    
    [data-testid="stSidebar"] h1 {
        font-size: 1.3rem !important;
        color: #3d3929 !important;
        margin-bottom: 1rem !important;
        font-family: 'Merriweather', serif !important;
    }
    
    [data-testid="stSidebar"] .stMarkdown {
        color: #3d3929;
        font-family: 'Inter', sans-serif;
    }

    /* ============================================================
       HORIZONTAL RULE
    ============================================================ */
    hr {
        border: none;
        height: 1px;
        background: #ebe9e0;
        margin: 2rem 0;
    }

    /* ============================================================
       LINKS - Claude Orange
    ============================================================ */
    a {
        color: #c15f3c !important;
        text-decoration: none !important;
        font-weight: 500 !important;
        transition: color 0.2s ease !important;
    }
    
    a:hover {
        color: #a14a2f !important;
        text-decoration: underline !important;
    }

    /* ============================================================
       HIDE STREAMLIT BRANDING
    ============================================================ */
    #MainMenu {visibility: hidden;}
    footer {visibility: hidden;}
    header {visibility: hidden;}
    
    /* ============================================================
       CUSTOM SCROLLBAR - Claude Style
    ============================================================ */
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }
    
    ::-webkit-scrollbar-track {
        background: #f5f3ed;
    }
    
    ::-webkit-scrollbar-thumb {
        background: #c15f3c;
        border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb:hover {
        background: #a14a2f;
    }

    /* ============================================================
       TYPOGRAPHY IMPROVEMENTS
    ============================================================ */
    body {
        font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
        color: #3d3929;
        line-height: 1.6;
    }
    
    h2, h3, h4, h5, h6 {
        font-family: 'Merriweather', serif;
        color: #3d3929;
    }
    
    /* ============================================================
       RESPONSIVE DESIGN
    ============================================================ */
    @media (max-width: 768px) {
        h1 {
            font-size: 2.2rem !important;
        }
        
        .subtitle {
            font-size: 1rem !important;
        }
        
        .mindmap-card {
            padding: 1.5rem;
        }
        
        .stTextInput > div > div > input {
            font-size: 15px !important;
            padding: 14px 18px !important;
        }
        
        .stButton > button {
            font-size: 14px !important;
            padding: 12px 24px !important;
        }
    }
    
    /* ============================================================
       SMOOTH INTERACTIONS
    ============================================================ */
    * {
        transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    html {
        scroll-behavior: smooth;
    }

    /* ============================================================
       CLEAN, MINIMAL AESTHETIC
    ============================================================ */
    .stApp {
        background: #faf9f5;
    }
    
    /* Remove unnecessary decorations */
    .stDeployButton {
        display: none;
    }
</style>
""", unsafe_allow_html=True)



# ============================================================================
# SESSION STATE MANAGEMENT
# ============================================================================

def initialize_session_state():
    """Initialize all session state variables"""
    if 'mindmap_history' not in st.session_state:
        st.session_state.mindmap_history = []

    if 'current_mindmap' not in st.session_state:
        st.session_state.current_mindmap = None

    if 'query_count' not in st.session_state:
        st.session_state.query_count = 0

    if 'last_keyword' not in st.session_state:
        st.session_state.last_keyword = ""


# ============================================================================
# HELPER FUNCTIONS
# ============================================================================

def validate_api_keys() -> tuple[bool, list[str]]:
    """
    Validate that all required API keys are configured

    Returns:
        Tuple of (is_valid, missing_keys_list)
    """
    return settings.validate_api_keys()


def generate_mindmap(keyword: str) -> dict:
    """
    Generate mindmap for given keyword using API handler

    Args:
        keyword: Technical keyword to analyze

    Returns:
        Dictionary with mindmap data and metadata
    """
    try:
        result = fetch_mindmap_data(
            keyword=keyword,
            gemini_key=settings.gemini_api_key,
            tavily_key=settings.tavily_api_key,
            kg_api_key=settings.google_cloud_api_key
        )
        return result
    except Exception as e:
        st.error(f"Error generating mindmap: {str(e)}")
        return None


# ============================================================================
# MAIN APPLICATION
# ============================================================================

def main():
    """Main application logic"""

    # Initialize session state
    initialize_session_state()

    # ========================================================================
    # HEADER SECTION
    # ========================================================================

    st.markdown("<h1>🧠 Technical Mindmap Generator</h1>", unsafe_allow_html=True)
    st.markdown(
        "<p class='subtitle'>Transform technical keywords into interactive visual mindmaps powered by AI</p>",
        unsafe_allow_html=True
    )

    # ========================================================================
    # API KEY VALIDATION
    # ========================================================================

    is_valid, missing_keys = validate_api_keys()

    if not is_valid:
        st.error(f"⚠️ Missing API Keys: {', '.join(missing_keys)}")
        st.info("Please configure your API keys in the `.env` file before using the application.")

        with st.expander("πŸ“ How to set up API keys"):
            st.markdown("""
            1. Create a `.env` file in the project root
            2. Add your API keys:
               ```
               GEMINI_API_KEY=your_gemini_key
               TAVILY_API_KEY=your_tavily_key

               ```
            3. Restart the application

            **Get API Keys:**
            - Gemini: https://ai.google.dev/
            - Tavily: https://tavily.com/
            - Google Cloud: https://console.cloud.google.com/
            """)

        st.stop()

    # ========================================================================
    # INPUT SECTION
    # ========================================================================

    # Center the input field
    col1, col2, col3 = st.columns([1, 3, 1])

    with col2:
        keyword = st.text_input(
            "",
            placeholder="e.g., Machine Learning, Blockchain, Kubernetes, Neural Networks...",
            key=f"keyword_input_{st.session_state.query_count}",
            label_visibility="collapsed",
            help="Enter any technical keyword or concept"
        )

        # Center the button
        btn_col1, btn_col2, btn_col3 = st.columns([1, 1, 1])
        with btn_col2:
            generate_button = st.button(
                "πŸš€ Generate Mindmap",
                use_container_width=True,
                type="primary"
            )

    # ========================================================================
    # MINDMAP GENERATION
    # ========================================================================

    if generate_button and keyword:
        # Validate keyword
        if len(keyword.strip()) < 2:
            st.warning("⚠️ Please enter a longer keyword (at least 2 characters)")
        else:
            # Show loading animation
            with st.spinner(f"πŸ” Analyzing '{keyword}'...\n\n⚑ This may take 10-15 seconds..."):

                # Add progress messages
                progress_placeholder = st.empty()

                progress_placeholder.info("πŸ“‘ Step 1/3: Fetching web data from Tavily...")
                time.sleep(1)

                progress_placeholder.info("πŸ”— Step 2/3: Querying Knowledge Graph...")
                time.sleep(1)

                progress_placeholder.info("πŸ€– Step 3/3: Synthesizing with Gemini AI...")

                # Generate mindmap
                result = generate_mindmap(keyword)

                # Clear progress messages
                progress_placeholder.empty()

                if result:
                    # Store in session state
                    st.session_state.current_mindmap = result
                    st.session_state.mindmap_history.append({
                        'keyword': keyword,
                        'data': result,
                        'timestamp': time.time()
                    })
                    st.session_state.query_count += 1
                    st.session_state.last_keyword = keyword

                    st.success(f"βœ… Mindmap generated successfully for '{keyword}'!")
                else:
                    st.error("❌ Failed to generate mindmap. Please try again.")

    # ========================================================================
    # DISPLAY MINDMAP
    # ========================================================================

    if st.session_state.current_mindmap:
        st.markdown("<div class='mindmap-card'>", unsafe_allow_html=True)

        # Display mindmap
        mindmap_data = st.session_state.current_mindmap['mindmap']

        st.markdown(f"### πŸ—ΊοΈ Mindmap: {st.session_state.last_keyword}")
        st.markdown("*Zoom, pan, and hover over nodes for details*")

        try:
            generator = MindmapGenerator(height="700px", width="100%")
            generator.render_in_streamlit(mindmap_data)
        except Exception as e:
            st.error(f"Error rendering mindmap: {e}")

        st.markdown("</div>", unsafe_allow_html=True)

        # ====================================================================
        # METADATA SECTION
        # ====================================================================

        with st.expander("πŸ“Š View Generation Details", expanded=False):
            metadata = st.session_state.current_mindmap['metadata']

            # Metrics in columns
            metric_col1, metric_col2, metric_col3, metric_col4 = st.columns(4)

            with metric_col1:
                st.metric("🎯 Keyword", metadata['keyword'])

            with metric_col2:
                st.metric("πŸ”— Total Nodes", metadata.get('total_nodes', 0))

            with metric_col3:
                st.metric("πŸ“š Sources", len(metadata.get('tavily_sources', [])))

            with metric_col4:
                st.metric("πŸ” KG Entities", metadata.get('kg_entities_count', 0))

            st.markdown("---")

            # Display sources
            if metadata.get('tavily_sources'):
                st.subheader("πŸ“š Information Sources")
                for i, source in enumerate(metadata['tavily_sources'][:8], 1):
                    st.markdown(f"{i}. [{source}]({source})")

    else:
        # ====================================================================
        # WELCOME / INFO SECTION
        # ====================================================================

        st.markdown("""
        <div class='info-box'>
            <h3>πŸ’‘ How it works:</h3>
            <ol>
                <li><strong>Tavily API</strong>: Gathers real-time web context and discovers related terms</li>
                <li><strong>Knowledge Graph API</strong>: Provides structured entity relationships and descriptions</li>
                <li><strong>Gemini AI</strong>: Synthesizes all data into a comprehensive mindmap structure</li>
            </ol>
            <p style='margin-top:1.5rem; font-size:1.1rem;'>
                <strong>Simply enter a technical keyword above and click "Generate Mindmap" to begin!</strong>
            </p>
            <p style='margin-top:1rem; color:#95e1d3;'>
                πŸ’‘ <em>Tip: Try keywords like "Kubernetes", "Machine Learning", "Quantum Computing", or "Blockchain"</em>
            </p>
        </div>
        """, unsafe_allow_html=True)

    # ========================================================================
    # SIDEBAR - HISTORY & SETTINGS
    # ========================================================================

    with st.sidebar:
        st.title("πŸ“œ Query History")

        if st.session_state.mindmap_history:
            st.markdown(f"**Total Queries:** {len(st.session_state.mindmap_history)}")
            st.markdown("---")

            # Display history in reverse order (most recent first)
            for i, item in enumerate(reversed(st.session_state.mindmap_history)):
                keyword_display = item['keyword']

                # Create button with emoji
                if st.button(
                    f"πŸ”„ {keyword_display}",
                    key=f"history_{i}",
                    help=f"Load mindmap for '{keyword_display}'"
                ):
                    st.session_state.current_mindmap = item['data']
                    st.session_state.last_keyword = item['keyword']
                    st.rerun()
        else:
            st.info("No queries yet.\nGenerate your first mindmap!")

        st.markdown("---")

        # Settings section
        st.markdown("### βš™οΈ Settings")
        st.markdown(f"**Max Nodes:** {settings.max_nodes}")
        st.markdown(f"**Max Depth:** {settings.max_depth}")
        st.markdown(f"**Caching:** {'Enabled' if settings.cache_enabled else 'Disabled'}")

        st.markdown("---")

        # About section
        with st.expander("ℹ️ About"):
            st.markdown("""
            **Technical Mindmap Generator**

            Version 1.0.0

            A proof-of-concept application that creates interactive visual mindmaps for technical concepts using AI-powered APIs.

            **Technologies:**
            - Streamlit
            - PyVis
            - Gemini AI
            - Tavily Search
            - Knowledge Graph

            **Created by:** Your Name
            """)


# ============================================================================
# APPLICATION ENTRY POINT
# ============================================================================

if __name__ == "__main__":
    main()