Spaces:
Running
Running
Upload index.html with huggingface_hub
Browse files- index.html +264 -157
index.html
CHANGED
|
@@ -1,157 +1,264 @@
|
|
| 1 |
-
|
| 2 |
-
<
|
| 3 |
-
<
|
| 4 |
-
<
|
| 5 |
-
<
|
| 6 |
-
<
|
| 7 |
-
|
| 8 |
-
body { font-family:
|
| 9 |
-
.
|
| 10 |
-
h1 { color: #
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>ContextFlow OpenEnv</title>
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<style>
|
| 7 |
+
* { box-sizing: border-box; }
|
| 8 |
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 1000px; margin: 0 auto; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); min-height: 100vh; }
|
| 9 |
+
.container { background: white; border-radius: 20px; padding: 30px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
|
| 10 |
+
h1 { color: #667eea; text-align: center; margin-bottom: 5px; }
|
| 11 |
+
.subtitle { text-align: center; color: #888; margin-bottom: 30px; }
|
| 12 |
+
h2 { color: #333; border-bottom: 3px solid #667eea; padding-bottom: 10px; margin-top: 30px; }
|
| 13 |
+
.card { background: #f8f9fa; padding: 20px; border-radius: 15px; margin: 15px 0; }
|
| 14 |
+
.controls { display: flex; gap: 15px; flex-wrap: wrap; align-items: center; margin: 15px 0; }
|
| 15 |
+
button { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; padding: 15px 30px; border-radius: 10px; cursor: pointer; font-size: 16px; font-weight: bold; transition: transform 0.2s, box-shadow 0.2s; }
|
| 16 |
+
button:hover { transform: translateY(-2px); box-shadow: 0 5px 20px rgba(102,126,234,0.4); }
|
| 17 |
+
button:disabled { background: #ccc; cursor: not-allowed; transform: none; }
|
| 18 |
+
select, input[type="range"] { padding: 12px 15px; border: 2px solid #e0e0e0; border-radius: 10px; font-size: 16px; }
|
| 19 |
+
.result { background: #1a1a2e; color: #0f0; padding: 20px; border-radius: 10px; margin: 15px 0; font-family: 'Courier New', monospace; font-size: 14px; line-height: 1.6; max-height: 400px; overflow-y: auto; white-space: pre-wrap; word-wrap: break-word; }
|
| 20 |
+
.metrics { display: flex; gap: 10px; flex-wrap: wrap; margin: 15px 0; }
|
| 21 |
+
.metric { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 10px 20px; border-radius: 25px; font-weight: bold; }
|
| 22 |
+
.score { font-size: 48px; font-weight: bold; text-align: center; }
|
| 23 |
+
.pass { color: #10b981; }
|
| 24 |
+
.fail { color: #ef4444; }
|
| 25 |
+
.agent-info { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin: 15px 0; }
|
| 26 |
+
.agent-card { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 15px; border-radius: 10px; text-align: center; }
|
| 27 |
+
.agent-card h3 { margin: 0 0 5px 0; font-size: 14px; }
|
| 28 |
+
.agent-card p { margin: 0; font-size: 24px; font-weight: bold; }
|
| 29 |
+
.status { text-align: center; padding: 10px; border-radius: 10px; margin: 10px 0; font-weight: bold; }
|
| 30 |
+
.status.ready { background: #d4edda; color: #155724; }
|
| 31 |
+
.status.error { background: #f8d7da; color: #721c24; }
|
| 32 |
+
</style>
|
| 33 |
+
</head>
|
| 34 |
+
<body>
|
| 35 |
+
<div class="container">
|
| 36 |
+
<h1>ContextFlow OpenEnv</h1>
|
| 37 |
+
<p class="subtitle">Learning Confusion Prediction Environment</p>
|
| 38 |
+
|
| 39 |
+
<div id="status" class="status ready">Click "Reset Environment" to start</div>
|
| 40 |
+
|
| 41 |
+
<div class="card">
|
| 42 |
+
<h2>Environment Setup</h2>
|
| 43 |
+
<div class="controls">
|
| 44 |
+
<select id="difficulty">
|
| 45 |
+
<option value="easy">Easy (50 steps)</option>
|
| 46 |
+
<option value="medium" selected>Medium (75 steps)</option>
|
| 47 |
+
<option value="hard">Hard (100 steps)</option>
|
| 48 |
+
</select>
|
| 49 |
+
<button onclick="reset()">Reset Environment</button>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<div class="card">
|
| 54 |
+
<h2>Make Prediction</h2>
|
| 55 |
+
<div class="controls">
|
| 56 |
+
<label>Predicted Confusion:</label>
|
| 57 |
+
<input type="range" id="confusion" min="0" max="1" step="0.05" value="0.5">
|
| 58 |
+
<span id="confusionValue" style="font-size:24px;font-weight:bold;color:#667eea;">0.50</span>
|
| 59 |
+
</div>
|
| 60 |
+
<div class="controls">
|
| 61 |
+
<label>Intervention:</label>
|
| 62 |
+
<select id="intervention">
|
| 63 |
+
<option value="">None</option>
|
| 64 |
+
<option value="hint">Hint</option>
|
| 65 |
+
<option value="simplify">Simplify</option>
|
| 66 |
+
<option value="breakdown">Breakdown</option>
|
| 67 |
+
<option value="example">Example</option>
|
| 68 |
+
<option value="scaffold">Scaffold</option>
|
| 69 |
+
<option value="peer_connect">Peer Connect</option>
|
| 70 |
+
<option value="break">Break</option>
|
| 71 |
+
<option value="encourage">Encourage</option>
|
| 72 |
+
</select>
|
| 73 |
+
</div>
|
| 74 |
+
<button id="stepBtn" onclick="step()" disabled>Step</button>
|
| 75 |
+
</div>
|
| 76 |
+
|
| 77 |
+
<div class="card">
|
| 78 |
+
<h2>Results</h2>
|
| 79 |
+
<div id="result" class="result">Waiting for environment...</div>
|
| 80 |
+
</div>
|
| 81 |
+
|
| 82 |
+
<div class="card">
|
| 83 |
+
<h2>Metrics</h2>
|
| 84 |
+
<div class="metrics" id="metrics"></div>
|
| 85 |
+
</div>
|
| 86 |
+
|
| 87 |
+
<div class="card">
|
| 88 |
+
<h2>Active Agents</h2>
|
| 89 |
+
<div class="agent-info">
|
| 90 |
+
<div class="agent-card">
|
| 91 |
+
<h3>RL Predictor</h3>
|
| 92 |
+
<p>Q-Learning</p>
|
| 93 |
+
</div>
|
| 94 |
+
<div class="agent-card">
|
| 95 |
+
<h3>Knowledge Graph</h3>
|
| 96 |
+
<p>Prerequisites</p>
|
| 97 |
+
</div>
|
| 98 |
+
<div class="agent-card">
|
| 99 |
+
<h3>Peer Learning</h3>
|
| 100 |
+
<p>Connect Learners</p>
|
| 101 |
+
</div>
|
| 102 |
+
<div class="agent-card">
|
| 103 |
+
<h3>Recall System</h3>
|
| 104 |
+
<p>Spaced Repetition</p>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
</div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<script>
|
| 111 |
+
let episodeId = null;
|
| 112 |
+
let stepCount = 0;
|
| 113 |
+
let episodeReward = 0;
|
| 114 |
+
|
| 115 |
+
const confusionSlider = document.getElementById('confusion');
|
| 116 |
+
const confusionValue = document.getElementById('confusionValue');
|
| 117 |
+
const statusEl = document.getElementById('status');
|
| 118 |
+
const resultEl = document.getElementById('result');
|
| 119 |
+
const metricsEl = document.getElementById('metrics');
|
| 120 |
+
const stepBtn = document.getElementById('stepBtn');
|
| 121 |
+
|
| 122 |
+
confusionSlider.oninput = () => {
|
| 123 |
+
confusionValue.textContent = parseFloat(confusionSlider.value).toFixed(2);
|
| 124 |
+
};
|
| 125 |
+
|
| 126 |
+
const state = {
|
| 127 |
+
step_count: 0,
|
| 128 |
+
max_steps: 75,
|
| 129 |
+
predictions: [],
|
| 130 |
+
interventions: [],
|
| 131 |
+
rewards: [],
|
| 132 |
+
ground_truth: [],
|
| 133 |
+
multimodal_fused: true,
|
| 134 |
+
agent_epsilon: 1.0
|
| 135 |
+
};
|
| 136 |
+
|
| 137 |
+
function generateConfusion(step, difficulty) {
|
| 138 |
+
const configs = {
|
| 139 |
+
easy: { base: 0.3, noise: 0.1, spikeProb: 0.08 },
|
| 140 |
+
medium: { base: 0.5, noise: 0.2, spikeProb: 0.12 },
|
| 141 |
+
hard: { base: 0.6, noise: 0.3, spikeProb: 0.15 }
|
| 142 |
+
};
|
| 143 |
+
const cfg = configs[difficulty] || configs.medium;
|
| 144 |
+
let confusion = cfg.base + Math.sin(step * 0.1) * 0.2;
|
| 145 |
+
confusion += (Math.random() - 0.5) * 2 * cfg.noise;
|
| 146 |
+
if (Math.random() < cfg.spikeProb) confusion += 0.3;
|
| 147 |
+
return Math.max(0, Math.min(1, confusion));
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
function reset() {
|
| 151 |
+
const difficulty = document.getElementById('difficulty').value;
|
| 152 |
+
state.step_count = 0;
|
| 153 |
+
state.max_steps = difficulty === 'easy' ? 50 : difficulty === 'hard' ? 100 : 75;
|
| 154 |
+
state.predictions = [];
|
| 155 |
+
state.interventions = [];
|
| 156 |
+
state.rewards = [];
|
| 157 |
+
state.ground_truth = [];
|
| 158 |
+
state.agent_epsilon = 1.0;
|
| 159 |
+
state.multimodal_fused = true;
|
| 160 |
+
stepCount = 0;
|
| 161 |
+
episodeReward = 0;
|
| 162 |
+
episodeId = 'ep_' + Date.now();
|
| 163 |
+
|
| 164 |
+
const gt = generateConfusion(0, difficulty);
|
| 165 |
+
state.ground_truth.push(gt);
|
| 166 |
+
|
| 167 |
+
statusEl.className = 'status ready';
|
| 168 |
+
statusEl.textContent = `Episode: ${episodeId.slice(0,12)}... | Difficulty: ${difficulty} | Steps: 0/${state.max_steps}`;
|
| 169 |
+
|
| 170 |
+
resultEl.innerHTML = JSON.stringify({
|
| 171 |
+
"Episode Started": {
|
| 172 |
+
episode_id: episodeId,
|
| 173 |
+
difficulty: difficulty,
|
| 174 |
+
multimodal_fused: state.multimodal_fused,
|
| 175 |
+
available_interventions: ["hint", "simplify", "breakdown", "example", "scaffold", "peer_connect", "break", "encourage"],
|
| 176 |
+
prediction_window: difficulty === 'easy' ? 3 : difficulty === 'hard' ? 7 : 5,
|
| 177 |
+
ground_truth_confusion: gt.toFixed(3),
|
| 178 |
+
agent_state: { epsilon: state.agent_epsilon.toFixed(3) }
|
| 179 |
+
}
|
| 180 |
+
}, null, 2);
|
| 181 |
+
|
| 182 |
+
metricsEl.innerHTML = '';
|
| 183 |
+
stepBtn.disabled = false;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
function step() {
|
| 187 |
+
const predicted = parseFloat(confusionSlider.value);
|
| 188 |
+
const intervention = document.getElementById('intervention').value;
|
| 189 |
+
|
| 190 |
+
state.step_count++;
|
| 191 |
+
stepCount++;
|
| 192 |
+
|
| 193 |
+
const gt = state.ground_truth[state.ground_truth.length - 1];
|
| 194 |
+
const error = Math.abs(predicted - gt);
|
| 195 |
+
let reward = (1 - error) * 0.4;
|
| 196 |
+
|
| 197 |
+
if (state.ground_truth.length > 1) {
|
| 198 |
+
const prev = state.ground_truth[state.ground_truth.length - 2];
|
| 199 |
+
if (gt > prev && predicted > prev) reward += 0.2;
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
if (intervention) {
|
| 203 |
+
state.interventions.push({ step: stepCount, type: intervention, intensity: 0.7 });
|
| 204 |
+
if (gt > 0.5) reward += 0.3;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
episodeReward += reward;
|
| 208 |
+
state.rewards.push(reward);
|
| 209 |
+
state.predictions.push(predicted);
|
| 210 |
+
|
| 211 |
+
const nextGt = generateConfusion(state.step_count, document.getElementById('difficulty').value);
|
| 212 |
+
state.ground_truth.push(nextGt);
|
| 213 |
+
state.agent_epsilon = Math.max(0.01, state.agent_epsilon * 0.995);
|
| 214 |
+
|
| 215 |
+
const done = stepCount >= state.max_steps;
|
| 216 |
+
|
| 217 |
+
if (done) {
|
| 218 |
+
const preds = state.predictions;
|
| 219 |
+
const gts = state.ground_truth.slice(0, preds.length);
|
| 220 |
+
const mae = preds.reduce((sum, p, i) => sum + Math.abs(p - gts[i]), 0) / preds.length;
|
| 221 |
+
let spikes = 0, detected = 0;
|
| 222 |
+
for (let i = 1; i < gts.length; i++) {
|
| 223 |
+
if (gts[i] > 0.6) { spikes++; if (preds[i] > 0.6) detected++; }
|
| 224 |
+
}
|
| 225 |
+
const edr = spikes > 0 ? detected / spikes : 0;
|
| 226 |
+
const ie = state.interventions.length > 0 ? state.interventions.length / preds.length : 0;
|
| 227 |
+
const score = (1 - mae) * 0.4 + edr * 0.3 + ie * 0.3;
|
| 228 |
+
const threshold = document.getElementById('difficulty').value === 'easy' ? 0.5 : document.getElementById('difficulty').value === 'hard' ? 0.7 : 0.6;
|
| 229 |
+
const passed = score >= threshold;
|
| 230 |
+
|
| 231 |
+
resultEl.innerHTML = JSON.stringify({
|
| 232 |
+
"Episode Complete": {
|
| 233 |
+
step: stepCount,
|
| 234 |
+
total_reward: episodeReward.toFixed(3),
|
| 235 |
+
grader_result: {
|
| 236 |
+
score: score.toFixed(3),
|
| 237 |
+
passed: passed,
|
| 238 |
+
feedback: `MAE: ${mae.toFixed(3)} | Early Detection: ${(edr*100).toFixed(0)}% | Intervention Effect: ${(ie*100).toFixed(0)}%`,
|
| 239 |
+
metrics: { mae: mae.toFixed(3), early_detection_rate: edr.toFixed(3), intervention_effectiveness: ie.toFixed(3), total_predictions: preds.length, total_interventions: state.interventions.length }
|
| 240 |
+
}
|
| 241 |
+
}
|
| 242 |
+
}, null, 2);
|
| 243 |
+
|
| 244 |
+
metricsEl.innerHTML = `<div class="metric" style="font-size:36px;">${passed ? 'PASSED' : 'FAILED'}</div><div class="metric">Score: ${score.toFixed(3)}</div><div class="metric">MAE: ${mae.toFixed(3)}</div><div class="metric">E.D.R: ${(edr*100).toFixed(0)}%</div><div class="metric">Reward: ${episodeReward.toFixed(2)}</div>`;
|
| 245 |
+
stepBtn.disabled = true;
|
| 246 |
+
statusEl.textContent = `${passed ? 'PASSED' : 'FAILED'} - Click Reset to try again`;
|
| 247 |
+
} else {
|
| 248 |
+
resultEl.innerHTML = JSON.stringify({
|
| 249 |
+
step: stepCount,
|
| 250 |
+
reward: reward.toFixed(3),
|
| 251 |
+
ground_truth: gt.toFixed(3),
|
| 252 |
+
prediction_error: error.toFixed(3),
|
| 253 |
+
prediction: predicted.toFixed(2),
|
| 254 |
+
intervention: intervention || null,
|
| 255 |
+
agent_state: { epsilon: state.agent_epsilon.toFixed(3) }
|
| 256 |
+
}, null, 2);
|
| 257 |
+
statusEl.textContent = `Episode: ${episodeId.slice(0,12)}... | Steps: ${stepCount}/${state.max_steps} | Reward: ${episodeReward.toFixed(2)}`;
|
| 258 |
+
}
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
window.onload = reset;
|
| 262 |
+
</script>
|
| 263 |
+
</body>
|
| 264 |
+
</html>
|