File size: 13,229 Bytes
282fafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f4fcc2
 
282fafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f4fcc2
282fafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f4fcc2
 
 
 
 
 
 
 
 
 
 
 
 
282fafd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import json
from datetime import datetime
import time
import requests

# API endpoint (replace with your actual endpoint)
API_ENDPOINT = "https://api.example.com/personalize-course"

# 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;
    }
    
    /* 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;
    }
    
    .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: 1px solid var(--border-color);
    }
    
    /* Form container */
    div[data-testid="stForm"] {
        background-color: var(--card-background);
        padding: 1.5rem;
        border-radius: 8px;
        box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    }
    
    /* Button styling */
    .stButton>button {
        background-color: var(--accent-color);
        color: white;
        border-radius: 4px;
        padding: 0.5rem 2rem;
        font-weight: 500;
        border: none;
    }
    
    /* Input fields */
    div[data-baseweb="select"] > div {
        background-color: var(--background-color);
        border-color: var(--border-color);
    }
    
    .stTextInput > div > div > input {
        background-color: var(--background-color);
        color: var(--text-color);
        border-color: var(--border-color);
    }
    
    .stNumberInput > div > div > input {
        background-color: var(--background-color);
        color: var(--text-color);
    }
    
    .stTextArea > div > div > textarea {
        background-color: var(--background-color);
        color: var(--text-color);
        border-color: var(--border-color);
    }
    
    /* Radio buttons */
    .stRadio > div {
        background-color: transparent;
    }
    
    /* Spacing */
    div.block-container {
        padding-top: 2rem;
    }
    
    hr {
        margin-top: 1rem;
        margin-bottom: 1rem;
        border-color: var(--border-color);
    }
    
    /* Footer */
    footer {
        color: #888888;
    }
    
    /* API Response Container */
    .api-response {
        background-color: #1A1A1A;
        border-radius: 8px;
        padding: 1rem;
        border-left: 4px solid var(--accent-color);
    }
    
    /* Custom label colors for Full Name and Gender */
    [data-testid="stForm"] label:contains("Full Name"),
    [data-testid="stForm"] label:contains("Gender") {
        color: white !important;
        font-weight: 500;
    }
    
    /* Alternative approach if the above doesn't work */
    .st-emotion-cache-1gulkj5 label,  /* For Full Name */
    .st-emotion-cache-1aumxhf label { /* For Gender */
        color: white !important;
    }
