banao-tech commited on
Commit
0e658c0
Β·
verified Β·
1 Parent(s): 2b2f698

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -64
app.py CHANGED
@@ -169,14 +169,61 @@ st.markdown("""
169
  </style>
170
  """, unsafe_allow_html=True)
171
 
172
- # Initialize session state for topics
173
  if 'topics_list' not in st.session_state:
174
- st.session_state.topics_list = [{"topic_title": "What is Flask"}]
175
  if 'session_ids' not in st.session_state:
176
  st.session_state.session_ids = []
 
 
177
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  # App Header
179
- st.markdown('<h1 class="main-header">πŸ“š Base Course Personalization</h1>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
180
  st.markdown("""
181
  <div style="text-align: center; margin-bottom: 2rem;">
182
  Complete this form to tailor your learning experience to your preferences.<br>
@@ -268,21 +315,21 @@ with st.form("personalization_form", clear_on_submit=False):
268
  if topic_mode == "Multiple Topics":
269
  col1, col2, col3 = st.columns([1, 1, 2])
270
  with col1:
271
- if st.button("βž• Add More Topic"):
272
  st.session_state.topics_list.append({"topic_title": f"Topic {len(st.session_state.topics_list) + 1}"})
273
  st.rerun()
274
  with col2:
275
- if st.button("πŸ”„ Reset Topics"):
276
  st.session_state.topics_list = [{"topic_title": "What is Flask"}]
277
  st.rerun()
278
 
279
  # Handle submission
280
  if submitted:
281
  # Validate inputs
282
- if topic_mode == "Single Topic" and not single_topic_title:
283
- st.error("Please enter a topic title")
284
- elif topic_mode == "Multiple Topics" and not any(topic["topic_title"] for topic in st.session_state.topics_list):
285
- st.error("Please enter at least one topic title")
286
  else:
287
  # Show loading state
288
  with st.spinner("Generating your personalized course..."):
@@ -326,49 +373,31 @@ if submitted:
326
  "video_type": "base_video"
327
  }
328
 
329
- # Create payload based on topic mode
330
- if topic_mode == "Single Topic":
331
- payload = {
332
- "personalization_id": personalization_id,
333
- "user_profile": user_profile,
334
- "settings": settings,
335
- "topic_data": {
336
- "topic_id": 10834, # Hardcoded
337
- "topic_title": single_topic_title,
338
- "chapter_id": 647, # Hardcoded
339
- "chapter_title": "Introduction to Flask", # Hardcoded
340
- "course_id": course_id,
341
- "video_url": "https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/47/647/1729064365.mp4", # Hardcoded
342
- "video_duration": 462, # Hardcoded
343
- "sequence_number": 1 # Hardcoded
344
- }
345
- }
346
- else:
347
- # Generate topics data with hardcoded values
348
- topics_data = []
349
- for i, topic in enumerate(st.session_state.topics_list):
350
- if topic["topic_title"]: # Only include non-empty topics
351
- topics_data.append({
352
- "topic_id": 10834 + i, # Hardcoded with increment
353
- "topic_title": topic["topic_title"],
354
- "chapter_id": 647, # Hardcoded
355
- "chapter_title": "Introduction to Flask", # Hardcoded
356
- "course_id": course_id,
357
- "video_url": f"https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/47/647/172906{4365+i*50}.mp4", # Hardcoded with variation
358
- "video_duration": 462 + i*20, # Hardcoded with variation
359
- "sequence_number": i + 1,
360
- })
361
-
362
- payload = {
363
- "personalization_id": personalization_id,
364
- "user_id": user_id,
365
  "course_id": course_id,
366
- "total_videos": len(topics_data),
367
- "created_at": datetime.utcnow().isoformat(),
368
- "user_profile": user_profile,
369
- "topics": topics_data,
370
- "settings": settings
371
- }
 
 
 
 
 
 
 
 
 
 
372
 
373
  # Make API call
374
  try:
@@ -394,7 +423,7 @@ if submitted:
394
  **Programming Language**: {programming_language.capitalize()}
395
  **Target Language**: {target_language.capitalize()}
396
  **Voice**: {tts_voice.capitalize()} ({tts_gender.capitalize()})
397
- **Topics**: {len(st.session_state.topics_list) if topic_mode == "Multiple Topics" else 1}
398
  """)
399
 
400
  # Display session IDs
@@ -432,15 +461,3 @@ if submitted:
432
  # Show payload for debugging
433
  st.warning("Request payload for debugging:")
434
  st.json(payload)
435
-
436
- # Display previous session IDs if any
437
- if st.session_state.session_ids:
438
- st.markdown("---")
439
- st.markdown("### πŸ“‹ Previous Session IDs")
440
- for i, session_id in enumerate(st.session_state.session_ids, 1):
441
- st.markdown(f'<div class="session-info"><strong>Session {i}:</strong> <code>{session_id}</code></div>', unsafe_allow_html=True)
442
-
443
- # Button to clear session history
444
- if st.button("Clear Session History"):
445
- st.session_state.session_ids = []
446
- st.rerun()
 
169
  </style>
170
  """, unsafe_allow_html=True)
171
 
172
+ # Initialize session state for topics and authentication
173
  if 'topics_list' not in st.session_state:
174
+ st.session_state.topics_list = [{"topic_title": "What is Flask", "chapter_title": "Introduction to Flask"}]
175
  if 'session_ids' not in st.session_state:
176
  st.session_state.session_ids = []
177
+ if 'authenticated' not in st.session_state:
178
+ st.session_state.authenticated = False
179
 
180
+ # Hardcoded credentials (you can change these)
181
+ VALID_USERNAME = "admin"
182
+ VALID_PASSWORD = "techlearn2024"
183
+
184
+ # Authentication check
185
+ if not st.session_state.authenticated:
186
+ st.markdown('<h1 class="main-header">πŸ” Login to Course Personalization</h1>', unsafe_allow_html=True)
187
+
188
+ with st.form("login_form"):
189
+ st.markdown('<div class="section-header">πŸ”‘ Authentication Required</div>', unsafe_allow_html=True)
190
+
191
+ col1, col2, col3 = st.columns([1, 2, 1])
192
+ with col2:
193
+ username = st.text_input("Username", placeholder="Enter username")
194
+ password = st.text_input("Password", placeholder="Enter password", type="password")
195
+
196
+ login_submitted = st.form_submit_button("πŸš€ Login", use_container_width=True)
197
+
198
+ if login_submitted:
199
+ if username == VALID_USERNAME and password == VALID_PASSWORD:
200
+ st.session_state.authenticated = True
201
+ st.success("Login successful! Redirecting...")
202
+ time.sleep(1)
203
+ st.rerun()
204
+ else:
205
+ st.error(" Invalid username or password")
206
+
207
+ st.markdown("---")
208
+ st.markdown("""
209
+ <div style="text-align: center; color: #888888;">
210
+ <small>Demo Credentials: admin / techlearn2024</small>
211
+ </div>
212
+ """, unsafe_allow_html=True)
213
+ st.stop()
214
+
215
+ # Main app (only shown after authentication)
216
  # App Header
217
+ col1, col2, col3 = st.columns([1, 2, 1])
218
+ with col2:
219
+ st.markdown('<h1 class="main-header">πŸ“š Base Course Personalization</h1>', unsafe_allow_html=True)
220
+ with col3:
221
+ if st.button(" Logout"):
222
+ st.session_state.authenticated = False
223
+ st.session_state.topics_list = [{"topic_title": "What is Flask", "chapter_title": "Introduction to Flask"}]
224
+ st.session_state.session_ids = []
225
+ st.rerun()
226
+
227
  st.markdown("""
228
  <div style="text-align: center; margin-bottom: 2rem;">
229
  Complete this form to tailor your learning experience to your preferences.<br>
 
315
  if topic_mode == "Multiple Topics":
316
  col1, col2, col3 = st.columns([1, 1, 2])
317
  with col1:
318
+ if st.button(" Add More Topic"):
319
  st.session_state.topics_list.append({"topic_title": f"Topic {len(st.session_state.topics_list) + 1}"})
320
  st.rerun()
321
  with col2:
322
+ if st.button(" Reset Topics"):
323
  st.session_state.topics_list = [{"topic_title": "What is Flask"}]
324
  st.rerun()
325
 
326
  # Handle submission
327
  if submitted:
328
  # Validate inputs
329
+ valid_topics = [topic for topic in st.session_state.topics_list if topic["topic_title"].strip() and topic["chapter_title"].strip()]
330
+
331
+ if not valid_topics:
332
+ st.error("Please enter at least one topic with both topic title and chapter title")
333
  else:
334
  # Show loading state
335
  with st.spinner("Generating your personalized course..."):
 
373
  "video_type": "base_video"
374
  }
