namish10 commited on
Commit
b37e8f2
·
verified ·
1 Parent(s): 259e5e3

Upload index.html with huggingface_hub

Browse files
Files changed (1) hide show
  1. index.html +264 -157
index.html CHANGED
@@ -1,157 +1,264 @@
1
-
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
- <title>ContextFlow OpenEnv</title>
6
- <meta name="viewport" content="width=device-width, initial-scale=1">
7
- <style>
8
- body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; background: #f5f5f5; }
9
- .card { background: white; padding: 20px; border-radius: 10px; margin: 10px 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
10
- h1 { color: #333; text-align: center; }
11
- h2 { color: #666; border-bottom: 2px solid #007bff; padding-bottom: 10px; }
12
- button { background: #007bff; color: white; border: none; padding: 12px 24px; border-radius: 5px; cursor: pointer; font-size: 16px; margin: 5px; }
13
- button:hover { background: #0056b3; }
14
- button:disabled { background: #ccc; cursor: not-allowed; }
15
- input, select { padding: 10px; border: 1px solid #ddd; border-radius: 5px; margin: 5px; }
16
- .result { background: #e9ecef; padding: 15px; border-radius: 5px; margin: 10px 0; font-family: monospace; white-space: pre-wrap; }
17
- .success { color: green; }
18
- .error { color: red; }
19
- .metric { display: inline-block; background: #007bff; color: white; padding: 5px 15px; border-radius: 20px; margin: 5px; }
20
- </style>
21
- </head>
22
- <body>
23
- <h1>ContextFlow OpenEnv</h1>
24
- <p style="text-align:center;color:#666;">Learning Confusion Prediction Environment</p>
25
-
26
- <div class="card">
27
- <h2>Setup</h2>
28
- <select id="difficulty">
29
- <option value="easy">Easy</option>
30
- <option value="medium" selected>Medium</option>
31
- <option value="hard">Hard</option>
32
- </select>
33
- <button onclick="reset()">Reset Environment</button>
34
- <div id="status" class="result"></div>
35
- </div>
36
-
37
- <div class="card">
38
- <h2>Predict Confusion</h2>
39
- <p>Predicted Confusion (0-1): <input type="range" id="confusion" min="0" max="1" step="0.1" value="0.5" oninput="updateConfusion()"> <span id="confusionValue">0.5</span></p>
40
- <p>Intervention:
41
- <select id="intervention">
42
- <option value="">None</option>
43
- <option value="hint">Hint</option>
44
- <option value="simplify">Simplify</option>
45
- <option value="breakdown">Breakdown</option>
46
- <option value="example">Example</option>
47
- <option value="scaffold">Scaffold</option>
48
- </select>
49
- </p>
50
- <button id="stepBtn" onclick="step()" disabled>Step</button>
51
- <div id="result" class="result"></div>
52
- </div>
53
-
54
- <div class="card">
55
- <h2>Episode Summary</h2>
56
- <div id="metrics"></div>
57
- <div id="finalResult" class="result"></div>
58
- </div>
59
-
60
- <script>
61
- let episodeId = null;
62
- let stepCount = 0;
63
-
64
- const API_BASE = window.location.origin;
65
-
66
- function updateConfusion() {
67
- document.getElementById('confusionValue').textContent = document.getElementById('confusion').value;
68
- }
69
-
70
- async function reset() {
71
- const difficulty = document.getElementById('difficulty').value;
72
- document.getElementById('status').textContent = 'Resetting...';
73
-
74
- try {
75
- const response = await fetch(API_BASE + '/reset?difficulty=' + difficulty, { method: 'POST' });
76
- const data = await response.json();
77
-
78
- episodeId = data.episode_id;
79
- stepCount = 0;
80
-
81
- const obs = data.observation;
82
- document.getElementById('status').innerHTML =
83
- '<span class="success">Episode started!</span>\n' +
84
- 'Episode ID: ' + episodeId.substring(0, 8) + '...\n' +
85
- 'Difficulty: ' + obs.learning_context.difficulty + '\n' +
86
- 'Multi-modal fused: ' + obs.multimodal_fused + '\n' +
87
- 'Available interventions: ' + obs.available_interventions.join(', ');
88
-
89
- document.getElementById('stepBtn').disabled = false;
90
- document.getElementById('result').textContent = '';
91
- document.getElementById('finalResult').textContent = '';
92
- document.getElementById('metrics').innerHTML = '';
93
- } catch (e) {
94
- document.getElementById('status').innerHTML = '<span class="error">Error: ' + e.message + '</span>';
95
- }
96
- }
97
-
98
- async function step() {
99
- if (!episodeId) return;
100
-
101
- const confusion = document.getElementById('confusion').value;
102
- const intervention = document.getElementById('intervention').value;
103
-
104
- try {
105
- const response = await fetch(API_BASE + '/step', {
106
- method: 'POST',
107
- headers: { 'Content-Type': 'application/json' },
108
- body: JSON.stringify({
109
- episode_id: episodeId,
110
- action_type: intervention ? 'trigger_intervention' : 'predict_confusion',
111
- predicted_confusion: parseFloat(confusion),
112
- intervention_type: intervention || null,
113
- intervention_intensity: intervention ? 0.7 : null
114
- })
115
- });
116
-
117
- const data = await response.json();
118
- stepCount++;
119
-
120
- if (data.error) {
121
- document.getElementById('result').innerHTML = '<span class="error">' + data.error + '</span>';
122
- return;
123
- }
124
-
125
- const obs = data.observation;
126
- const reward = data.reward;
127
-
128
- document.getElementById('result').innerHTML =
129
- 'Step ' + stepCount + ':\n' +
130
- 'Reward: ' + reward.total.toFixed(3) + '\n' +
131
- 'Ground Truth: ' + reward.metadata.ground_truth.toFixed(2) + '\n' +
132
- 'Prediction Error: ' + reward.metadata.prediction_error.toFixed(2);
133
-
134
- if (data.done) {
135
- document.getElementById('stepBtn').disabled = true;
136
- const grader = data.info.grader_result;
137
- document.getElementById('finalResult').innerHTML =
138
- '<span class="' + (grader.passed ? 'success' : 'error') + '">' +
139
- (grader.passed ? 'PASSED' : 'FAILED') + '</span>\n' +
140
- 'Score: ' + grader.score.toFixed(3) + '\n\n' +
141
- grader.feedback;
142
-
143
- document.getElementById('metrics').innerHTML =
144
- '<span class="metric">MAE: ' + grader.metrics.mae.toFixed(3) + '</span>' +
145
- '<span class="metric">Early Detection: ' + (grader.metrics.early_detection_rate * 100).toFixed(0) + '%</span>' +
146
- '<span class="metric">Interventions: ' + grader.metrics.total_interventions + '</span>';
147
- }
148
- } catch (e) {
149
- document.getElementById('result').innerHTML = '<span class="error">Error: ' + e.message + '</span>';
150
- }
151
- }
152
-
153
- // Auto-reset on load
154
- window.onload = reset;
155
- </script>
156
- </body>
157
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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>