File size: 27,909 Bytes
282fafd
 
 
 
 
febc5c7
 
2b2f698
3eddd77
282fafd
2b2f698
 
febc5c7
 
2b2f698
 
 
 
 
 
 
 
 
 
 
 
282fafd
6a8ccf5
 
 
 
3eddd77
 
 
 
 
 
 
 
 
 
282fafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f4fcc2
 
6a8ccf5
 
 
282fafd
 
 
 
 
 
 
 
 
 
 
 
 
 
febc5c7
6a8ccf5
282fafd
 
 
 
 
1f4fcc2
282fafd
 
 
6a8ccf5
 
 
 
282fafd
 
 
 
 
6a8ccf5
 
 
 
 
282fafd
 
 
 
6a8ccf5
282fafd
6a8ccf5
 
 
282fafd
6a8ccf5
 
 
 
 
 
 
282fafd
 
6a8ccf5
282fafd
 
6a8ccf5
 
 
 
 
 
 
 
282fafd
 
febc5c7
 
282fafd
 
 
6a8ccf5
 
 
 
282fafd
 
6a8ccf5
 
 
 
 
282fafd
 
6a8ccf5
 
 
 
 
 
 
 
2b2f698
 
6a8ccf5
 
 
 
 
 
 
2b2f698
 
6a8ccf5
 
 
 
 
 
 
2b2f698
6a8ccf5
2b2f698
 
6a8ccf5
 
 
 
 
 
2b2f698
6a8ccf5
 
2b2f698
 
6a8ccf5
 
2b2f698
6a8ccf5
2b2f698
 
282fafd
 
 
6a8ccf5
282fafd
 
 
6a8ccf5
 
 
282fafd
 
 
 
 
6a8ccf5
 
282fafd
6a8ccf5
282fafd
1f4fcc2
febc5c7
 
6a8ccf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
febc5c7
6a8ccf5
febc5c7
6a8ccf5
 
 
 
 
 
 
 
febc5c7
1f4fcc2
279e214
 
 
 
 
 
 
 
 
282fafd
 
 
0e658c0
2b2f698
0e658c0
febc5c7
 
0e658c0
 
279e214
3eddd77
febc5c7
0e658c0
 
3eddd77
0e658c0
d90c34f
 
 
 
 
6a8ccf5
 
 
 
0e658c0
6a8ccf5
 
 
 
 
 
 
 
 
d90c34f
6a8ccf5
 
 
 
 
 
0e658c0
6a8ccf5
0e658c0
 
d90c34f
0e658c0
d90c34f
0e658c0
 
 
 
279e214
 
 
3eddd77
279e214
 
 
 
3eddd77
 
279e214
 
 
6a8ccf5
279e214
6a8ccf5
0e658c0
 
 
3eddd77
0e658c0
 
279e214
 
 
 
3eddd77
 
 
 
279e214
3eddd77
 
 
 
 
 
 
 
 
 
 
 
279e214
 
fde10e9
279e214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
febc5c7
279e214
 
 
282fafd
279e214
 
 
 
 
 
282fafd
279e214
 
 
 
282fafd
279e214
 
 
 
65d60ca
279e214
 
 
 
 
 
 
 
 
65d60ca
279e214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282fafd
279e214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
febc5c7
279e214
 
0e658c0
279e214
 
 
 
 
 
 
 
 
282fafd
279e214
 
 
 
3eddd77
279e214
 
 
 
 
 
3eddd77
 
 
 
 
279e214
 
 
 
 
 
 
 
 
 
3eddd77
279e214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
febc5c7
 
279e214
 
 
 
 
 
 
 
 
 
 
 
282fafd
3eddd77
279e214
 
 
 
 
3eddd77
279e214
3eddd77
 
279e214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282fafd
279e214
6a8ccf5
279e214
 
 
 
3eddd77
279e214
 
 
 
 
 
 
 
 
 
3eddd77
279e214
 
 
 
 
 
 
 
3eddd77
 
279e214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3eddd77
279e214
 
 
 
6a8ccf5
febc5c7
279e214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import json
from datetime import datetime
import time
import requests
import boto3
import uuid
import os
from AdminDashboard import render_admin_dashboard

