Update app.py
Browse files
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
|
| 630 |
|
| 631 |
-
#
|
| 632 |
-
st.markdown('<div class="section-header"
|
| 633 |
|
| 634 |
-
col1, col2 = st.columns([
|
| 635 |
with col1:
|
| 636 |
-
|
| 637 |
-
"
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
help="
|
| 641 |
)
|
| 642 |
-
|
| 643 |
with col2:
|
| 644 |
-
st.info(
|
| 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)
|
| 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)
|
| 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 |
-
#
|
| 815 |
-
|
| 816 |
-
|
| 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
|
| 830 |
progress_bar = st.progress(0)
|
| 831 |
for i in range(100):
|
| 832 |
-
time.sleep(0.02)
|
| 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,
|
| 877 |
"topic_title": topic["topic_title"].strip(),
|
| 878 |
-
"chapter_id": chapter_id,
|
| 879 |
-
"chapter_title": topic["chapter_title"].strip(),
|
| 880 |
-
"course_id": course_id,
|
| 881 |
-
"course_name":
|
| 882 |
-
"video_url": f"https://techlearn-dev.s3.ap-south-1.amazonaws.com/course_videos/{course_id}/{chapter_id}/172906{4365+i*50}.mp4",
|
| 883 |
-
"video_duration": 462 + i*20,
|
| 884 |
"sequence_number": i + 1,
|
| 885 |
})
|
| 886 |
|
| 887 |
-
# Create payload
|
| 888 |
payload = {
|
| 889 |
"personalization_id": personalization_id,
|
| 890 |
"user_id": user_id,
|
| 891 |
"course_id": course_id,
|
| 892 |
-
"course_name":
|
| 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"π
|
| 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 |
-
**
|
| 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
|
| 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 |
|