namish10 commited on
Commit
41db8ed
Β·
verified Β·
1 Parent(s): ced8871

Upload ARCHITECTURE.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. ARCHITECTURE.md +1029 -0
ARCHITECTURE.md ADDED
@@ -0,0 +1,1029 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ContextFlow Architecture: Complete System Overview
2
+
3
+ ## Table of Contents
4
+ 1. [System Vision](#1-system-vision)
5
+ 2. [High-Level Architecture](#2-high-level-architecture)
6
+ 3. [Frontend Layer](#3-frontend-layer)
7
+ 4. [Backend Layer](#4-backend-layer)
8
+ 5. [Agent Network](#5-agent-network)
9
+ 6. [Reinforcement Learning Pipeline](#6-reinforcement-learning-pipeline)
10
+ 7. [Data Flow](#7-data-flow)
11
+ 8. [API Design](#8-api-design)
12
+ 9. [Multi-Modal Detection](#9-multi-modal-detection)
13
+ 10. [Privacy & Security](#10-privacy--security)
14
+ 11. [Deployment Architecture](#11-deployment-architecture)
15
+
16
+ ---
17
+
18
+ ## 1. System Vision
19
+
20
+ **ContextFlow** is an AI-powered learning intelligence engine that predicts when learners will get confused BEFORE it happens, enabling proactive intervention in educational settings.
21
+
22
+ ### Core Problem Solved
23
+ - Traditional learning systems are **reactive** - they respond after confusion occurs
24
+ - ContextFlow is **proactive** - it predicts confusion and intervenes before disengagement
25
+
26
+ ### Key Innovations
27
+ 1. **Predictive AI** - RL-based doubt prediction
28
+ 2. **Gesture Control** - Hands-free learning assistance
29
+ 3. **Multi-Agent Orchestration** - 9 specialized agents working in concert
30
+ 4. **Privacy-First** - Face blur for classroom deployment
31
+
32
+ ---
33
+
34
+ ## 2. High-Level Architecture
35
+
36
+ ```
37
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
38
+ β”‚ USERS β”‚
39
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
40
+ β”‚ β”‚ Students β”‚ β”‚ Teachers β”‚ β”‚ Researchers β”‚ β”‚
41
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚
42
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
43
+ β”‚ β”‚ β”‚
44
+ β–Ό β–Ό β–Ό
45
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
46
+ β”‚ PRESENTATION LAYER β”‚
47
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
48
+ β”‚ β”‚ React Frontend (Vite) β”‚ β”‚
49
+ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
50
+ β”‚ β”‚ β”‚ Learn β”‚ β”‚ LLMFlow β”‚ β”‚Gestures β”‚ β”‚ Predict β”‚ ... β”‚ β”‚
51
+ β”‚ β”‚ β”‚ Tab β”‚ β”‚ Tab β”‚ β”‚ Tab β”‚ β”‚ Tab β”‚ β”‚ β”‚
52
+ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
53
+ β”‚ β”‚ β”‚ β”‚
54
+ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
55
+ β”‚ β”‚ β”‚ MediaPipe Camera Feed (Gesture + Face) β”‚ β”‚ β”‚
56
+ β”‚ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚
57
+ β”‚ β”‚ β”‚ β”‚ Hand β”‚ β”‚ Face β”‚ β”‚ β”‚ β”‚
58
+ β”‚ β”‚ β”‚ β”‚ Detection β”‚ β”‚ Blur β”‚ β”‚ β”‚ β”‚
59
+ β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”‚
60
+ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
61
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
62
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
63
+ β”‚
64
+ β”‚ REST API (JSON)
65
+ β”‚ WebSocket (Optional)
66
+ β–Ό
67
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€οΏ½οΏ½β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
68
+ β”‚ BACKEND LAYER (Flask) β”‚
69
+ β”‚ β”‚
70
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
71
+ β”‚ β”‚ API Gateway (Flask Blueprints) β”‚ β”‚
72
+ β”‚ β”‚ /api/session/* /api/predict/* /api/gesture/* /api/* β”‚ β”‚
73
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
74
+ β”‚ β”‚ β”‚
75
+ β”‚ β–Ό β”‚
76
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
77
+ β”‚ β”‚ STUDY ORCHESTRATOR (Central Coordinator) β”‚ β”‚
78
+ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
79
+ β”‚ β”‚ β”‚ Agent Registry β”‚ β”‚ β”‚
80
+ β”‚ β”‚ β”‚ DoubtPredictor β”‚ Behavioral β”‚ Gesture β”‚ Recall β”‚ β”‚ β”‚
81
+ β”‚ β”‚ β”‚ KnowledgeGraph β”‚ PeerLearn β”‚ LLMOrch β”‚ Prompt β”‚ β”‚ β”‚
82
+ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
83
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
84
+ β”‚ β”‚ β”‚
85
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
86
+ β”‚ β–Ό β–Ό β–Ό β–Ό β–Ό β”‚
87
+ β”‚ β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β” β”‚
88
+ β”‚ β”‚ Q- β”‚ β”‚Behavioralβ”‚ β”‚Gestureβ”‚ β”‚Recallβ”‚ β”‚LLM β”‚ β”‚
89
+ β”‚ β”‚Networkβ”‚ β”‚Agent β”‚ β”‚Agent β”‚ β”‚Agent β”‚ β”‚Orch β”‚ β”‚
90
+ β”‚ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”˜ β”‚
91
+ β”‚ β”‚
92
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
93
+ β”‚
94
+ β–Ό
95
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
96
+ β”‚ DATA LAYER β”‚
97
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
98
+ β”‚ β”‚ Checkpoint β”‚ β”‚ Session β”‚ β”‚ Knowledge β”‚ β”‚ Real β”‚ β”‚
99
+ β”‚ β”‚ (RL Model) β”‚ β”‚ State β”‚ β”‚ Graph β”‚ β”‚ Data β”‚ β”‚
100
+ β”‚ β”‚ .pkl β”‚ β”‚ JSON β”‚ β”‚ NetworkX β”‚ β”‚ Collectionβ”‚ β”‚
101
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
102
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 3. Frontend Layer
108
+
109
+ ### 3.1 Technology Stack
110
+
111
+ | Component | Technology | Purpose |
112
+ |-----------|------------|---------|
113
+ | Framework | React 18 | UI Components |
114
+ | Build Tool | Vite | Fast development |
115
+ | Styling | Tailwind CSS | Responsive design |
116
+ | Icons | Lucide React | Consistent icons |
117
+ | Camera | MediaPipe | Hand/Face detection |
118
+
119
+ ### 3.2 Application Structure
120
+
121
+ ```
122
+ frontend/src/
123
+ β”œβ”€β”€ App.jsx # Main application (9 tabs)
124
+ β”œβ”€β”€ main.jsx # Entry point
125
+ β”œβ”€β”€ index.css # Global styles
126
+ β”œβ”€β”€ BrowserLLMLauncher.js # AI chat launcher
127
+ └── MediaPipeProcessor.js # Camera + gesture processing
128
+ ```
129
+
130
+ ### 3.3 Tab Interface
131
+
132
+ | Tab | Purpose |
133
+ |-----|---------|
134
+ | **Learn** | Dashboard with predictions, reviews, gamification |
135
+ | **LLM Flow** | Browser-based AI launcher (no API keys) |
136
+ | **Gestures** | Train custom hand gestures |
137
+ | **Predict** | RL doubt prediction visualization |
138
+ | **Behavior** | Behavioral signal tracking |
139
+ | **Peer** | Social learning insights |
140
+ | **Stats** | Learning statistics |
141
+ | **Gamify** | Fish/XP rewards system |
142
+ | **Settings** | AI provider configuration |
143
+
144
+ ### 3.4 BrowserLLMLauncher.js
145
+
146
+ Opens AI chats directly in browser without API keys:
147
+
148
+ ```javascript
149
+ // Opens chat.openai.com with pre-filled context
150
+ openAIChat(context, model = 'gpt-4') {
151
+ const url = `https://chat.openai.com/?q=${encodeURIComponent(context)}`;
152
+ window.open(url, '_blank');
153
+ }
154
+ ```
155
+
156
+ ### 3.5 MediaPipeProcessor.js
157
+
158
+ Handles real-time camera processing:
159
+
160
+ ```
161
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
162
+ β”‚ Camera Feed β”‚
163
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
164
+ β”‚
165
+ β–Ό
166
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
167
+ β”‚ Hand Landmark β”‚ β”‚ Face Mesh β”‚
168
+ β”‚ Detection β”‚ β”‚ Detection β”‚
169
+ β”‚ (21 points) β”‚ β”‚ (468 points) β”‚
170
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
171
+ β”‚ β”‚
172
+ β–Ό β–Ό
173
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
174
+ β”‚ Gesture β”‚ β”‚ Face Blur β”‚
175
+ β”‚ Recognition │───▢│ (Privacy) β”‚
176
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
177
+ β”‚
178
+ β–Ό
179
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
180
+ β”‚ Backend API β”‚
181
+ β”‚ /api/gesture/ β”‚
182
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
183
+ ```
184
+
185
+ ---
186
+
187
+ ## 4. Backend Layer
188
+
189
+ ### 4.1 Technology Stack
190
+
191
+ | Component | Technology | Purpose |
192
+ |-----------|------------|---------|
193
+ | Framework | Flask | REST API |
194
+ | Async | asyncio | Non-blocking I/O |
195
+ | ML | PyTorch | RL model |
196
+ | Data | NumPy | Feature extraction |
197
+ | Graphs | NetworkX | Knowledge graphs |
198
+ | Storage | JSON/SQLite | Session persistence |
199
+
200
+ ### 4.2 Flask Application Structure
201
+
202
+ ```
203
+ backend/
204
+ β”œβ”€β”€ run.py # Application entry point
205
+ β”œβ”€β”€ app/
206
+ β”‚ β”œβ”€β”€ __init__.py # Flask app factory
207
+ β”‚ β”œβ”€β”€ config.py # Configuration
208
+ β”‚ β”œβ”€β”€ api/
209
+ β”‚ β”‚ β”œβ”€β”€ __init__.py
210
+ β”‚ β”‚ └── main.py # All API routes (889 lines)
211
+ β”‚ └── agents/
212
+ β”‚ β”œβ”€β”€ __init__.py
213
+ β”‚ β”œβ”€β”€ study_orchestrator.py # Central coordinator
214
+ β”‚ β”œβ”€β”€ doubt_predictor.py # RL prediction
215
+ β”‚ β”œβ”€β”€ behavioral_agent.py # Signal processing
216
+ β”‚ β”œβ”€β”€ hand_gesture_agent.py # MediaPipe integration
217
+ β”‚ β”œβ”€β”€ recall_agent.py # Spaced repetition
218
+ β”‚ β”œβ”€β”€ knowledge_graph_agent.py # Concept mapping
219
+ β”‚ β”œβ”€β”€ peer_learning_agent.py # Social learning
220
+ β”‚ β”œβ”€β”€ llm_orchestrator_agent.py # Multi-AI
221
+ β”‚ β”œβ”€β”€ gesture_action_agent.py # Gestureβ†’Action
222
+ β”‚ └── prompt_agent.py # Prompt templates
223
+ ```
224
+
225
+ ### 4.3 Flask App Factory
226
+
227
+ ```python
228
+ def create_app():
229
+ app = Flask(__name__)
230
+
231
+ # Load config
232
+ app.config.from_object('app.config.Config')
233
+
234
+ # Register blueprints
235
+ from app.api.main import api
236
+ app.register_blueprint(api, url_prefix='/api')
237
+
238
+ # Initialize agents
239
+ init_agents()
240
+
241
+ return app
242
+ ```
243
+
244
+ ---
245
+
246
+ ## 5. Agent Network
247
+
248
+ ### 5.1 Agent Overview
249
+
250
+ ```
251
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
252
+ β”‚ STUDY ORCHESTRATOR β”‚
253
+ β”‚ (Central Coordinator) β”‚
254
+ β”‚ β”‚
255
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
256
+ β”‚ β”‚ Doubt β”‚ β”‚ Behavioral β”‚ β”‚ Hand β”‚ β”‚
257
+ β”‚ β”‚ Predictor │◀─│ Agent │─▢│ Gesture β”‚ β”‚
258
+ β”‚ β”‚ Agent β”‚ β”‚ β”‚ β”‚ Agent β”‚ β”‚
259
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚
260
+ β”‚ β”‚ β”‚ β”‚
261
+ β”‚ β–Ό β–Ό β”‚
262
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
263
+ β”‚ β”‚ Knowledge β”‚ β”‚ Recall β”‚ β”‚ LLM β”‚ β”‚
264
+ β”‚ β”‚ Graph │◀─│ Agent │─▢│ Orchestratorβ”‚ β”‚
265
+ β”‚ β”‚ Agent β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
266
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
267
+ β”‚ β”‚
268
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
269
+ β”‚ β”‚ Peer β”‚ β”‚ Gesture β”‚ β”‚
270
+ β”‚ β”‚ Learning β”‚ β”‚ Action β”‚ β”‚
271
+ β”‚ β”‚ Agent β”‚ β”‚ Mapper β”‚ β”‚
272
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
273
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
274
+ ```
275
+
276
+ ### 5.2 StudyOrchestrator (Central Coordinator)
277
+
278
+ The orchestrator manages the learning lifecycle:
279
+
280
+ ```python
281
+ class StudyOrchestrator:
282
+ def __init__(self, user_id: str):
283
+ self.user_id = user_id
284
+
285
+ # Initialize all agents
286
+ self.doubt_predictor = DoubtPredictorAgent(user_id)
287
+ self.behavioral_agent = BehavioralAgent(user_id)
288
+ self.gesture_agent = HandGestureAgent(user_id)
289
+ self.recall_agent = RecallAgent(user_id)
290
+ self.knowledge_graph = KnowledgeGraphAgent(user_id)
291
+ self.peer_agent = PeerLearningAgent(user_id)
292
+
293
+ # State management
294
+ self.state = OrchestratorState()
295
+ ```
296
+
297
+ **Session Lifecycle:**
298
+ 1. **PRE_LEARNING** - Load predictions, check recalls, get peer insights
299
+ 2. **ACTIVE_LEARNING** - Monitor signals, update predictions, capture doubts
300
+ 3. **REVIEW** - Trigger spaced repetition, update knowledge graph
301
+ 4. **POST_LEARNING** - Sync data, update gamification, generate summary
302
+
303
+ ### 5.3 DoubtPredictorAgent (RL Core)
304
+
305
+ Predicts confusion before it happens:
306
+
307
+ ```python
308
+ class DoubtPredictorAgent:
309
+ def __init__(self, user_id: str, config: dict = None):
310
+ self.user_id = user_id
311
+ self.model = self._load_checkpoint()
312
+ self.feature_extractor = FeatureExtractor()
313
+
314
+ def predict_doubts(self, context: dict, top_k: int = 5):
315
+ # 1. Extract 64-dim state vector
316
+ state = self.feature_extractor.extract_state(context)
317
+
318
+ # 2. Get Q-values from RL model
319
+ q_values = self.model.predict(state)
320
+
321
+ # 3. Return top-k predictions
322
+ return self._format_predictions(q_values, top_k)
323
+ ```
324
+
325
+ ### 5.4 BehavioralAgent
326
+
327
+ Processes raw behavioral signals:
328
+
329
+ ```python
330
+ class BehavioralSignal:
331
+ mouse_hesitation: float # Pause frequency
332
+ scroll_reversals: int # Back-and-forth
333
+ time_on_page: float # Seconds
334
+ eye_tracking: Tuple[float, float]
335
+ click_frequency: int
336
+
337
+ def calculate_confusion_score(self) -> float:
338
+ # Weighted average of signals
339
+ weights = {
340
+ 'hesitation': 0.3,
341
+ 'reversals': 0.25,
342
+ 'time_on_page': 0.2,
343
+ 'tab_switches': 0.15,
344
+ 'back_button': 0.1
345
+ }
346
+ return weighted_sum(signals, weights)
347
+ ```
348
+
349
+ ### 5.5 HandGestureAgent
350
+
351
+ MediaPipe integration for gesture recognition:
352
+
353
+ ```
354
+ Camera Frame
355
+ β”‚
356
+ β–Ό
357
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
358
+ β”‚ MediaPipe Hands β”‚
359
+ β”‚ (21 landmarks) β”‚
360
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
361
+ β”‚
362
+ β–Ό
363
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
364
+ β”‚ Gesture Templateβ”‚
365
+ β”‚ Matching β”‚
366
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
367
+ β”‚
368
+ β–Ό
369
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
370
+ β”‚ Confidence │──▢ Recognized Gesture
371
+ β”‚ Score (0-1) β”‚
372
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
373
+ ```
374
+
375
+ **Pre-built Gestures:**
376
+ | Gesture | Description |
377
+ |---------|-------------|
378
+ | pinch | Thumb + Index |
379
+ | swipe_up | 2-finger up |
380
+ | swipe_down | 2-finger down |
381
+ | swipe_right | 2-finger right |
382
+ | swipe_left | 2-finger left |
383
+ | point | Index extended |
384
+ | wave | Open palm wave |
385
+ | thumbs_up | πŸ‘ confirmation |
386
+ | thumbs_down | πŸ‘Ž rejection |
387
+ | fist | Closed hand |
388
+
389
+ ### 5.6 RecallAgent
390
+
391
+ SM-2 based spaced repetition:
392
+
393
+ ```python
394
+ class RecallCard:
395
+ front: str # Question
396
+ back: str # Answer
397
+ interval: int # Days until review
398
+ ease_factor: float # Difficulty (default 2.5)
399
+ repetitions: int # Successful reviews
400
+
401
+ def schedule_review(card: RecallCard, quality: int):
402
+ if quality >= 3: # Correct
403
+ if card.repetitions == 0:
404
+ card.interval = 1
405
+ elif card.repetitions == 1:
406
+ card.interval = 6
407
+ else:
408
+ card.interval *= card.ease_factor
409
+ card.repetitions += 1
410
+ else: # Incorrect
411
+ card.repetitions = 0
412
+ card.interval = 1
413
+
414
+ # Update ease factor
415
+ card.ease_factor += (0.1 - (5 - quality) * (0.08 + (5 - quality) * 0.02))
416
+ card.ease_factor = max(1.3, card.ease_factor)
417
+ ```
418
+
419
+ ### 5.7 KnowledgeGraphAgent
420
+
421
+ Concept mapping with NetworkX:
422
+
423
+ ```python
424
+ class KnowledgeGraphAgent:
425
+ def __init__(self, user_id: str):
426
+ self.graph = nx.MultiDiGraph()
427
+
428
+ def add_doubt_to_graph(self, doubt: dict):
429
+ # Create node
430
+ self.graph.add_node(
431
+ doubt['concept'],
432
+ type='concept',
433
+ topic=doubt['topic'],
434
+ timestamp=datetime.now()
435
+ )
436
+
437
+ # Connect to prerequisites
438
+ for prereq in doubt.get('prerequisites', []):
439
+ self.graph.add_edge(prereq, doubt['concept'], type='prerequisite')
440
+
441
+ # Connect to related concepts
442
+ for related in doubt.get('related', []):
443
+ self.graph.add_edge(doubt['concept'], related, type='related')
444
+
445
+ def find_learning_path(self, from_topic: str, to_topic: str):
446
+ try:
447
+ return nx.shortest_path(self.graph, from_topic, to_topic)
448
+ except nx.NetworkXNoPath:
449
+ return []
450
+ ```
451
+
452
+ ### 5.8 LLMOrchestrator
453
+
454
+ Multi-provider AI integration:
455
+
456
+ ```python
457
+ class LLMOrchestrator:
458
+ SUPPORTED_PROVIDERS = {
459
+ 'chatgpt': LLMProvider.CHATGPT,
460
+ 'gemini': LLMProvider.GEMINI,
461
+ 'claude': LLMProvider.CLAUDE,
462
+ 'deepseek': LLMProvider.DEEPSEEK,
463
+ 'ollama': LLMProvider.OLLAMA,
464
+ 'groq': LLMProvider.GROQ
465
+ }
466
+
467
+ async def query_parallel(self, request: LLMRequest):
468
+ tasks = []
469
+ for provider in request.providers:
470
+ task = self._query_provider(provider, request)
471
+ tasks.append(task)
472
+
473
+ # Execute all queries concurrently
474
+ responses = await asyncio.gather(*tasks, return_exceptions=True)
475
+ return [r for r in responses if not isinstance(r, Exception)]
476
+ ```
477
+
478
+ ### 5.9 GestureActionMapper
479
+
480
+ Maps gestures to system actions:
481
+
482
+ ```python
483
+ class GestureAction(Enum):
484
+ QUERY_MULTI_LLM = "query_multi_llm"
485
+ QUERY_CHATGPT = "query_chatgpt"
486
+ QUERY_GEMINI = "query_gemini"
487
+ TRIGGER_RL_LOOP = "trigger_rl_loop"
488
+ CAPTURE_CONTENT = "capture_content"
489
+ PAUSE_SESSION = "pause_session"
490
+ RESUME_SESSION = "resume_session"
491
+
492
+ class GestureActionMapper:
493
+ def __init__(self):
494
+ self.action_rules = {
495
+ GestureAction.QUERY_MULTI_LLM: {
496
+ "trigger": {"finger_count": 2, "swipe": "right"}
497
+ },
498
+ GestureAction.PAUSE_SESSION: {
499
+ "trigger": {"gesture": "open_palm"}
500
+ },
501
+ GestureAction.RESUME_SESSION: {
502
+ "trigger": {"gesture": "thumbs_up"}
503
+ }
504
+ }
505
+ ```
506
+
507
+ ### 5.10 PeerLearningAgent
508
+
509
+ Social learning insights:
510
+
511
+ ```python
512
+ class PeerLearningAgent:
513
+ def get_peer_insights(self, topic: str):
514
+ # Aggregate insights from "similar" students
515
+ insights = []
516
+
517
+ # Find students who learned this topic
518
+ similar_students = self._find_similar_students(topic)
519
+
520
+ for student in similar_students:
521
+ # What confused them?
522
+ insights.extend(student.difficult_concepts)
523
+
524
+ # Return aggregated insights
525
+ return self._aggregate_insights(insights)
526
+ ```
527
+
528
+ ---
529
+
530
+ ## 6. Reinforcement Learning Pipeline
531
+
532
+ ### 6.1 Problem Formulation
533
+
534
+ **State Space (64 dimensions):**
535
+ ```
536
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
537
+ β”‚ Topic Embedding (32) β”‚ Progress β”‚ Confusion (16) β”‚ Gesture (14) β”‚ Time β”‚
538
+ β”‚ TF-IDF of topic β”‚ 0.0-1.0 β”‚ Behavioral β”‚ Hand β”‚ 0-1 β”‚
539
+ β”‚ β”‚ β”‚ signals β”‚ signals β”‚ β”‚
540
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
541
+ ```
542
+
543
+ **Action Space (10 doubt types):**
544
+ 1. `what_is_backpropagation`
545
+ 2. `why_gradient_descent`
546
+ 3. `how_overfitting_works`
547
+ 4. `explain_regularization`
548
+ 5. `what_loss_function`
549
+ 6. `how_optimization_works`
550
+ 7. `explain_learning_rate`
551
+ 8. `what_regularization`
552
+ 9. `how_batch_norm_works`
553
+ 10. `explain_softmax`
554
+
555
+ **Reward Function:**
556
+ | Event | Reward |
557
+ |-------|--------|
558
+ | Correct prediction | +1.0 |
559
+ | Helpful explanation | +0.5 |
560
+ | Engagement maintained | +0.3 |
561
+ | False positive | -0.5 |
562
+ | Missed confusion | -1.0 |
563
+
564
+ ### 6.2 Q-Network Architecture
565
+
566
+ ```python
567
+ class QNetwork(nn.Module):
568
+ def __init__(self, state_dim=64, action_dim=10, hidden_dim=128):
569
+ super().__init__()
570
+ self.fc1 = nn.Linear(state_dim, hidden_dim) # 64 β†’ 128
571
+ self.fc2 = nn.Linear(hidden_dim, hidden_dim) # 128 β†’ 128
572
+ self.fc3 = nn.Linear(hidden_dim, action_dim) # 128 β†’ 10
573
+
574
+ def forward(self, x):
575
+ x = F.relu(self.fc1(x)) # ReLU activation
576
+ x = F.relu(self.fc2(x))
577
+ return self.fc3(x) # Q-values for each action
578
+ ```
579
+
580
+ ### 6.3 Training Algorithm (GRPO)
581
+
582
+ ```python
583
+ class DoubtPredictionRL:
584
+ def train(self, epochs=10, batch_size=32):
585
+ for epoch in range(epochs):
586
+ for batch in self.dataloader:
587
+ # 1. Get current Q-values
588
+ q_values = self.q_network(batch.states)
589
+
590
+ # 2. Compute targets (GRPO-style)
591
+ with torch.no_grad():
592
+ next_q = self.target_network(batch.next_states).max(1)[0]
593
+ targets = batch.rewards + self.gamma * next_q * (~batch.dones)
594
+
595
+ # 3. Compute loss and update
596
+ loss = self.loss_fn(q_values.gather(1, batch.actions), targets)
597
+ loss.backward()
598
+ self.optimizer.step()
599
+
600
+ # 4. Update target network
601
+ self.update_target_network()
602
+
603
+ # 5. Decay epsilon (exploration)
604
+ self.epsilon *= self.epsilon_decay
605
+ ```
606
+
607
+ ### 6.4 Feature Extraction
608
+
609
+ ```python
610
+ class FeatureExtractor:
611
+ STATE_DIM = 64
612
+
613
+ def extract_state(self, context: dict) -> np.ndarray:
614
+ # Topic embedding (32 dims)
615
+ topic_emb = self._extract_topic_embedding(context['topic'])
616
+
617
+ # Progress (1 dim)
618
+ progress = np.array([context['progress']])
619
+
620
+ # Confusion signals (16 dims)
621
+ confusion = self._extract_confusion_signals(context['confusion_signals'])
622
+
623
+ # Gesture signals (14 dims)
624
+ gestures = self._extract_gesture_signals(context['gesture_signals'])
625
+
626
+ # Time spent (1 dim)
627
+ time_spent = np.array([context['time_spent'] / 1800])
628
+
629
+ # Concatenate
630
+ return np.concatenate([topic_emb, progress, confusion, gestures, time_spent])
631
+ ```
632
+
633
+ ---
634
+
635
+ ## 7. Data Flow
636
+
637
+ ### 7.1 Learning Session Flow
638
+
639
+ ```
640
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
641
+ β”‚ USER STARTS SESSION β”‚
642
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
643
+ β”‚
644
+ β–Ό
645
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
646
+ β”‚ ORCHESTRATOR.START_SESSION() β”‚
647
+ β”‚ 1. Create new LearningSession β”‚
648
+ β”‚ 2. Load RL model checkpoint β”‚
649
+ β”‚ 3. Build learning context β”‚
650
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
651
+ β”‚
652
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
653
+ β–Ό β–Ό β–Ό
654
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
655
+ β”‚ Doubt β”‚ β”‚ Behavioralβ”‚ β”‚ Peer β”‚
656
+ β”‚ Predictor β”‚ β”‚ Agent β”‚ β”‚ Learning β”‚
657
+ β”‚ β”‚ β”‚ β”‚ β”‚ Agent β”‚
658
+ β”‚ Predict β”‚ β”‚ Analyze β”‚ β”‚ Get β”‚
659
+ β”‚ doubts β”‚ β”‚ signals β”‚ β”‚ insights β”‚
660
+ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
661
+ β”‚ β”‚ β”‚
662
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
663
+ β–Ό
664
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
665
+ β”‚ RETURN INITIAL PREDICTIONS β”‚
666
+ β”‚ - Top 5 predicted doubts β”‚
667
+ β”‚ - Pending reviews β”‚
668
+ β”‚ - Peer insights β”‚
669
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
670
+ ```
671
+
672
+ ### 7.2 Behavioral Signal Flow
673
+
674
+ ```
675
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
676
+ β”‚ REAL-TIME SIGNALS β”‚
677
+ β”‚ β”‚
678
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
679
+ β”‚ β”‚ Mouse β”‚ β”‚ Scroll β”‚ β”‚Gesture β”‚ β”‚ Time β”‚ β”‚
680
+ β”‚ β”‚Movement β”‚ β”‚ Pattern β”‚ β”‚Camera β”‚ β”‚ On β”‚ β”‚
681
+ β”‚ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β”‚
682
+ β””β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
683
+ β”‚ β”‚ β”‚ β”‚
684
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
685
+ β–Ό
686
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
687
+ β”‚ BEHAVIORAL AGENT β”‚
688
+ β”‚ β”‚
689
+ β”‚ calculate_confusion_ β”‚
690
+ β”‚ score(signals) β”‚
691
+ β”‚ β”‚
692
+ β”‚ Returns: 0.0 - 1.0 β”‚
693
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
694
+ β”‚
695
+ β–Ό
696
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
697
+ β”‚ DOUBT PREDICTOR β”‚
698
+ β”‚ β”‚
699
+ β”‚ If score > 0.5: β”‚
700
+ β”‚ Re-predict doubts β”‚
701
+ β”‚ Trigger interventionβ”‚
702
+ β”‚ β”‚
703
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
704
+ ```
705
+
706
+ ### 7.3 Gesture-to-Action Flow
707
+
708
+ ```
709
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
710
+ β”‚ CAMERA FRAME β”‚
711
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
712
+ β”‚
713
+ β–Ό
714
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
715
+ β”‚ MEDIAPIPE PROCESSING β”‚
716
+ β”‚ β”‚
717
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
718
+ β”‚ β”‚ Hand Landmark β”‚ β”‚ Face Mesh β”‚ β”‚
719
+ β”‚ β”‚ Detection β”‚ β”‚ (468 points) β”‚ β”‚
720
+ β”‚ β”‚ (21 points) β”‚ β”‚ β”‚ β”‚
721
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
722
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
723
+ β”‚ β”‚
724
+ β–Ό β–Ό
725
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
726
+ β”‚ GESTURE TEMPLATE β”‚ β”‚ FACE BLUR β”‚
727
+ β”‚ MATCHING β”‚ β”‚ (Privacy) β”‚
728
+ β”‚ β”‚ β”‚ β”‚
729
+ β”‚ Compare landmarks β”‚ β”‚ Blur regions with β”‚
730
+ β”‚ to known gestures β”‚ β”‚ facial keypoints β”‚
731
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
732
+ β”‚
733
+ β–Ό
734
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
735
+ β”‚ GESTURE RECOGNIZED │──▢ Backend /api/gesture/recognize
736
+ β”‚ β”‚
737
+ β”‚ { β”‚
738
+ β”‚ "gesture": "pinch",β”‚
739
+ β”‚ "confidence": 0.92β”‚
740
+ β”‚ } β”‚
741
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
742
+ β”‚
743
+ β–Ό
744
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
745
+ β”‚ GESTURE ACTION MAPPER β”‚
746
+ β”‚ β”‚
747
+ β”‚ pinch ──────────────▢│ TRIGGER_AI_HELP
748
+ β”‚ swipe_right ────────▢│ LAUNCH_BROWSER_CHAT
749
+ β”‚ open_palm ──────────▢│ PAUSE_SESSION
750
+ β”‚ thumbs_up ──────────▢│ MARK_UNDERSTOOD
751
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
752
+ ```
753
+
754
+ ---
755
+
756
+ ## 8. API Design
757
+
758
+ ### 8.1 API Structure
759
+
760
+ | Category | Endpoints |
761
+ |----------|-----------|
762
+ | Session | `/session/start`, `/session/update`, `/session/end`, `/session/insights` |
763
+ | Prediction | `/predict/doubts`, `/recommendations` |
764
+ | Behavior | `/behavior/track`, `/behavior/heatmap` |
765
+ | Graph | `/graph/add`, `/graph/query`, `/graph/path` |
766
+ | Review | `/review/due`, `/review/complete`, `/review/stats` |
767
+ | Peer | `/peer/insights`, `/peer/doubts`, `/peer/trending` |
768
+ | Gesture | `/gesture/list`, `/gesture/recognize`, `/gesture/training/*` |
769
+ | LLM | `/llm/query`, `/llm/gesture-action`, `/llm/rl/*` |
770
+
771
+ ### 8.2 Session API
772
+
773
+ ```python
774
+ # POST /api/session/start
775
+ {
776
+ "user_id": "student123",
777
+ "topic": "Machine Learning",
778
+ "subtopic": "Neural Networks"
779
+ }
780
+
781
+ # Response
782
+ {
783
+ "session_id": "session_1699999999.123",
784
+ "topic": "Machine Learning",
785
+ "predictions": [
786
+ {
787
+ "doubt": "how_overfitting_works",
788
+ "confidence": 0.85,
789
+ "explanation": "Student showing signs of confusion...",
790
+ "priority": 1
791
+ }
792
+ ],
793
+ "pending_reviews": 5,
794
+ "peer_insights_count": 3
795
+ }
796
+ ```
797
+
798
+ ### 8.3 Doubt Prediction API
799
+
800
+ ```python
801
+ # POST /api/predict/doubts
802
+ {
803
+ "context": {
804
+ "topic": "Neural Networks",
805
+ "progress": 0.5,
806
+ "confusion_signals": 0.7
807
+ }
808
+ }
809
+
810
+ # Response
811
+ {
812
+ "predictions": [
813
+ {
814
+ "doubt": "how_overfitting_works",
815
+ "confidence": 0.85,
816
+ "explanation": "...",
817
+ "priority": 1,
818
+ "estimated_time": "10 min",
819
+ "prerequisites": ["regularization", "bias-variance"]
820
+ }
821
+ ]
822
+ }
823
+ ```
824
+
825
+ ---
826
+
827
+ ## 9. Multi-Modal Detection
828
+
829
+ ### 9.1 Supported Modalities
830
+
831
+ ```
832
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
833
+ β”‚ MULTI-MODAL FUSION β”‚
834
+ β”‚ β”‚
835
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
836
+ β”‚ β”‚ Audio β”‚ β”‚ Biometric β”‚ β”‚ Behavioral β”‚ β”‚
837
+ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
838
+ β”‚ β”‚ Speech rate β”‚ β”‚ Heart rate β”‚ β”‚ Mouse moves β”‚ β”‚
839
+ β”‚ β”‚ Hesitations β”‚ β”‚ GSR β”‚ β”‚ Scroll β”‚ β”‚
840
+ β”‚ β”‚ Pauses β”‚ β”‚ Eye trackingβ”‚ β”‚ Key presses β”‚ β”‚
841
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β”‚
842
+ β”‚ β”‚ β”‚ β”‚ β”‚
843
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
844
+ β”‚ β–Ό β”‚
845
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
846
+ β”‚ β”‚ WEIGHTED FUSION β”‚ β”‚
847
+ β”‚ β”‚ β”‚ β”‚
848
+ β”‚ β”‚ audio_weight: 0.2 β”‚ β”‚
849
+ β”‚ β”‚ biometric_weight: 0.3 β”‚ β”‚
850
+ β”‚ β”‚ behavioral_weight: 0.5 β”‚ β”‚
851
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
852
+ β”‚ β”‚ β”‚
853
+ β”‚ β–Ό β”‚
854
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
855
+ β”‚ β”‚ UNIFIED CONFUSION β”‚ β”‚
856
+ β”‚ β”‚ SCORE β”‚ β”‚
857
+ β”‚ β”‚ 0.0 - 1.0 β”‚ β”‚
858
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
859
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
860
+ ```
861
+
862
+ ### 9.2 Feature Extraction by Modality
863
+
864
+ **Audio (7 features):**
865
+ - Speech rate (WPM)
866
+ - Pause frequency
867
+ - Pause duration
868
+ - Pitch variation
869
+ - Volume level
870
+ - Hesitation count
871
+ - Question markers
872
+
873
+ **Biometric (6 features):**
874
+ - Heart rate (BPM)
875
+ - Heart rate variability
876
+ - Skin conductance (GSR)
877
+ - Skin temperature
878
+ - Eye blink rate
879
+ - Eye open duration
880
+
881
+ **Behavioral (8 features):**
882
+ - Mouse hesitation
883
+ - Scroll reversals
884
+ - Time on page
885
+ - Click frequency
886
+ - Back button usage
887
+ - Tab switches
888
+ - Copy attempts
889
+ - Search usage
890
+
891
+ ---
892
+
893
+ ## 10. Privacy & Security
894
+
895
+ ### 10.1 Face Blur Implementation
896
+
897
+ ```python
898
+ class FaceBlurProcessor:
899
+ def __init__(self):
900
+ self.face_mesh = mp_face_mesh.FaceMesh(
901
+ static_image_mode=False,
902
+ max_num_faces=1,
903
+ refine_landmarks=True
904
+ )
905
+
906
+ def blur_face(self, frame):
907
+ # Detect face landmarks
908
+ results = self.face_mesh.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
909
+
910
+ if results.multi_face_landmarks:
911
+ # Get face region
912
+ face_region = self._get_face_region(frame, results)
913
+
914
+ # Apply Gaussian blur
915
+ blurred = cv2.GaussianBlur(face_region, (51, 51), 0)
916
+
917
+ # Replace face region
918
+ frame = self._replace_region(frame, blurred, results)
919
+
920
+ return frame
921
+ ```
922
+
923
+ ### 10.2 Data Privacy
924
+
925
+ | Data Type | Storage | Privacy |
926
+ |-----------|---------|---------|
927
+ | Video frames | None | Processed in-memory only |
928
+ | Face images | None | Auto-blurred |
929
+ | Hand landmarks | Optional | Anonymized |
930
+ | Session data | Local JSON | User-owned |
931
+ | Model weights | HuggingFace | Open |
932
+
933
+ ---
934
+
935
+ ## 11. Deployment Architecture
936
+
937
+ ### 11.1 Development Setup
938
+
939
+ ```
940
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
941
+ β”‚ DEVELOPMENT β”‚
942
+ β”‚ β”‚
943
+ β”‚ Terminal 1: Terminal 2: β”‚
944
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
945
+ β”‚ β”‚ cd backend β”‚ β”‚ cd frontend β”‚ β”‚
946
+ β”‚ β”‚ python run.py β”‚ β”‚ npm run dev β”‚ β”‚
947
+ β”‚ β”‚ β”‚ β”‚ β”‚ β”‚
948
+ β”‚ β”‚ Flask :5001 β”‚ β”‚ Vite :5173 β”‚ β”‚
949
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
950
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
951
+ β”‚ β”‚
952
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
953
+ β”‚ β”‚
954
+ β–Ό β–Ό
955
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
956
+ β”‚ BROWSER (localhost) β”‚
957
+ β”‚ β”‚
958
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
959
+ β”‚ β”‚ Frontend (:5173) <─────── Proxy ───────> Backend (:5001)β”‚ β”‚
960
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
961
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
962
+ ```
963
+
964
+ ### 11.2 Production Setup
965
+
966
+ ```
967
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
968
+ β”‚ Load Balancer β”‚
969
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
970
+ β”‚
971
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€οΏ½οΏ½
972
+ β”‚ β”‚ β”‚
973
+ β–Ό β–Ό β–Ό
974
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
975
+ β”‚ Flask Worker β”‚ β”‚ Flask Worker β”‚ β”‚ Flask Worker β”‚
976
+ β”‚ (:5001) β”‚ β”‚ (:5001) β”‚ β”‚ (:5001) β”‚
977
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
978
+ β”‚ β”‚ β”‚
979
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
980
+ β”‚
981
+ β–Ό
982
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
983
+ β”‚ Redis Cache β”‚
984
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
985
+ β”‚
986
+ β–Ό
987
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
988
+ β”‚ PostgreSQL β”‚
989
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
990
+ ```
991
+
992
+ ### 11.3 HuggingFace Model Hosting
993
+
994
+ ```
995
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
996
+ β”‚ HuggingFace Hub β”‚
997
+ β”‚ β”‚
998
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
999
+ β”‚ β”‚ namish10/contextflow-rl β”‚ β”‚
1000
+ β”‚ β”‚ β”‚ β”‚
1001
+ β”‚ β”‚ checkpoint.pkl ← Trained RL model β”‚ β”‚
1002
+ β”‚ β”‚ train_rl.py ← Training script β”‚ β”‚
1003
+ β”‚ β”‚ feature_extractor.py ← State extraction β”‚ β”‚
1004
+ β”‚ β”‚ online_learning.py ← Continuous learning β”‚ β”‚
1005
+ β”‚ β”‚ data_collector.py ← Real data collection β”‚ β”‚
1006
+ β”‚ β”‚ multimodal_detection.py ← Audio/biometric fusion β”‚ β”‚
1007
+ β”‚ β”‚ demo.ipynb ← Interactive demo β”‚ β”‚
1008
+ β”‚ β”‚ RESEARCH_PAPER.md ← Full documentation β”‚ β”‚
1009
+ β”‚ β”‚ β”‚ β”‚
1010
+ β”‚ β”‚ app/ (9 agents + API) β”‚ β”‚
1011
+ β”‚ β”‚ frontend/ (React UI) β”‚ β”‚
1012
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
1013
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
1014
+ ```
1015
+
1016
+ ---
1017
+
1018
+ ## Summary
1019
+
1020
+ ContextFlow is a comprehensive system combining:
1021
+
1022
+ 1. **Predictive AI** - RL-based doubt prediction before confusion occurs
1023
+ 2. **Multi-Agent Architecture** - 9 specialized agents coordinated by orchestrator
1024
+ 3. **Gesture Recognition** - Privacy-first MediaPipe hand detection
1025
+ 4. **Multi-Modal Sensing** - Audio + Biometric + Behavioral fusion
1026
+ 5. **Browser-Based AI** - Direct AI chat launching without API keys
1027
+ 6. **Continuous Learning** - Online learning from user feedback
1028
+
1029
+ The system is production-ready with all 9 API endpoints working, complete agent network, and trained RL model available on HuggingFace.