Spaces:
Sleeping
Sleeping
File size: 14,298 Bytes
a044ede |
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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
"""
Educational Interface Page for POLYMEROS
Interactive learning system with adaptive progression and virtual laboratory
"""
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
import json
from typing import Dict, List, Any
# Import POLYMEROS educational components
import sys
import os
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), "modules"))
from modules.educational_framework import EducationalFramework
def init_educational_session():
"""Initialize educational session state"""
if "educational_framework" not in st.session_state:
st.session_state.educational_framework = EducationalFramework()
if "current_user_id" not in st.session_state:
st.session_state.current_user_id = "demo_user"
if "user_progress" not in st.session_state:
st.session_state.user_progress = (
st.session_state.educational_framework.initialize_user(
st.session_state.current_user_id
)
)
def render_competency_assessment():
"""Render interactive competency assessment"""
st.header("π§ͺ Knowledge Assessment")
domains = ["spectroscopy_basics", "polymer_aging", "ai_ml_concepts"]
selected_domain = st.selectbox(
"Select assessment domain:",
domains,
format_func=lambda x: x.replace("_", " ").title(),
)
framework = st.session_state.educational_framework
assessor = framework.competency_assessor
if selected_domain in assessor.assessment_tasks:
tasks = assessor.assessment_tasks[selected_domain]
st.subheader(f"Assessment: {selected_domain.replace('_', ' ').title()}")
responses = []
for i, task in enumerate(tasks):
st.write(f"**Question {i+1}:** {task['question']}")
response = st.radio(
f"Select answer for question {i+1}:",
options=range(len(task["options"])),
format_func=lambda x, task=task: task["options"][x],
key=f"q_{selected_domain}_{i}",
index=0,
)
responses.append(response)
if st.button("Submit Assessment", key=f"submit_{selected_domain}"):
results = framework.assess_user_competency(selected_domain, responses)
st.success(f"Assessment completed! Score: {results['score']:.1%}")
st.write(f"**Your level:** {results['level']}")
st.subheader("Detailed Feedback:")
for feedback in results["feedback"]:
st.write(feedback)
st.subheader("Recommendations:")
for rec in results["recommendations"]:
st.write(f"β’ {rec}")
def render_learning_path():
"""Render personalized learning path"""
st.header("π― Your Learning Path")
user_progress = st.session_state.user_progress
framework = st.session_state.educational_framework
# Display current progress
col1, col2, col3 = st.columns(3)
with col1:
st.metric("Completed Objectives", len(user_progress.completed_objectives))
with col2:
avg_score = (
np.mean(list(user_progress.competency_scores.values()))
if user_progress.competency_scores
else 0
)
st.metric("Average Score", f"{avg_score:.1%}")
with col3:
st.metric("Current Level", user_progress.current_level.title())
# Learning style selection
st.subheader("Learning Preferences")
learning_styles = ["visual", "hands-on", "theoretical", "collaborative"]
current_style = user_progress.preferred_learning_style
new_style = st.selectbox(
"Preferred learning style:",
learning_styles,
index=(
learning_styles.index(current_style)
if current_style in learning_styles
else 0
),
)
if new_style != current_style:
user_progress.preferred_learning_style = new_style
framework.save_user_progress()
st.success("Learning style updated!")
# Target competencies
st.subheader("Learning Goals")
target_competencies = st.multiselect(
"Select areas you want to focus on:",
["spectroscopy", "polymer_science", "machine_learning", "data_analysis"],
default=["spectroscopy", "polymer_science"],
)
if st.button("Generate Learning Path"):
learning_path = framework.get_personalized_learning_path(target_competencies)
if learning_path:
st.subheader("Recommended Learning Path:")
for i, item in enumerate(learning_path):
objective = item["objective"]
with st.expander(
f"{i+1}. {objective['title']} (Level {objective['difficulty_level']})"
):
st.write(f"**Description:** {objective['description']}")
st.write(
f"**Estimated time:** {objective['estimated_time']} minutes"
)
st.write(
f"**Recommended approach:** {item['recommended_approach']}"
)
if item["priority_resources"]:
st.write("**Priority resources:**")
for resource in item["priority_resources"]:
st.write(f"- {resource['type']}: {resource['url']}")
else:
st.info("Complete an assessment to get personalized recommendations!")
def render_virtual_laboratory():
"""Render virtual laboratory interface"""
st.header("π¬ Virtual Laboratory")
framework = st.session_state.educational_framework
virtual_lab = framework.virtual_lab
# Select experiment
experiments = list(virtual_lab.experiments.keys())
selected_experiment = st.selectbox(
"Select experiment:",
experiments,
format_func=lambda x: virtual_lab.experiments[x]["title"],
)
experiment_info = virtual_lab.experiments[selected_experiment]
st.subheader(experiment_info["title"])
st.write(f"**Description:** {experiment_info['description']}")
st.write(f"**Difficulty:** {experiment_info['difficulty']}/5")
st.write(f"**Estimated time:** {experiment_info['estimated_time']} minutes")
# Experiment-specific inputs
if selected_experiment == "polymer_identification":
st.subheader("Polymer Identification Challenge")
polymer_type = st.selectbox(
"Select polymer to analyze:", ["PE", "PP", "PS", "PVC"]
)
if st.button("Generate Spectrum"):
result = framework.run_virtual_experiment(
selected_experiment, {"polymer_type": polymer_type}
)
if result.get("success"):
# Plot the spectrum
fig, ax = plt.subplots(figsize=(10, 6))
ax.plot(result["wavenumbers"], result["spectrum"])
ax.set_xlabel("Wavenumber (cmβ»ΒΉ)")
ax.set_ylabel("Intensity")
ax.set_title(f"Unknown Polymer Spectrum")
ax.grid(True, alpha=0.3)
st.pyplot(fig)
st.subheader("Analysis Hints:")
for hint in result["hints"]:
st.write(f"π‘ {hint}")
# User identification
user_guess = st.selectbox(
"Your identification:", ["PE", "PP", "PS", "PVC"]
)
if st.button("Submit Identification"):
if user_guess == polymer_type:
st.success("π Correct! Well done!")
else:
st.error(f"β Incorrect. The correct answer is {polymer_type}")
elif selected_experiment == "aging_simulation":
st.subheader("Polymer Aging Simulation")
aging_time = st.slider("Aging time (hours):", 0, 200, 50)
if st.button("Run Aging Simulation"):
result = framework.run_virtual_experiment(
selected_experiment, {"aging_time": aging_time}
)
if result.get("success"):
# Plot comparison
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(15, 6))
# Initial spectrum
ax1.plot(result["wavenumbers"], result["initial_spectrum"])
ax1.set_title("Initial Spectrum")
ax1.set_xlabel("Wavenumber (cmβ»ΒΉ)")
ax1.set_ylabel("Intensity")
ax1.grid(True, alpha=0.3)
# Aged spectrum
ax2.plot(result["wavenumbers"], result["aged_spectrum"])
ax2.set_title(f"After {aging_time} hours")
ax2.set_xlabel("Wavenumber (cmβ»ΒΉ)")
ax2.set_ylabel("Intensity")
ax2.grid(True, alpha=0.3)
plt.tight_layout()
st.pyplot(fig)
st.subheader("Observations:")
for obs in result["observations"]:
st.write(f"π {obs}")
elif selected_experiment == "model_training":
st.subheader("Train Your Own Model")
col1, col2 = st.columns(2)
with col1:
model_type = st.selectbox("Model type:", ["CNN", "ResNet", "Transformer"])
with col2:
epochs = st.slider("Training epochs:", 5, 50, 10)
if st.button("Start Training"):
with st.spinner("Training model..."):
result = framework.run_virtual_experiment(
selected_experiment, {"model_type": model_type, "epochs": epochs}
)
if result.get("success"):
# Plot training metrics
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5))
# Training loss
ax1.plot(result["train_losses"])
ax1.set_title("Training Loss")
ax1.set_xlabel("Epoch")
ax1.set_ylabel("Loss")
ax1.grid(True, alpha=0.3)
# Validation accuracy
ax2.plot(result["val_accuracies"])
ax2.set_title("Validation Accuracy")
ax2.set_xlabel("Epoch")
ax2.set_ylabel("Accuracy")
ax2.grid(True, alpha=0.3)
plt.tight_layout()
st.pyplot(fig)
st.success(
f"Training completed! Final accuracy: {result['final_accuracy']:.3f}"
)
st.subheader("Training Insights:")
for insight in result["insights"]:
st.write(f"π― {insight}")
def render_progress_analytics():
"""Render learning analytics dashboard"""
st.header("π Your Progress Analytics")
framework = st.session_state.educational_framework
analytics = framework.get_learning_analytics()
if analytics:
# Overview metrics
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Completed Objectives", analytics["completed_objectives"])
with col2:
st.metric("Study Time", f"{analytics['total_study_time']} min")
with col3:
st.metric("Current Level", analytics["current_level"].title())
with col4:
st.metric("Sessions", analytics["session_count"])
# Competency scores
if analytics["competency_scores"]:
st.subheader("Competency Scores")
domains = list(analytics["competency_scores"].keys())
scores = list(analytics["competency_scores"].values())
fig, ax = plt.subplots(figsize=(10, 6))
bars = ax.bar(domains, scores)
ax.set_ylabel("Score")
ax.set_title("Competency Assessment Results")
ax.set_ylim(0, 1)
# Color bars based on score
for bar, score in zip(bars, scores):
if score >= 0.8:
bar.set_color("green")
elif score >= 0.6:
bar.set_color("orange")
else:
bar.set_color("red")
plt.xticks(rotation=45)
plt.tight_layout()
st.pyplot(fig)
# Learning style
st.subheader("Learning Profile")
st.write(f"**Preferred learning style:** {analytics['learning_style'].title()}")
# Recommendations
recommendations = framework.get_learning_recommendations()
if recommendations:
st.subheader("Next Steps")
for rec in recommendations:
st.write(f"β’ {rec}")
else:
st.info("Complete assessments to see your progress analytics!")
def main():
"""Main educational interface"""
st.set_page_config(
page_title="POLYMEROS Educational Interface", page_icon="π", layout="wide"
)
st.title("π POLYMEROS Educational Interface")
st.markdown("**Interactive Learning System for Polymer Science and AI**")
# Initialize session
init_educational_session()
# Sidebar navigation
st.sidebar.title("π Learning Modules")
page = st.sidebar.selectbox(
"Select module:",
[
"Knowledge Assessment",
"Learning Path",
"Virtual Laboratory",
"Progress Analytics",
],
)
# Render selected page
if page == "Knowledge Assessment":
render_competency_assessment()
elif page == "Learning Path":
render_learning_path()
elif page == "Virtual Laboratory":
render_virtual_laboratory()
elif page == "Progress Analytics":
render_progress_analytics()
# Footer
st.sidebar.markdown("---")
st.sidebar.markdown("**POLYMEROS Educational Framework**")
st.sidebar.markdown("*Adaptive learning for polymer science*")
if __name__ == "__main__":
main()
|