banao-tech commited on
Commit
62b2803
Β·
verified Β·
1 Parent(s): 3e66a46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -45
app.py CHANGED
@@ -22,22 +22,14 @@ AWS_DEFAULT_REGION = os.getenv("AWS_DEFAULT_REGION", "ap-south-1")
22
  # Default values
23
  DEFAULT_USER_ID = int(os.getenv("DEFAULT_USER_ID", "30"))
24
  DEFAULT_PERSONALIZATION_ID = int(os.getenv("DEFAULT_PERSONALIZATION_ID", "100"))
 
 
25
  API_TIMEOUT = int(os.getenv("API_TIMEOUT", "30"))
26
 
27
  # Authentication credentials from environment variables
28
  VALID_USERNAME = os.getenv("APP_USERNAME")
29
  VALID_PASSWORD = os.getenv("APP_PASSWORD")
30
 
31
- # Course configurations
32
- COURSE_CONFIGS = {
33
- "AI Ready Course": {"course_id": 47, "chapter_id": 647},
34
- "MERN": {"course_id": 48, "chapter_id": 648},
35
- "Machine Learning": {"course_id": 49, "chapter_id": 649},
36
- "Data Science": {"course_id": 50, "chapter_id": 650},
37
- "Flask": {"course_id": 51, "chapter_id": 651},
38
- "Django": {"course_id": 52, "chapter_id": 652}
39
- }
40
-
41
  # Set page configuration
42
  st.set_page_config(
43
  page_title="Base Course Personalization",
@@ -51,7 +43,7 @@ st.set_page_config(
51
  }
52
  )
53
 
54
- # Custom CSS for dark theme styling
55
  st.markdown("""
56
  <style>
57
  /* Dark theme colors */
@@ -313,6 +305,8 @@ if 'authenticated' not in st.session_state:
313
  st.session_state.authenticated = False
314
  if 'current_page' not in st.session_state:
315
  st.session_state.current_page = "Course Generation"
 
 
316
 
317
  # Initialize DynamoDB client
318
  @st.cache_resource
@@ -444,7 +438,7 @@ def render_admin_dashboard():
444
  with col1:
445
  session_id_input = st.text_input(
446
  "Enter Session ID",
447
- placeholder="e.g., 2025-01-15-12-30-45-abc123",
448
  help="Enter the session ID to monitor"
449
  )
450
  with col2:
@@ -620,29 +614,30 @@ with col4:
620
  st.session_state.topics_list = [{"topic_title": "What is Flask", "chapter_title": "Introduction to Flask"}]
621
  st.session_state.session_ids = []
622
  st.session_state.current_page = "Course Generation"
 
623
  st.rerun()
624
 
625
  # Page routing
626
  if st.session_state.current_page == "Admin Dashboard":
627
  render_admin_dashboard()
628
  else:
629
- # Course Generation Page (Original Content)
630
 
631
- # Course Selection Section
632
- st.markdown('<div class="section-header">πŸ“š Course Selection</div>', unsafe_allow_html=True)
633
 
634
- col1, col2 = st.columns([2, 3])
635
  with col1:
636
- selected_course = st.selectbox(
637
- "Select Course Type",
638
- options=list(COURSE_CONFIGS.keys()),
639
- index=0,
640
- help="Choose the course you want to generate content for"
641
  )
642
-
643
  with col2:
644
- st.info(f"**Selected:** {selected_course} (Course ID: {COURSE_CONFIGS[selected_course]['course_id']})")
645
-
646
  # Topics Section (Outside form for dynamic interaction)
647
  st.markdown('<div class="section-header">πŸ“‹ Topics Configuration</div>', unsafe_allow_html=True)
648
 
@@ -672,7 +667,7 @@ else:
672
 
673
  with col3:
674
  if len(st.session_state.topics_list) > 1:
675
- st.markdown("<br>", unsafe_allow_html=True) # Add spacing
676
  if st.button("πŸ—‘οΈ", key=f"remove_{i}", help="Remove this topic"):
677
  st.session_state.topics_list.pop(i)
678
  st.rerun()
@@ -797,7 +792,7 @@ else:
797
  help="Select the primary programming language, framework, or technology for examples"
798
  )
799
  with col2:
800
- st.markdown("<br>", unsafe_allow_html=True) # Add spacing
801
  toggle_hinglish = st.toggle("Enable Hinglish", value=True, help="Enable mixing of Hindi and English")
802
 
803
  # Submit button
@@ -811,10 +806,9 @@ else:
811
  # Use the topics from session state directly
812
  topics_to_process = st.session_state.topics_list
813
 
814
- # Get course configuration
815
- course_config = COURSE_CONFIGS[selected_course]
816
- course_id = course_config["course_id"]
817
- chapter_id = course_config["chapter_id"]
818
 
819
  # Validate inputs
820
  valid_topics = []
@@ -826,10 +820,10 @@ else:
826
  st.error("❌ Please enter at least one topic with both topic title and chapter title")
827
  else:
828
  # Show loading state with better animation
829
- with st.spinner(f"🎬 Generating your {selected_course} course... This may take a few moments."):
830
  progress_bar = st.progress(0)
831
  for i in range(100):
832
- time.sleep(0.02) # Simulating progress
833
  progress_bar.progress(i + 1)
834
 
835
  # Hardcoded values
@@ -873,29 +867,33 @@ else:
873
  topics_data = []
874
  for i, topic in enumerate(valid_topics):
875
  topics_data.append({
876
- "topic_id": 10834 + i, # Hardcoded with increment
877
  "topic_title": topic["topic_title"].strip(),
878
- "chapter_id": chapter_id, # From selected course
879
- "chapter_title": topic["chapter_title"].strip(), # User input
880
- "course_id": course_id, # From selected course
881
- "course_name": selected_course, # Add course name to each topic
882
- "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
883
- "video_duration": 462 + i*20, # Hardcoded with variation
884
  "sequence_number": i + 1,
885
  })
886
 
887
- # Create payload (always multiple topics structure) - NOW INCLUDING COURSE_NAME
888
  payload = {
889
  "personalization_id": personalization_id,
890
  "user_id": user_id,
891
  "course_id": course_id,
892
- "course_name": selected_course,
893
  "total_videos": len(topics_data),
894
  "created_at": datetime.utcnow().isoformat(),
895
  "user_profile": user_profile,
896
  "topics": topics_data,
897
  "settings": settings
898
  }
 
 
 
 
899
 
900
  # Make API call
901
  try:
@@ -909,7 +907,7 @@ else:
909
  response_data = response.json()
910
  session_ids = response_data.get("session_ids", [])
911
 
912
- st.success(f"πŸŽ‰ {selected_course} generation started successfully!")
913
 
914
  # Store session IDs in session state
915
  st.session_state.session_ids.extend(session_ids)
@@ -920,8 +918,8 @@ else:
920
  col1, col2 = st.columns(2)
921
  with col1:
922
  st.markdown(f"""
923
- **Course**: {selected_course}
924
  **Course ID**: {course_id}
 
925
  **Programming Language**: {programming_language.capitalize()}
926
  **Target Language**: {target_language.capitalize()}
927
  """)
@@ -930,7 +928,7 @@ else:
930
  **Voice**: {tts_voice.capitalize()} ({tts_gender.capitalize()})
931
  **Topics Count**: {len(valid_topics)}
932
  **Hinglish**: {"Enabled" if toggle_hinglish else "Disabled"}
933
- **Chapter ID**: {chapter_id}
934
  """)