# Load configuration from environment variables (Hugging Face Spaces)
API_ENDPOINT = os.getenv("API_ENDPOINT", "https://oau6sljd4l.execute-api.ap-south-1.amazonaws.com/production/process")

# DynamoDB configuration for session tracking
DYNAMODB_REGION = os.getenv("DYNAMODB_REGION", "ap-south-1") 
SESSION_TABLE = os.getenv("SESSION_TABLE", "SessionTracking")

# AWS Configuration
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
AWS_DEFAULT_REGION = os.getenv("AWS_DEFAULT_REGION", "ap-south-1")

# Default values
DEFAULT_USER_ID = int(os.getenv("DEFAULT_USER_ID", "30")) 
DEFAULT_PERSONALIZATION_ID = int(os.getenv("DEFAULT_PERSONALIZATION_ID", "100"))
API_TIMEOUT = int(os.getenv("API_TIMEOUT", "30"))

# Authentication credentials from environment variables
VALID_USERNAME = os.getenv("APP_USERNAME")
VALID_PASSWORD = os.getenv("APP_PASSWORD")

# Course configurations
COURSE_CONFIGS = {
    "AI Ready Course": {"course_id": 47, "chapter_id": 647},
    "MERN": {"course_id": 48, "chapter_id": 648},
    "Machine Learning": {"course_id": 49, "chapter_id": 649},
    "Data Science": {"course_id": 50, "chapter_id": 650},
    "Flask": {"course_id": 51, "chapter_id": 651},
    "Django": {"course_id": 52, "chapter_id": 652}
}

# Set page configuration
st.set_page_config(
    page_title="Base Course Personalization",
    layout="wide",
    initial_sidebar_state="collapsed",
    page_icon="πŸ“š",
    menu_items={
        'Get Help': None,
        'Report a bug': None,
        'About': None
    }
)

