""" Integrate personalized learning pathway functionality into Gradio interface """ import gradio as gr import json from datetime import datetime from personalized_learning import ( UserProfilingSystem, LearningPathGenerator, AdaptiveLearningEngine ) # Initialize system components def initialize_personalized_learning(available_topics: list, client): """Initialize personalized learning system""" user_profiling = UserProfilingSystem() learning_path_generator = LearningPathGenerator(user_profiling, available_topics) adaptive_engine = AdaptiveLearningEngine(user_profiling, learning_path_generator) return user_profiling, learning_path_generator, adaptive_engine # Create personalized learning path tab def create_personalized_learning_tab(adaptive_engine, user_profiling, query_rag_model, generate_multiple_choice_questions, client): """Create personalized learning path tab""" with gr.TabItem("Personalized Learning Path"): gr.Markdown("## π― Your Personalized Learning Journey") gr.Markdown("Get a customized learning path based on your knowledge profile and performance.") # User ID input with gr.Row(): user_id_input = gr.Textbox( label="User ID", placeholder="Enter your user ID (e.g., user_001)", value="default_user" ) load_profile_btn = gr.Button("Load My Profile") # User profile display with gr.Column(visible=False) as profile_container: profile_summary = gr.Markdown() with gr.Row(): with gr.Column(): gr.Markdown("### π Knowledge Profile") knowledge_level_display = gr.JSON() with gr.Column(): gr.Markdown("### π Learning Statistics") learning_stats = gr.JSON() # Learning path section with gr.Row(): focus_areas_input = gr.CheckboxGroup( label="Focus Areas (Optional)", choices=[], value=[], interactive=True ) generate_path_btn = gr.Button("Generate Learning Path", variant="primary") # Learning path visualization with gr.Column(visible=False) as path_container: gr.Markdown("### πΊοΈ Your Learning Path") path_progress = gr.HTML() path_visualization = gr.HTML() # Current node information with gr.Row(): with gr.Column(): current_node_info = gr.Markdown() with gr.Column(): next_action_btn = gr.Button("Start This Node", variant="primary") skip_node_btn = gr.Button("Skip This Node") # Recommendations section with gr.Row(): with gr.Column(): gr.Markdown("### π‘ Recommendations") recommendations_display = gr.JSON() # Learning activity history with gr.Column(visible=False) as history_container: gr.Markdown("### π Learning History") learning_history = gr.Dataframe( headers=["Date", "Topic", "Activity", "Score"], interactive=False ) # Handler functions def load_user_profile(user_id): """Load user profile""" if not user_id: return ( gr.update(visible=False), # profile_container "", # profile_summary {}, # knowledge_level_display {}, # learning_stats [], # focus_areas_input choices gr.update(visible=False) # path_container ) profile = user_profiling.get_or_create_profile(user_id) summary = user_profiling.get_profile_summary(user_id) # Generate summary text summary_text = f""" ### π€ User Profile: {user_id} **Learning Style:** {summary['learning_style'].title()} **Learning Pace:** {summary['learning_pace'].title()} **Overall Progress:** {summary['overall_progress']:.1%} **Total Questions Asked:** {summary['total_questions']} **Total Tests Completed:** {summary['total_tests']} **Strong Areas:** {', '.join(summary['strong_areas']) if summary['strong_areas'] else 'None yet'} **Areas Needing Improvement:** {', '.join(summary['weak_areas']) if summary['weak_areas'] else 'None yet'} """ # Prepare knowledge level data knowledge_data = summary['knowledge_level'] if not knowledge_data: knowledge_data = {"No topics learned yet": 0.0} # Prepare statistics data stats_data = { "Total Questions": summary['total_questions'], "Total Tests": summary['total_tests'], "Preferred Topics": summary['preferred_topics'][:5] if summary['preferred_topics'] else [], "Overall Progress": f"{summary['overall_progress']:.1%}" } # Update focus areas options all_topics = list(set(list(knowledge_data.keys()) + summary['preferred_topics'] + summary['weak_areas'])) return ( gr.update(visible=True), summary_text, knowledge_data, stats_data, all_topics, gr.update(visible=False) ) def generate_learning_path(user_id, focus_areas): """Generate learning path""" if not user_id: return ( gr.update(visible=False), "", "", "", {}, gr.update(visible=False) ) path = adaptive_engine.create_or_update_path(user_id, focus_areas if focus_areas else None) # Generate path visualization HTML vis_data = adaptive_engine.get_path_visualization_data(user_id) # Create progress bar progress_html = f"""
Total Nodes: {len(path.nodes)} | Completed: {sum(1 for n in path.nodes if n.status == 'completed')} | Estimated Time: {path.estimated_total_time} minutes
""" # Create path visualization path_html = "