935
 
936
  # Display session IDs
@@ -948,7 +946,7 @@ else:
948
  # Information about tracking
949
  st.info(f"""
950
  πŸ’‘ **Tracking Information**
951
- You can track the progress of your {selected_course} course generation using the session IDs above.
952
  The processing status will be updated in DynamoDB table: {SESSION_TABLE}
953
  Region: {DYNAMODB_REGION}
954
 
 
22
  # Default values
23
  DEFAULT_USER_ID = int(os.getenv("DEFAULT_USER_ID", "30"))
24
  DEFAULT_PERSONALIZATION_ID = int(os.getenv("DEFAULT_PERSONALIZATION_ID", "100"))
25
+ DEFAULT_COURSE_ID = int(os.getenv("DEFAULT_COURSE_ID", "47"))
26
+ DEFAULT_CHAPTER_ID = int(os.getenv("DEFAULT_CHAPTER_ID", "647"))
27
  API_TIMEOUT = int(os.getenv("API_TIMEOUT", "30"))
28
 
29
  # Authentication credentials from environment variables
30
  VALID_USERNAME = os.getenv("APP_USERNAME")
31
  VALID_PASSWORD = os.getenv("APP_PASSWORD")
32
 
 
 
 
 
 
 
 
 
 
 
33
  # Set page configuration
34
  st.set_page_config(
35
  page_title="Base Course Personalization",
 
43
  }
44
  )
45
 
46
+ # Custom CSS for dark theme styling (keep existing CSS)
47
  st.markdown("""
48
  <style>
49
  /* Dark theme colors */
 
305
  st.session_state.authenticated = False
306
  if 'current_page' not in st.session_state:
307
  st.session_state.current_page = "Course Generation"
308
+ if 'manual_session_id' not in st.session_state:
309
+ st.session_state.manual_session_id = ""
310
 
311
  # Initialize DynamoDB client
312
  @st.cache_resource
 
438
  with col1:
439
  session_id_input = st.text_input(
440
  "Enter Session ID",
441
+ placeholder="e.g., sess_abc123 or 2025-01-15-12-30-45-abc123",
442
  help="Enter the session ID to monitor"
443
  )
444
  with col2:
 
614
  st.session_state.topics_list = [{"topic_title": "What is Flask", "chapter_title": "Introduction to Flask"}]
615
  st.session_state.session_ids = []
616
  st.session_state.current_page = "Course Generation"
617
+ st.session_state.manual_session_id = ""
618
  st.rerun()
619
 
620
  # Page routing
621
  if st.session_state.current_page == "Admin Dashboard":
622
  render_admin_dashboard()
623
  else:
624
+ # Course Generation Page
625
 
626
+ # NEW: Manual Session ID Section
627
+ st.markdown('<div class="section-header">🎯 Session ID Configuration</div>', unsafe_allow_html=True)
628
 
629
+ col1, col2 = st.columns([3, 2])
630
  with col1:
631
+ manual_session_id_input = st.text_input(
632
+ "Manual Session ID (Optional)",
633
+ value=st.session_state.manual_session_id,
634
+ placeholder="Leave empty for auto-generated session ID (e.g., sess_abc12345)",
635
+ help="Provide a custom session ID or leave empty to auto-generate"
636
  )
637
+ st.session_state.manual_session_id = manual_session_id_input
638
  with col2:
639
+ st.info("πŸ’‘ If provided, this session ID will be used instead of auto-generating one")
640
+
641
  # Topics Section (Outside form for dynamic interaction)
642
  st.markdown('<div class="section-header">πŸ“‹ Topics Configuration</div>', unsafe_allow_html=True)
643
 
 
667
 
668
  with col3:
669
  if len(st.session_state.topics_list) > 1:
670
+ st.markdown("<br>", unsafe_allow_html=True)
671
  if st.button("πŸ—‘οΈ", key=f"remove_{i}", help="Remove this topic"):
672
  st.session_state.topics_list.pop(i)
673
  st.rerun()
 
792
  help="Select the primary programming language, framework, or technology for examples"
793
  )