# Custom CSS for dark theme styling
st.markdown("""
<style>
    /* Dark theme colors */
    :root {
        --background-color: #1E1E1E;
        --card-background: #2D2D2D;
        --text-color: #E0E0E0;
        --accent-color: #4F97FF;
        --border-color: #444444;
        --header-color: #4F97FF;
        --subheader-color: #FFFFFF;
        --success-color: #10B981;
        --warning-color: #F59E0B;
        --error-color: #EF4444;
    }
    
    /* Main container styling */
    .stApp {
        background-color: var(--background-color);
        color: var(--text-color);
    }
    
    /* Headers */
    .main-header {
        font-size: 2.5rem;
        font-weight: 600;
        color: var(--header-color);
        margin-bottom: 1rem;
        text-align: center;
        text-shadow: 0 2px 4px rgba(79, 151, 255, 0.3);
    }
    
    .section-header {
        font-size: 1.5rem;
        font-weight: 500;
        color: var(--subheader-color);
        margin-top: 2rem;
        margin-bottom: 1rem;
        padding-bottom: 0.5rem;
        border-bottom: 2px solid var(--border-color);
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    /* Form container */
    div[data-testid="stForm"] {
        background-color: var(--card-background);
        padding: 2rem;
        border-radius: 12px;
        box-shadow: 0 8px 25px rgba(0,0,0,0.4);
        border: 1px solid var(--border-color);
        margin-bottom: 1rem;
    }
    
    /* Button styling */
    .stButton>button {
        background: linear-gradient(135deg, var(--accent-color) 0%, #3B82F6 100%);
        color: white;
        border-radius: 8px;
        padding: 0.75rem 2rem;
        font-weight: 600;
        border: none;
        transition: all 0.3s ease;
        box-shadow: 0 4px 15px rgba(79, 151, 255, 0.3);
    }
    
    .stButton>button:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(79, 151, 255, 0.4);
    }
    
    /* Input fields styling */
    div[data-baseweb="select"] > div {
        background-color: var(--background-color);
        border: 2px solid var(--border-color);
        border-radius: 8px;
        transition: border-color 0.3s ease;
    }
    
    div[data-baseweb="select"] > div:focus-within {
        border-color: var(--accent-color);
        box-shadow: 0 0 0 3px rgba(79, 151, 255, 0.1);
    }
    
    .stTextInput > div > div > input,
    .stNumberInput > div > div > input,
    .stTextArea > div > div > textarea {
        background-color: var(--background-color);
        color: var(--text-color);
        border: 2px solid var(--border-color);
        border-radius: 8px;
        padding: 0.75rem;
        transition: border-color 0.3s ease;
    }
    
    .stTextInput > div > div > input:focus,
    .stNumberInput > div > div > input:focus,
    .stTextArea > div > div > textarea:focus {
        border-color: var(--accent-color);
        box-shadow: 0 0 0 3px rgba(79, 151, 255, 0.1);
    }
    
    /* Topic container styling */
    .topic-container {
        background-color: var(--card-background);
        padding: 1.5rem;
        border-radius: 10px;
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        position: relative;
    }
    
    .topic-header {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        margin-bottom: 1rem;
        font-weight: 600;
        color: var(--accent-color);
    }
    
    /* Radio buttons */
    .stRadio > div {
        background-color: transparent;
        gap: 1rem;
    }
    
    .stRadio > div > label > div {
        color: var(--text-color) !important;
        font-weight: 500;
    }
    
    /* Labels */
    .stSelectbox > label,
    .stTextInput > label,
    .stNumberInput > label,
    .stTextArea > label,
    .stRadio > label {
        color: var(--text-color) !important;
        font-weight: 500;
        margin-bottom: 0.5rem;
    }
    
    /* Toggle switch */
    .stToggle > label {
        color: var(--text-color) !important;
        font-weight: 500;
    }
    
    /* Spacing */
    div.block-container {
        padding-top: 2rem;
        max-width: 1200px;
    }
    
    hr {
        margin: 2rem 0;
        border: none;
        border-top: 1px solid var(--border-color);
    }
    
    /* API Response Container */
    .api-response {
        background-color: #1A1A1A;
        border-radius: 10px;
        padding: 1.5rem;
        border-left: 4px solid var(--accent-color);
        margin: 1rem 0;
    }
    
    .session-info {
        background-color: var(--card-background);
        padding: 1.5rem;
        border-radius: 10px;
        margin: 1rem 0;
        border: 1px solid var(--border-color);
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    }
    
    /* Action buttons container */
    .action-buttons {
        display: flex;
        gap: 1rem;
        margin: 1rem 0;
        justify-content: flex-start;
    }
    
    /* Small action buttons */
    .small-button {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Success/Error styling */
    .stSuccess, .stError, .stWarning, .stInfo {
        border-radius: 8px;
        padding: 1rem;
        margin: 1rem 0;
    }
    
    /* Login container */
    .login-container {
        background-color: var(--card-background);
        padding: 3rem;
        border-radius: 15px;
        box-shadow: 0 10px 30px rgba(0,0,0,0.5);
        border: 1px solid var(--border-color);
    }
    
    /* Navigation tab styling */
    .nav-tabs {
        background-color: var(--card-background);
        padding: 1rem;
        border-radius: 10px;
        margin-bottom: 2rem;
        border: 1px solid var(--border-color);
    }
</style>
""", unsafe_allow_html=True)

# Initialize session state for topics and authentication
if 'topics_list' not in st.session_state:
    st.session_state.topics_list = [{"topic_title": "What is Flask", "chapter_title": "Introduction to Flask"}]
if 'session_ids' not in st.session_state:
    st.session_state.session_ids = []
if 'authenticated' not in st.session_state:
    st.session_state.authenticated = False
if 'current_page' not in st.session_state:
    st.session_state.current_page = "Course Generation"

