Spaces:
Sleeping
Sleeping
File size: 8,130 Bytes
6a11527 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
"""
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
}
|