794
  with col2:
795
+ st.markdown("<br>", unsafe_allow_html=True)
796
  toggle_hinglish = st.toggle("Enable Hinglish", value=True, help="Enable mixing of Hindi and English")
797
 
798
  # Submit button
 
806
  # Use the topics from session state directly
807
  topics_to_process = st.session_state.topics_list
808
 
809
+ # Use default course configuration
810
+ course_id = DEFAULT_COURSE_ID
811
+ chapter_id = DEFAULT_CHAPTER_ID
 
812
 
813
  # Validate inputs
814
  valid_topics = []
 
820
  st.error("❌ Please enter at least one topic with both topic title and chapter title")
821
  else:
822
  # Show loading state with better animation
823
+ with st.spinner(f"🎬 Generating your course... This may take a few moments."):
824
  progress_bar = st.progress(0)
825
  for i in range(100):
826
+ time.sleep(0.02)
827
  progress_bar.progress(i + 1)
828
 
829
  # Hardcoded values
 
867
  topics_data = []
868
  for i, topic in enumerate(valid_topics):
869
  topics_data.append({
870
+ "topic_id": 10834 + i,
871
  "topic_title": topic["topic_title"].strip(),
872
+ "chapter_id": chapter_id,
873
+ "chapter_title": topic["chapter_title"].strip(),
874
+ "course_id": course_id,
875
+ "course_name": "Base Course",
876
+ "video_url": f"https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/{course_id}/{chapter_id}/172906{4365+i*50}.mp4",
877
+ "video_duration": 462 + i*20,
878
  "sequence_number": i + 1,
879
  })
880
 
881
+ # Create payload with manual session ID if provided
882
  payload = {
883
  "personalization_id": personalization_id,
884
  "user_id": user_id,
885
  "course_id": course_id,
886
+ "course_name": "Base Course",
887
  "total_videos": len(topics_data),
888
  "created_at": datetime.utcnow().isoformat(),
889
  "user_profile": user_profile,
890
  "topics": topics_data,
891
  "settings": settings
892
  }
893
+
894
+ # Add manual session ID if provided
895
+ if st.session_state.manual_session_id.strip():
896
+ payload["manual_session_id"] = st.session_state.manual_session_id.strip()
897
 
898
  # Make API call
899
  try:
 
907
  response_data = response.json()
908
  session_ids = response_data.get("session_ids", [])
909
 
910
+ st.success(f"πŸŽ‰ Course generation started successfully!")
911
 
912
  # Store session IDs in session state
913
  st.session_state.session_ids.extend(session_ids)
 
918
  col1, col2 = st.columns(2)
919
  with col1:
920
  st.markdown(f"""
 
921
  **Course ID**: {course_id}
922
+ **Chapter ID**: {chapter_id}
923
  **Programming Language**: {programming_language.capitalize()}
924
  **Target Language**: {target_language.capitalize()}
925
  """)
 
928
  **Voice**: {tts_voice.capitalize()} ({tts_gender.capitalize()})
929
  **Topics Count**: {len(valid_topics)}
930
  **Hinglish**: {"Enabled" if toggle_hinglish else "Disabled"}
931
+ **Manual Session ID**: {st.session_state.manual_session_id if st.session_state.manual_session_id.strip() else "Auto-generated"}
932
  """)
933
 
934
  # Display session IDs
 
946
  # Information about tracking
947
  st.info(f"""
948
  πŸ’‘ **Tracking Information**
949
+ You can track the progress of your course generation using the session IDs above.
950
  The processing status will be updated in DynamoDB table: {SESSION_TABLE}
951
  Region: {DYNAMODB_REGION}
952