375
 
376
+ # Generate topics data with user input for titles and hardcoded values for others
377
+ topics_data = []
378
+ for i, topic in enumerate(valid_topics):
379
+ topics_data.append({
380
+ "topic_id": 10834 + i, # Hardcoded with increment
381
+ "topic_title": topic["topic_title"].strip(),
382
+ "chapter_id": 647, # Hardcoded
383
+ "chapter_title": topic["chapter_title"].strip(), # User input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  "course_id": course_id,
385
+ "video_url": f"https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/47/647/172906{4365+i*50}.mp4", # Hardcoded with variation
386
+ "video_duration": 462 + i*20, # Hardcoded with variation
387
+ "sequence_number": i + 1,
388
+ })
389
+
390
+ # Create payload (always multiple topics structure)
391
+ payload = {
392
+ "personalization_id": personalization_id,
393
+ "user_id": user_id,
394
+ "course_id": course_id,
395
+ "total_videos": len(topics_data),
396
+ "created_at": datetime.utcnow().isoformat(),
397
+ "user_profile": user_profile,
398
+ "topics": topics_data,
399
+ "settings": settings
400
+ }
401
 
402
  # Make API call
403
  try:
 
423
  **Programming Language**: {programming_language.capitalize()}
424
  **Target Language**: {target_language.capitalize()}
425
  **Voice**: {tts_voice.capitalize()} ({tts_gender.capitalize()})
426
+ **Topics**: {len(valid_topics)}
427
  """)
428
 
429
  # Display session IDs
 
461
  # Show payload for debugging
462
  st.warning("Request payload for debugging:")
463
  st.json(payload)