""" Cold start onboarding module Used to collect initial information from new users """ import gradio as gr from typing import Dict, List try: from modules.personalized_learning import UserProfilingSystem except ImportError: # Fallback for direct import from personalized_learning import UserProfilingSystem def create_onboarding_interface(user_profiling: UserProfilingSystem, available_topics: List[str]): """Create cold start onboarding interface""" def process_onboarding(user_id: str, background: str, learning_style: str, learning_pace: str, learning_goals: List[str], knowledge_survey: Dict[str, float]) -> Dict: """Process cold start data collection""" # Build onboarding data onboarding_data = { 'learning_style': learning_style, 'learning_pace': learning_pace, 'background_experience': background, 'learning_goals': learning_goals if learning_goals else [], 'initial_knowledge_survey': knowledge_survey, 'initial_assessment_completed': True } # Complete cold start setup profile = user_profiling.complete_onboarding(user_id, onboarding_data) return { "status": "success", "message": f"Onboarding completed for {user_id}", "profile_summary": user_profiling.get_profile_summary(user_id) } def create_onboarding_form(): """Create cold start form""" with gr.Blocks(title="Welcome! Let's Get Started") as onboarding: gr.Markdown("# 🎯 Welcome to Personalized Learning!") gr.Markdown("We need some information to create your personalized learning path.") with gr.Row(): user_id_input = gr.Textbox( label="User ID", placeholder="Enter your user ID", value="new_user" ) with gr.Accordion("📋 Step 1: Background Information", open=True): background_input = gr.Radio( label="What's your experience with ADAS systems?", choices=[ ("Beginner - I'm new to ADAS systems", "beginner"), ("Intermediate - I know some basics", "intermediate"), ("Experienced - I have good knowledge", "experienced") ], value="beginner" ) with gr.Accordion("🎨 Step 2: Learning Preferences", open=True): learning_style_input = gr.Radio( label="How do you prefer to learn?", choices=[ ("Visual - I like diagrams and illustrations", "visual"), ("Textual - I prefer reading and explanations", "textual"), ("Practical - I learn by doing", "practical"), ("Mixed - I like a combination", "mixed") ], value="mixed" ) learning_pace_input = gr.Radio( label="What's your preferred learning pace?", choices=[ ("Slow - I like to take my time", "slow"), ("Medium - Normal pace is fine", "medium"), ("Fast - I want to learn quickly", "fast") ], value="medium" ) with gr.Accordion("🎯 Step 3: Learning Goals", open=True): learning_goals_input = gr.CheckboxGroup( label="What are your learning goals? (Select all that apply)", choices=[ "Understand basic ADAS functions", "Learn how to operate ADAS features", "Master advanced ADAS capabilities", "Troubleshoot ADAS issues", "Prepare for certification", "General knowledge improvement" ], value=["Understand basic ADAS functions"] ) with gr.Accordion("📊 Step 4: Initial Knowledge Assessment", open=True): gr.Markdown("Rate your familiarity with each topic (0 = No knowledge, 1 = Expert)") knowledge_sliders = {} for topic in available_topics: # Simplify topic name for display display_name = topic.replace("Function of ", "").replace(" Assist", "") knowledge_sliders[topic] = gr.Slider( label=display_name, minimum=0.0, maximum=1.0, value=0.0, step=0.1 ) with gr.Row(): submit_btn = gr.Button("Complete Setup", variant="primary") output_result = gr.JSON(label="Setup Result") def submit_onboarding(user_id: str, background: str, learning_style: str, learning_pace: str, learning_goals: List[str], **knowledge_values): """Submit cold start data""" # Build knowledge survey dictionary knowledge_survey = {} for topic in available_topics: knowledge_survey[topic] = knowledge_values.get(topic, 0.0) # Process background selection (extract value from tuple) if isinstance(background, tuple): background = background[1] if len(background) > 1 else background[0] if isinstance(learning_style, tuple): learning_style = learning_style[1] if len(learning_style) > 1 else learning_style[0] if isinstance(learning_pace, tuple): learning_pace = learning_pace[1] if len(learning_pace) > 1 else learning_pace[0] result = process_onboarding( user_id, background, learning_style, learning_pace, learning_goals, knowledge_survey ) return result # Build input list inputs = [user_id_input, background_input, learning_style_input, learning_pace_input, learning_goals_input] + list(knowledge_sliders.values()) submit_btn.click( submit_onboarding, inputs=inputs, outputs=output_result ) return onboarding return create_onboarding_form() def check_and_show_onboarding(user_profiling: UserProfilingSystem, user_id: str) -> bool: """Check if cold start interface needs to be shown""" return user_profiling.is_cold_start(user_id) def get_onboarding_data_summary(user_profiling: UserProfilingSystem, user_id: str) -> Dict: """Get summary of data collected during cold start""" if user_profiling.is_cold_start(user_id): return { "status": "cold_start", "message": "User has not completed onboarding" } profile = user_profiling.get_or_create_profile(user_id) return { "status": "completed", "has_completed_onboarding": profile.has_completed_onboarding, "background_experience": profile.background_experience, "learning_style": profile.learning_style, "learning_pace": profile.learning_pace, "learning_goals": profile.learning_goals if profile.learning_goals else [], "initial_knowledge_survey": profile.initial_knowledge_survey if profile.initial_knowledge_survey else {}, "initial_assessment_completed": profile.initial_assessment_completed }