# Authentication check
if not st.session_state.authenticated:
    st.markdown('<h1 class="main-header">πŸ” Login to Course Management</h1>', unsafe_allow_html=True)
    
    # Check if credentials are configured
    if not VALID_USERNAME or not VALID_PASSWORD:
        st.error("❌ Authentication credentials not configured. Please contact administrator.")
        st.stop()
    
    col1, col2, col3 = st.columns([1, 2, 1])
    with col2:
        with st.container():
            st.markdown('<div class="login-container">', unsafe_allow_html=True)
            
            with st.form("login_form"):
                st.markdown('<div class="section-header">πŸ”‘ Authentication Required</div>', unsafe_allow_html=True)
                
                username = st.text_input("Username", placeholder="Enter username", key="login_username")
                password = st.text_input("Password", placeholder="Enter password", type="password", key="login_password")
                
                login_submitted = st.form_submit_button("πŸš€ Login", use_container_width=True)
                
                if login_submitted:
                    if VALID_USERNAME and VALID_PASSWORD and username == VALID_USERNAME and password == VALID_PASSWORD:
                        st.session_state.authenticated = True
                        st.success("Login successful! Redirecting...")
                        time.sleep(1)
                        st.rerun()
                    else:
                        st.error("❌ Invalid username or password")
            
            st.markdown('</div>', unsafe_allow_html=True)
    
    st.markdown("---")
    st.markdown("""
    <div style="text-align: center; color: #888888;">
    <small>Please contact administrator for access credentials</small>
    </div>
    """, unsafe_allow_html=True)
    st.stop()

# Navigation and Header (after login)
col1, col2, col3, col4 = st.columns([3, 2, 2, 1])
with col1:
    st.markdown('<h1 class="main-header">πŸ“š Course Management System</h1>', unsafe_allow_html=True)

with col2:
    page = st.selectbox(
        "πŸ“‹ Navigate to:",
        ["Course Generation", "Admin Dashboard"],
        index=0 if st.session_state.current_page == "Course Generation" else 1,
        key="page_selector"
    )
    st.session_state.current_page = page

with col4:
    if st.button("πŸ”“ Logout", key="logout_btn"):
        st.session_state.authenticated = False
        st.session_state.topics_list = [{"topic_title": "What is Flask", "chapter_title": "Introduction to Flask"}]
        st.session_state.session_ids = []
        st.session_state.current_page = "Course Generation"
        st.rerun()

# Page routing
if st.session_state.current_page == "Admin Dashboard":
    render_admin_dashboard()
