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(""" """, unsafe_allow_html=True) # App Header col1, col2, col3 = st.columns([1, 3, 1]) with col2: st.markdown('

📚 Base Course Personalization

', 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('
👤 Personal Details
', 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('
🎯 Preferences
', 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('
🎓 Learning Preferences
', 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('
🗣️ Language & Voice Settings
', 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('
💻 Technical Preferences
', 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("
", 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('
🌍 API Response
', unsafe_allow_html=True) st.markdown('
', unsafe_allow_html=True) st.json(response.json()) st.markdown('
', 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")