</style>
""", unsafe_allow_html=True)

# App Header
col1, col2, col3 = st.columns([1, 3, 1])
with col2:
    st.markdown('<h1 class="main-header">πŸ“š Base Course Personalization</h1>', unsafe_allow_html=True)
    st.markdown("""
    Complete this form to tailor your learning experience to your preferences.
    Your personalized course will be generated based on the information you provide below.
    """)

# Main Form
with st.form("personalization_form", clear_on_submit=False):
    # Personal Information Section
    st.markdown('<div class="section-header">πŸ‘€ Personal Details</div>', unsafe_allow_html=True)
    
    col1, col2 = st.columns(2)
    with col1:
        user_name = st.text_input("Full Name", placeholder="Enter your full name")
        user_age = st.number_input("Age", min_value=10, max_value=100, value=22)
    
    with col2:
        user_gender = st.selectbox(
            "Gender", 
            ["male", "female", "other"], 
            index=0,
            format_func=lambda x: x.capitalize()
        )
        tech_knowledge = st.select_slider(
            "Technical Knowledge",
            options=["beginner", "intermediate", "advanced"],
            value="beginner"
        )
    
    st.markdown('<div class="section-header">🎯 Preferences</div>', unsafe_allow_html=True)
    col1, col2 = st.columns(2)
    
    with col1:
        preferred_activity = st.text_area(
            "Preferred Activities", 
            placeholder="e.g., movies, painting, shopping",
            help="Enter activities separated by commas"
        )
        physical_activities = st.text_area(
            "Physical Activities", 
            placeholder="e.g., badminton, cricket, yoga",
            help="Enter activities separated by commas"
        )
    
    with col2:
        food = st.text_area(
            "Food Preferences", 
            placeholder="e.g., vegetarian, paneer, pizza",
            help="Enter food items separated by commas"
        )
    
    # Learning Style Section
    st.markdown('<div class="section-header">πŸŽ“ Learning Preferences</div>', unsafe_allow_html=True)
    
    learning_style = st.radio(
        "Learning Style",
        ["visual", "auditory", "kinesthetic"],
        index=0,
        help="Visual: learn by seeing, Auditory: learn by hearing, Kinesthetic: learn by doing",
        horizontal=True,
        format_func=lambda x: x.capitalize()
    )
    
    with st.expander("Learn more about learning styles"):
        st.info("""
        - **Visual learners** prefer images, diagrams, and spatial understanding
        - **Auditory learners** learn best through listening and verbal instructions
        - **Kinesthetic learners** prefer hands-on activities and learning by doing
        """)
    
    # Language 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", "telugu", "tamil", "other"],
            index=0,
            format_func=lambda x: x.capitalize()
        )
    
    with col2:
        tts_gender = st.selectbox(
            "Voice Gender", 
            ["male", "female"], 
            index=0,
            format_func=lambda x: x.capitalize()
        )
    
    with col3:
        tts_voice = st.selectbox(
            "Voice Style", 
            ["echo", "soprano", "alto", "robotic"],
            index=0,
            format_func=lambda x: x.capitalize()
        )
    
    toggle_hinglish = st.toggle("Enable Hinglish", value=True, help="Mix of Hindi and English")

    # Course Settings Section
    st.markdown('<div class="section-header">πŸ’» Technical Preferences</div>', unsafe_allow_html=True)
    
    programming_language = st.selectbox(
        "Programming Language", 
        ["python", "java", "javascript", "c++", "go"],
        index=0,
        format_func=lambda x: x.capitalize()
    )
    
    # Show sample lesson structure
    with st.expander("πŸ“‹ Sample Course Structure"):
        st.markdown("""
        ### Introduction to Flask
        1. What is Flask
        2. Setting Up Flask Environment
        3. Understanding Flask Project Structure
        """)
    
    # 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 Personalized Course", use_container_width=True)

# Handle submission
if submitted:
    # Validate inputs
    if not user_name:
        st.error("Please enter your name")
    elif not preferred_activity:
        st.warning("Adding preferred activities will help us personalize your content better")
    else:
        # Show loading state
        with st.spinner("Generating your personalized course..."):
            time.sleep(1.5)  # Simulating API call delay
            
            # Create payload
            payload = {
                "personalization_id": 100,
                "user_id": 30,
                "course_id": 47,
                "total_videos": 3,
                "created_at": datetime.utcnow().isoformat(),
                "user_profile": {
                    "personalized": True,
                    "user_name": user_name,
                    "user_age": user_age,
                    "user_gender": user_gender,
                    "user_tech_knowledge": tech_knowledge,
                    "user_preferred_activity": preferred_activity,
                    "user_food": food,
                    "user_physical_activities": physical_activities,
                    "learning_style": learning_style,
                    "target_language": target_language,
                    "tts_gender": tts_gender,
                    "tts_voice": tts_voice,
                    "toggle_hinglish": toggle_hinglish,
                    "run_visualization": False,
                    "subtitle": "",
                    "age_group": "18-25",
                },
                "topics": [
                    {
                        "topic_id": 10834,
                        "topic_title": "Setting Up Flask Environment",
                        "chapter_id": 647,
                        "chapter_title": "Introduction to Flask",
                        "course_id": 47,
                        "video_url": "https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/47/647/1729064365.mp4",
                        "video_duration": 462,
                        "sequence_number": 2
                    },
                    {
                        "topic_id": 10835,
                        "topic_title": "Understanding Flask Project Structure",
                        "chapter_id": 647,
                        "chapter_title": "Introduction to Flask",
                        "course_id": 47,
                        "video_url": "https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/47/647/1729064412.mp4",
                        "video_duration": 429,
                        "sequence_number": 3
                    },
                    {
                        "topic_id": 10833,
                        "topic_title": "What is Flask",
                        "chapter_id": 647,
                        "chapter_title": "Introduction to Flask",
                        "course_id": 47,
                        "video_url": "https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/47/647/1729064322.mp4",
                        "video_duration": 410,
                        "sequence_number": 1
                    }
                ],
                "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,
                }
            }

            # Make API call
            try:
                response = requests.post(API_ENDPOINT, json=payload)
                
                if response.status_code == 200:
                    st.success(f"Course personalized successfully for {user_name}!")
                    
                    # Display results in a clean format
                    st.markdown("### πŸŽ‰ Your personalized course is ready!")
                    st.markdown(f"""
                    **Course**: Introduction to Flask  
                    **Programming Language**: {programming_language.capitalize()}  
                    **Learning Style**: {learning_style.capitalize()}  
                    **Voice**: {tts_voice.capitalize()} ({tts_gender.capitalize()})
                    """)
                    
                    # Display API response
                    st.markdown('<div class="section-header">🌍 API Response</div>', unsafe_allow_html=True)
                    st.markdown('<div class="api-response">', unsafe_allow_html=True)
                    st.json(response.json())
                    st.markdown('</div>', unsafe_allow_html=True)
                else:
                    st.error(f"API Error: {response.status_code} - {response.text}")
            except Exception as e:
                st.error(f"API call failed: {e}")
                
                # Show local payload as fallback
                st.warning("Using local data as fallback:")
                st.json(payload)

# Footer
st.markdown("---")
st.caption("Β© 2025 Base Course Personalization | All Rights Reserved")