else:
    # Course Generation Page (Original Content)
    
    # Course Selection Section
    st.markdown('<div class="section-header">πŸ“š Course Selection</div>', unsafe_allow_html=True)
    
    col1, col2 = st.columns([2, 3])
    with col1:
        selected_course = st.selectbox(
            "Select Course Type",
            options=list(COURSE_CONFIGS.keys()),
            index=0,
            help="Choose the course you want to generate content for"
        )
    
    with col2:
        st.info(f"**Selected:** {selected_course} (Course ID: {COURSE_CONFIGS[selected_course]['course_id']})")

    # Topics Section (Outside form for dynamic interaction)
    st.markdown('<div class="section-header">πŸ“‹ Topics Configuration</div>', unsafe_allow_html=True)

    # Display existing topics with better styling
    for i, topic in enumerate(st.session_state.topics_list):
        st.markdown(f'<div class="topic-container">', unsafe_allow_html=True)
        st.markdown(f'<div class="topic-header">πŸ“– Topic {i+1}</div>', unsafe_allow_html=True)
        
        col1, col2, col3 = st.columns([3, 3, 1])
        with col1:
            topic_title = st.text_input(
                "Topic Title", 
                value=topic["topic_title"], 
                key=f"topic_title_{i}",
                help="Enter the topic title"
            )
            st.session_state.topics_list[i]["topic_title"] = topic_title
        
        with col2:
            chapter_title = st.text_input(
                "Chapter Title", 
                value=topic["chapter_title"], 
                key=f"chapter_title_{i}",
                help="Enter the chapter title"
            )
            st.session_state.topics_list[i]["chapter_title"] = chapter_title
        
        with col3:
            if len(st.session_state.topics_list) > 1:
                st.markdown("<br>", unsafe_allow_html=True)  # Add spacing
                if st.button("πŸ—‘οΈ", key=f"remove_{i}", help="Remove this topic"):
                    st.session_state.topics_list.pop(i)
                    st.rerun()
        
        st.markdown('</div>', unsafe_allow_html=True)

    # Add/Remove topic buttons outside the form
    st.markdown('<div class="action-buttons">', unsafe_allow_html=True)
    col1, col2, col3, col4 = st.columns([2, 2, 2, 4])
    with col1:
        if st.button("βž• Add Topic", key="add_topic", help="Add a new topic"):
            st.session_state.topics_list.append({
                "topic_title": f"Topic {len(st.session_state.topics_list) + 1}", 
                "chapter_title": f"Chapter {len(st.session_state.topics_list) + 1}"
            })
            st.rerun()
    with col2:
        if st.button("πŸ”„ Reset All", key="reset_topics", help="Reset to default topics"):
            st.session_state.topics_list = [{"topic_title": "What is Flask", "chapter_title": "Introduction to Flask"}]
            st.rerun()
    st.markdown('</div>', unsafe_allow_html=True)

    # Main Form (for settings and submission)
    with st.form("personalization_form", clear_on_submit=False):
        # Language & Voice Settings Section  
        st.markdown('<div class="section-header">πŸ—£οΈ Language & Voice Settings</div>', unsafe_allow_html=True)
        
        col1, col2, col3 = st.columns(3)
        with col1:
            target_language = st.selectbox(
                "Target Language", 
                ["english", "hindi", "marathi", "kannada", "punjabi","gujarati"],
                index=0,
                format_func=lambda x: x.capitalize(),
                help="Select the target language for content generation"
            )
        
        with col2:
            tts_gender = st.selectbox(
                "Voice Gender", 
                ["male", "female"], 
                index=0,
                format_func=lambda x: x.capitalize(),
                help="Select the voice gender for text-to-speech"
            )
        
        with col3:
            tts_voice = st.selectbox(
                "Voice Style", 
                ["alloy", "echo", "fable", "onyx", "nova", "shimmer"],
                index=3,  # Default to "onyx"
                format_func=lambda x: x.capitalize(),
                help="Select the voice style for text-to-speech"
            )

        # Technical Settings Section
        st.markdown('<div class="section-header">πŸ’» Technical Settings</div>', unsafe_allow_html=True)
        
        col1, col2 = st.columns(2)
        with col1:
            # Comprehensive list of programming languages, frameworks, and databases
            tech_options = [
                # Programming Languages
                "Python", "Java", "JavaScript", "TypeScript", "C++", "C#", "C", "Go", "Rust", "Swift", 
                "Kotlin", "Scala", "Ruby", "PHP", "Perl", "R", "MATLAB", "Dart", "Objective-C", "Assembly",
                "Haskell", "Erlang", "Elixir", "F#", "Clojure", "Lua", "Julia", "Groovy", "VB.NET", "COBOL",
                "Fortran", "Pascal", "Delphi", "Ada", "Prolog", "Lisp", "Scheme", "OCaml", "ML",
                
                # Web Technologies
                "HTML", "CSS", "SASS", "LESS", "Bootstrap", "Tailwind CSS", "Material-UI",
                
                # Frontend Frameworks/Libraries
                "React", "Vue.js", "Angular", "Svelte", "Next.js", "Nuxt.js", "Gatsby", "Ember.js", 
                "Backbone.js", "jQuery", "Alpine.js", "Lit", "Stencil", "Ionic", "React Native", 
                "Flutter", "Xamarin", "Cordova", "PhoneGap",
                
                # Backend Frameworks
                "Node.js", "Express.js", "Nest.js", "Django", "Flask", "FastAPI", "Pyramid", "Tornado",
                "Spring Boot", "Spring MVC", "Struts", "Hibernate", "ASP.NET", "ASP.NET Core", 
                "Ruby on Rails", "Sinatra", "Laravel", "Symfony", "CodeIgniter", "CakePHP", "Zend",
                "Gin", "Echo", "Fiber", "Actix", "Rocket", "Warp", "Axum",
                
                # Mobile Development
                "Android (Java)", "Android (Kotlin)", "iOS (Swift)", "iOS (Objective-C)", 
                
                # Game Development
                "Unity", "Unreal Engine", "Godot", "GameMaker Studio", "Construct", "Phaser",
                
                # Database Technologies
                "MySQL", "PostgreSQL", "SQLite", "Microsoft SQL Server", "Oracle Database", 
                "MongoDB", "Redis", "Cassandra", "DynamoDB", "Firebase", "Supabase", 
                "CouchDB", "Neo4j", "InfluxDB", "TimescaleDB", "ClickHouse", "Apache Spark",
                "Elasticsearch", "Apache Solr", "Amazon RDS", "Google Cloud SQL",
                
                # Cloud & DevOps
                "AWS", "Google Cloud Platform", "Microsoft Azure", "Digital Ocean", "Heroku",
                "Docker", "Kubernetes", "Terraform", "Ansible", "Jenkins", "GitLab CI", "GitHub Actions",
                "Nginx", "Apache", "Linux", "Ubuntu", "CentOS", "Red Hat",
                
                # Data Science & AI/ML
                "TensorFlow", "PyTorch", "Scikit-learn", "Pandas", "NumPy", "Matplotlib", "Seaborn",
                "Jupyter", "Apache Airflow", "Apache Kafka", "Apache Flink", "Hadoop", "Spark",
                "Tableau", "Power BI", "D3.js", "Plotly", "OpenCV", "Keras", "XGBoost",
                
                # Testing Frameworks
                "Jest", "Mocha", "Chai", "Cypress", "Selenium", "Playwright", "Puppeteer",
                "JUnit", "TestNG", "Mockito", "PyTest", "unittest", "RSpec", "PHPUnit",
                
                # Other Technologies
                "GraphQL", "REST API", "gRPC", "WebSocket", "Apache Kafka", "RabbitMQ", 
                "Blockchain", "Solidity", "Web3", "Ethereum", "Bitcoin", "Smart Contracts",
                "Microservices", "Serverless", "Lambda Functions", "API Gateway"
            ]
            
            # Sort the options alphabetically
            tech_options.sort()
            
            programming_language = st.selectbox(
                "Programming Language / Technology", 
                tech_options,
                index=tech_options.index("Python") if "Python" in tech_options else 0,
                help="Select the primary programming language, framework, or technology for examples"
            )
        with col2:
            st.markdown("<br>", unsafe_allow_html=True)  # Add spacing
            toggle_hinglish = st.toggle("Enable Hinglish", value=True, help="Enable mixing of Hindi and English")

        # Submit button
        st.markdown("<br>", unsafe_allow_html=True)
        col1, col2, col3 = st.columns([1, 2, 1])
        with col2:
            submitted = st.form_submit_button("πŸš€ Generate Course", use_container_width=True)

    # Handle submission
    if submitted:
        # Use the topics from session state directly
        topics_to_process = st.session_state.topics_list
        
        # Get course configuration
        course_config = COURSE_CONFIGS[selected_course]
        course_id = course_config["course_id"]
        chapter_id = course_config["chapter_id"]
        
        # Validate inputs
        valid_topics = []
        for topic in topics_to_process:
            if topic["topic_title"].strip() and topic["chapter_title"].strip():
                valid_topics.append(topic)
        
        if not valid_topics:
            st.error("❌ Please enter at least one topic with both topic title and chapter title")
        else:
            # Show loading state with better animation
            with st.spinner(f"🎬 Generating your {selected_course} course... This may take a few moments."):
                progress_bar = st.progress(0)
                for i in range(100):
                    time.sleep(0.02)  # Simulating progress
                    progress_bar.progress(i + 1)
                
                # Hardcoded values
                user_id = DEFAULT_USER_ID 
                personalization_id = DEFAULT_PERSONALIZATION_ID
                
                # Create user profile (hardcoded)
                user_profile = {
                    "personalized": True,
                    "user_name": "System User",
                    "user_age": 25,
                    "user_gender": "male",
                    "user_tech_knowledge": "beginner",
                    "user_preferred_activity": "coding, learning, technology",
                    "user_food": "healthy food, vegetarian",
                    "user_physical_activities": "walking, yoga",
                    "learning_style": "visual",
                    "target_language": target_language,
                    "tts_gender": tts_gender,
                    "tts_voice": tts_voice,
                    "toggle_hinglish": toggle_hinglish,
                    "run_visualization": False,
                    "subtitle": "",
                    "age_group": "18-25"
                }
                
                # Create settings
                settings = {
                    "target_language": target_language,
                    "tts_gender": tts_gender,
                    "tts_voice": tts_voice,
                    "toggle_hinglish": toggle_hinglish,
                    "run_visualization": False,
                    "subtitle": "",
                    "programming_language": programming_language,
                    "slide_colour": "blue",
                    "video_type": "base_video"
                }
                
                # Generate topics data with user input for titles and course-specific values
                topics_data = []
                for i, topic in enumerate(valid_topics):
                    topics_data.append({
                        "topic_id": 10834 + i,  # Hardcoded with increment
                        "topic_title": topic["topic_title"].strip(),
                        "chapter_id": chapter_id,  # From selected course
                        "chapter_title": topic["chapter_title"].strip(),  # User input
                        "course_id": course_id,  # From selected course
                        "video_url": f"https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/{course_id}/{chapter_id}/172906{4365+i*50}.mp4",  # Course-specific
                        "video_duration": 462 + i*20,  # Hardcoded with variation
                        "sequence_number": i + 1,
                    })
                
                # Create payload (always multiple topics structure)
                payload = {
                    "personalization_id": personalization_id,
                    "user_id": user_id,
                    "course_id": course_id,
                    "total_videos": len(topics_data),
                    "created_at": datetime.utcnow().isoformat(),
                    "user_profile": user_profile,
                    "topics": topics_data,
                    "settings": settings
                }

                # Make API call
                try:
                    headers = {
                        'Content-Type': 'application/json'
                    }
                    
                    response = requests.post(API_ENDPOINT, json=payload, headers=headers, timeout=API_TIMEOUT)
                    
                    if response.status_code == 200:
                        response_data = response.json()
                        session_ids = response_data.get("session_ids", [])
                        
                        st.success(f"πŸŽ‰ {selected_course} generation started successfully!")
                        
                        # Store session IDs in session state
                        st.session_state.session_ids.extend(session_ids)
                        
                        # Display results in a clean format
                        st.markdown("### πŸ“Š Generation Summary")
                        
                        col1, col2 = st.columns(2)
                        with col1:
                            st.markdown(f"""
                            **Course**: {selected_course}  
                            **Course ID**: {course_id}  
                            **Programming Language**: {programming_language.capitalize()}  
                            **Target Language**: {target_language.capitalize()}  
                            """)
                        with col2:
                            st.markdown(f"""
                            **Voice**: {tts_voice.capitalize()} ({tts_gender.capitalize()})  
                            **Topics Count**: {len(valid_topics)}  
                            **Hinglish**: {"Enabled" if toggle_hinglish else "Disabled"}  
                            **Chapter ID**: {chapter_id}
                            """)
                        
                        # Display session IDs
                        if session_ids:
                            st.markdown("### πŸ” Session Tracking IDs")
                            for i, session_id in enumerate(session_ids, 1):
                                st.markdown(f'<div class="session-info">πŸ“ <strong>Session {i}:</strong> <code>{session_id}</code></div>', unsafe_allow_html=True)
                        
                        # Display API response
                        with st.expander("πŸ“Š View Full API Response", expanded=False):
                            st.markdown('<div class="api-response">', unsafe_allow_html=True)
                            st.json(response_data)
                            st.markdown('</div>', unsafe_allow_html=True)
                        
                        # Information about tracking
                        st.info(f"""
                        πŸ’‘ **Tracking Information**  
                        You can track the progress of your {selected_course} course generation using the session IDs above.  
                        The processing status will be updated in DynamoDB table: {SESSION_TABLE}  
                        Region: {DYNAMODB_REGION}
                        
                        πŸ‘‰ **Next Steps**: Switch to the "Admin Dashboard" to monitor your session progress in real-time!
                        """)
                        
                    else:
                        st.error(f"❌ API Error: {response.status_code}")
                        if response.text:
                            st.error(f"**Error Details**: {response.text}")
                            
                except requests.exceptions.Timeout:
                    st.error("⏰ Request timed out. Please try again later.")
                except requests.exceptions.ConnectionError:
                    st.error("🌐 Connection error. Please check your internet connection.")
                except Exception as e:
                    st.error(f"❌ API call failed: {str(e)}")
                    
                    # Show payload for debugging
                    with st.expander("πŸ› Debug Information", expanded=False):
                        st.warning("Request payload for debugging:")
                        st.json(payload)