Seba is a modern, bilingual (Arabic/English) School Management System & Online Learning Platform tailored to the Egyptian National Curriculum. It integrates virtual learning modules with an advanced Computer Vision (CV) Real-time Focus & Proctoring Suite, a hardware NFC Attendance Subsystem, and a Cognitive AI Chatbot & RAG Engine.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ React Frontend โ
โ (TypeScript + TailwindCSS) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ
REST API / JSON โ WebSockets
(JWT Authentication) โ (Real-time Canvas Overlays)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FastAPI Web Server โ
โ (main.py / Database RBAC) โ
โโโโโโโโฌโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Computer Vision Engine โ โ SQLite Database โ โ AI Chatbot/RAG Engine โ
โ (RetinaFace, ArcFace, FSM) โ โ (learning_plat.db) โ โ (Ollama/Qwen OR Gemini) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ โ
โผ โผ
[Camera RTSP/Webcam Feed] [Egypt Curriculum PDFs]
Seba implements role-based access controls to partition dashboards and capabilities:
- ๐ Super Admin: Platform-wide auditor. Manages schools, platform billing, subscriptions, and global database schema migrations.
- ๐ซ School Manager: Local school administrator. Creates academic years, grades (e.g. "Grade 10"), physical classrooms, registers students and teachers, schedules the weekly timetables, and seeds face recognition databases.
- ๐ฉโ๐ซ Teacher: Classroom auditor. Controls physical monitoring cameras, starts/stops CV sessions, monitors real-time student focus, receives cheating flags, evaluates psychologist reports, and writes student progress notes.
- ๐ Student: Online learner. Views lessons, talks to the Seba AI tutor, asks voice questions, uploads handwritten problem photos, and takes adaptive quizzes.
- ๐ช Parent: Family auditor. Tracks their child's curriculum progress, grades, average physical classroom attendance, and focus rates.
The attendance subsystem bridges physical RFID/NFC hardware with student profiles in the database:
- Connection: An Arduino or ESP32-based RFID/NFC reader module (e.g. RC522 or PN532) connects to the host machine via a USB serial interface.
- Protocol: Serial connection established over COM ports (or
/dev/ttyUSBon Linux) configured at 9600 baud rate. - ESP32 Code (
esp32_nfc_code.ino): Scans Mifare NFC cards and outputs the UID as a clean hex string over the Serial interface. - Listener Daemon (
nfc_listener.py): Runs as a persistent background process. It polls the COM port for raw card UIDs, sanitizes the inputs, and sends structured HTTP POST requests to the backend's scan endpoint.
- Card Registration (
/api/attendance/enroll_card):- The student places a new card on the scanner.
- The scanner reads the card's Unique Identifier (UID) (e.g.
4A:F2:88:C1). - The admin maps the card UID to the student's ID inside the database.
- Daily Scanning (
/api/attendance/scan):- When a student taps their card in a physical classroom, the listener captures the UID.
- The backend checks
classroom_studentsto verify that the student is registered. - A new attendance record is logged in the
attendance_recordstable, updating the classroom's active attendance roster.
The real-time computer vision subsystem monitors physical classrooms to track student presence, focus rates, and exam integrity.
[Camera Frame] โโโบ Face Detection (RetinaFace) โโโบ Is Anchor Frame?
โ
โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโ
โ YES โ NO
โผ โผ
Face Recognition (ArcFace) ByteTrack Object Tracker
โ โ
โผ โผ
Match Enrolled Embeddings Maintain Track IDs
โ โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
2D Landmark Head Pose
โ
โผ
Focus State Machine
โ
โผ
Broadcast WebSockets
To optimize CPU/GPU cycles on host machines, the CV pipeline processes frames in a 30-frame sequence window:
- Frame 0 (Anchor Frame):
- RetinaFace Detection: Locates all facial bounding boxes and landmarks.
- ArcFace Recognition: Extracts 512-dimensional vector embeddings for each face.
- FAISS Database Lookup: Performs a cosine similarity search against enrolled student face profiles. If a match exceeds the threshold (cosine similarity
>0.6), the bounding box is labeled with thestudent_id. Unrecognized faces are flagged asunknown_face.
- Frames 1โ29 (Tracking Frames):
- Skips heavy face recognition.
- ByteTrack (Supervision): Performs object tracking using Kalman filters. It maintains bounding box associations between consecutive frames, locking the
student_idassigned on the anchor frame. - Re-anchoring occurs every 30 frames to correct track drift or identify newly arrived students.
Instead of running heavy 3D gaze estimation networks, Seba estimates Pitch, Yaw, and Roll using a highly stable 2D Facial Landmark Ratio Method:
-
Keypoints extracted: Left eye pupil (
$E_L$ ), right eye pupil ($E_R$ ), nose tip ($N$ ), left mouth corner ($M_L$ ), right mouth corner ($M_R$ ). -
Calculations:
-
Yaw (Horizontal turn): Distance ratio from nose tip to eyes:
$$d_L = |E_L - N|_2, \quad d_R = |E_R - N|_2$$ $$\text{Yaw Ratio} = \frac{d_L - d_R}{d_L + d_R + 10^{-6}}$$ $$\text{Yaw (Degrees)} = \text{Yaw Ratio} \times 130.0$$ A ratio close to0.0represents looking straight. Positive values indicate turning right; negative values indicate turning left. -
Pitch (Vertical tilt): Distance ratio of the nose relative to the eye-mouth vertical baseline:
$$\text{Eye Midpoint } (E_{\text{mid}}) = \frac{E_L + E_R}{2}, \quad \text{Mouth Midpoint } (M_{\text{mid}}) = \frac{M_L + M_R}{2}$$ $$\text{Face Height } (H_f) = |E_{\text{mid}} - M_{\text{mid}}|2$$ $$\text{Nose Position } (P_N) = \frac{(N - E{\text{mid}}) \cdot (M_{\text{mid}} - E_{\text{mid}})}{H_f^2}$$$$\text{Pitch (Degrees)} = -(P_N - 0.38) \times 130.0$$ Neutral position is typically around0.38. Deviations compute the vertical pitch angle. -
Roll (Sideways tilt): Angle of the inter-ocular line:
$$dy = E_{R,y} - E_{L,y}, \quad dx = E_{R,x} - E_{L,x}$$ $$\text{Roll (Degrees)} = \text{atan2}(dy, dx) \times \frac{180}{\pi}$$ Aligned to range from$-90^\circ$ to$+90^\circ$ relative to upright orientation.
-
Yaw (Horizontal turn): Distance ratio from nose tip to eyes:
- Benefit: 100% stable, math-error free, and extremely fast, avoiding the VRAM limits of deep spatial estimators.
Each tracked student's pitch and yaw inputs are evaluated against a state machine configured by classroom settings:
| Metric | Classroom Mode (is_exam=False) |
Exam Proctoring Mode (is_exam=True) |
|---|---|---|
| Distraction Threshold | Continuous pitch/yaw deviation for >3.0 seconds. | Continuous pitch/yaw deviation for >2.0 seconds. |
| Instant Distraction | Yaw deviation exceeds |
Yaw deviation exceeds |
| Lateral Glance | Not recorded. | Yaw deviation toward seat-neighbors (neighbor_glance. |
| Rapid Scan | Not recorded. | Direction reversals (Left-Right-Left) >3 times in 5 seconds flags a rapid_scan cheating alert. |
- Processed overlays (bounding boxes, names, yaw/pitch lines, focus indicators) are converted to structured JSON.
- The WebSocket server (
/api/cv/ws/{classroom_id}) broadcasts this payload to active frontend clients, rendering HTML5 canvas overlays at 30 FPS.
The online learning portal features a bilingual AI tutoring companion.
To adapt to Egyptian students, Seba implements a hybrid sentiment pipeline:
- Arabic Dialect Gatekeeper: Automatically checks if the student's message contains Arabic characters using a regex pattern.
- Translation Pipeline: If Arabic is detected, a specialized translation prompt is sent to the active LLM (Ollama/Gemini) to translate the Egyptian Arabic dialect (e.g. ู ุด ูุงูู , ู ุชุถุงูู, ุญุฒูู) to English while preserving technical terms. If the primary LLM fails, it automatically runs a fallback gatekeeper to try the alternative backend.
- Deep Emotion Classification: The translated English text is processed using a local, CPU-based HuggingFace
RoBERTa-base-go_emotionspipeline. It classifies the text into 28 discrete emotions (e.g.confusion,sadness,excitement,curiosity). - Sentiment Logs: The detected emotion, confidence score, original message, and translated text are saved to the
student_sentimentstable alongside local Cairo timestamps.
Seba retrieves math explanations from localized Egyptian curriculum documents using a hybrid search and re-ranking architecture:
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Student Query โ
โโโโโโโโโโโโฌโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโ
โผ โผ
Vector Search (FAISS) Lexical Search (BM25)
- BGE-M3 / Gemini Embeds - Tokenized Keywords
โ โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ
โผ
Course ID Filtering
โ
โผ
Combined Candidates (10)
โ
โผ
Cross-Encoder Reranking
(ms-marco-MiniLM-L-6-v2 CPU)
โ
โผ
Top 3 Reranked Chunks
โ
โผ
LLM Prompt Injection
- Ingestion: Math textbook PDFs are parsed, segmented into semantic blocks (300-token chunks with 50-token overlap), and cleaned of artifacts.
- Embeddings: Chunks are vectorized using either BGE-M3 (local) or Gemini Embedding API (
models/gemini-embedding-001). - Vector Storage: Embeddings are written to a local FAISS index.
- Lexical Storage: Chunks are tokenized and loaded into a
BM25Okapiindex. - Query Pipeline:
- Dual Retrieval: The system embeds the query and retrieves the top 10 candidates from FAISS (semantic) and the top 10 candidates from BM25 (lexical).
- In-Context Course Filtering: Filter candidate chunks based on active course IDs (e.g., mapping generic course ID 1 to Term 1 Course ID 6 or Term 2 Course ID 7) to enforce logical scoping.
- Cross-Encoder Re-ranking: Combined candidate chunks are scored via a CPU-based local
cross-encoder/ms-marco-MiniLM-L-6-v2model. - Scope Management & Disclaimer Router:
- In-Scope: If retrieval matches the current lesson title, the tutor focuses strictly on this content.
- Out-of-Scope (Reference Curriculum): If the topic is found in the curriculum but outside the current lesson, the response is generated but prefixed with:
โ ๏ธ Note: This topic is covered in [Lesson Name], not in our current lesson ([Current Lesson]). Here's what you need to know:and cites the source lesson clearly as[Term X LesY]. - Completely Unknown: If not in current lesson or reference materials, the chatbot declines politely and redirects the student to the current lesson content.
- Active Learning: A guided dialogue mode. The chatbot poses a math problem and walks the student through step-by-step solutions, loading/saving conversation memory using
active_learning_sessionshistory logs. - Multimodal OCR: The student can upload a photo of a handwritten math problem. The image is parsed via OCR, converted to LaTeX markdown, and explained by the tutor.
- Voice Pipeline:
- Speech-to-Text (STT): Transcribes audio bytes utilizing Groq Cloud's
whisper-large-v3API (zero local VRAM, free tier). - Text-to-Speech (TTS): Local pyttsx3 synthesis engine. Selecting Arabic voices if language is
ar(searching system voices containing "arabic" or "ar") and writing output to WAV bytes for frontend playback.
- Speech-to-Text (STT): Transcribes audio bytes utilizing Groq Cloud's
When a student requests a quiz (Egyptian Arabic trigger words like ุงุฎุชุจุฑูู, ูููุฒ, or English quiz me):
- Trigger Phrase Parsing: Recognizes intent from explicit phrases or standalone nouns combined with politeness markers.
- Sentiment Check: The engine checks the student's last 5 sentiment entries in the
student_sentimentstable. - Adaptation Strategy:
- If any recent entries show high anxiety, sadness, or confusion (e.g.
sadness,confusion,fear,nervousness), the quiz engine adapts:- Sets the quiz difficulty to
EASYto build confidence. - Adjusts the tone of the quiz title (e.g. "Confidence Booster Assessment") and tutor feedback to be highly supportive.
- Sets the quiz difficulty to
- If the student has been positive and focused, the difficulty scales up to
MEDIUMorHARD.
- If any recent entries show high anxiety, sadness, or confusion (e.g.
- Spaced Repetition: Generates 5 questions: Questions 1, 2, 4, and 5 cover the current lesson. Question 3 is seeded as a review question from previous lessons (looking back up to 3 past lessons).
- Database Persistence: Saves the generated quiz to the
quizzesandquiz_questionstables for structured grading.
Seba implements a background cognitive memory pipeline that automatically extracts, merges, and recalls pedagogical observations:
- At the end of chat sessions, a background thread runs
extract_learning_insightinnlp_engine.py. - It prompts the LLM to analyze the student's messages for specific learning indicators:
- Specific misconceptions (e.g. "Confused by fractions").
- Specific prerequisite knowledge gaps (e.g. "Struggles with division").
- Specific strengths or interests (e.g. "Excels at geometry").
- The pipeline produces a concise 6-word maximum note.
- The system embeds the extracted note content using BGE-M3 or Gemini.
- It compares this embedding to the student's existing notes in the
teacher_notestable. - Merging Threshold: If the cosine similarity between the new note and an existing note exceeds
0.85:- The new duplicate note is discarded.
- The existing note's
weightis incremented by0.5to highlight this recurring learning pattern.
- If no duplicate is found, the note is saved as a new entry with an initial weight (typically
1.5).
- When a student initiates a chat, the chatbot embeds the user's message.
- It computes the cosine similarity between the query embedding and all of the student's stored notes:
$$\text{Score} = \text{Similarity}(V_{\text{query}}, V_{\text{note}}) \times \text{Weight}_{\text{note}}$$ - Notes are sorted by Score, and the top 3 notes are injected as
SITUATIONAL MEMORIESin the system prompt. - This allows Seba to dynamically tailor its pedagogy to the student's persistent misconceptions or strengths.
The relational SQLite database manages the following 26 tables:
| Table Name | Primary Key | Foreign Keys | Key Columns | Purpose |
|---|---|---|---|---|
users |
id |
None | name, email, role, school_id, is_deleted |
User management and profiles |
schools |
id |
None | name, address, logo_url |
School profiles |
grades |
id |
school_id |
name, academic_year |
Academic tiers |
physical_classrooms |
id |
grade_id |
name, room_number, camera_source, is_exam_room |
Monitored school rooms |
classroom_students |
id |
classroom_id, student_id |
joined_at, is_active |
Roster mapping students to physical rooms |
classroom_teachers |
id |
classroom_id, teacher_id |
role, subject |
Roster mapping teachers to physical rooms |
class_schedule |
id |
classroom_id, teacher_id |
subject, day_of_week, period_start, period_end |
Physical weekly timetables |
student_face_profiles |
id |
student_id |
embedding (base64 pickling), photo_url |
Face verification representations |
cv_sessions |
id |
classroom_id, started_by |
session_type, started_at, ended_at, summary_json |
Camera session tracking |
focus_events |
id |
session_id, student_id |
event_type, pitch, yaw, duration_sec |
Distraction and cheating logs |
courses |
id |
None | title, description, subject, grade_level |
Educational course catalogs |
lessons |
id |
course_id |
title, content_en, content_ar |
Bilingual textbook lessons |
enrollments |
id |
student_id, course_id |
progress |
Online course enrollment rates |
lesson_progress |
id |
user_id, lesson_id |
time_spent_seconds, completed |
Time spent per student per lesson |
quizzes |
id |
lesson_id, student_id |
quiz_type, title, difficulty |
MC Quizzes (Generated or Platform) |
quiz_questions |
id |
quiz_id |
question, option_a, option_b, correct_answer |
MC Quiz questions |
quiz_answers |
id |
student_id, quiz_id |
question_id, answer, is_correct |
Answer choices selected by students |
quiz_submissions |
id |
student_id, quiz_id |
score, correct_answers, total_questions |
Structured quiz grades and scores |
attendance_records |
id |
student_id, classroom_id |
scanned_uid, created_at |
NFC-triggered attendance logs |
activities |
id |
user_id |
activity_type, entity_type, description |
Activity log events |
student_sentiments |
id |
student_id |
sentiment_label, confidence_score, created_at |
Sentiment log history |
teacher_notes |
id |
student_id |
teacher_id, content, created_at |
Teacher comments on students |
classwork |
id |
course_id |
title, classwork_type, resource_url, max_grade |
Assignments and homework uploads |
classwork_submissions |
id |
classwork_id, student_id |
completed, submission_file_url, grade |
Student homework file submissions |
active_learning_sessions |
id |
user_id, lesson_id |
history_json, is_completed |
Dialog session state logs |
classroom_messages |
id |
classroom_id, sender_id |
student_id, message, created_at |
Classroom message feeds |
Running LLM inference locally can easily exhaust systems with 16GB RAM. Seba handles this using a sequential lifecycle memory clearing system:
- Isolated Execution Device: Heavy embeddings models (BGE-M3) and the emotion parser are restricted to run on the CPU, keeping the GPU dedicated to Ollama (running Qwen 9B).
- RAM Eviction (
unload_local_models): Right before prompting Ollama:- References to CPU models are deleted.
- Python's Garbage Collector (
gc.collect()) is called. - CUDA cache is cleared (
torch.cuda.empty_cache()). - This frees 3+ GB of system memory, allowing Ollama to boot and compile responses without allocation crashes.
- Caching (
CACHE_LOCAL_MODELS):- Set to
trueon 32GB RAM machines (keeps models in memory to avoid reload latency). - Set to
falseon 16GB RAM machines (performs the eviction cleanup cycle on every prompt).
- Set to
- Folder:
backend/bge_m3_local/ - Link: Hugging Face BAAI/bge-m3
- Required files:
pytorch_model.bin(~2.27 GB),tokenizer.json,config.json, and all surrounding configuration binaries.
- Folder:
C:\Users\<Username>\.insightface\models\buffalo_l\ - Link: buffalo_l.zip
- Required files: Extract zip directly into target folder (
det_10g.onnx,w600k_r50.onnx, etc.).
- Install Python packages:
cd backend pip install -r requirements.txt - Place curriculum PDFs in
backend/curriculum_pdfs/Math/term_1/. - Ingest documents:
python ingest_pdfs.py
- Build RAG indexes:
python build_rag.py
- Initialize the database and tables:
python init_db.py
- Run the FastAPI development server:
python main.py
- Navigate to the frontend directory:
cd ../frontend - Install Node modules:
npm install
- Run the development server:
npm run dev
- Open your browser and navigate to
http://localhost:5173.