LectureLens transforms educational YouTube lectures into structured study guides with OpenCV-extracted slide images, active-recall revision tools, and an interactive, lecture-grounded Q&A assistant.
- How the Pipeline Actually Works
- Key Features
- Architecture Overview
- Empirical Evaluation & Benchmarks
- System Requirements
- Installation & Setup
- Configuration (.env)
- How to Run
- Running Automated Tests
- Data Storage & Lecture Isolation
- Troubleshooting & Known Limitations
It is important to understand the actual data flow of LectureLens:
- Direct Video Ingestion (No Caption/Transcript Dependencies):
- Gemini watches and listens to the public YouTube video directly via its native multimodal API (
google.genai.types.FileData(file_uri=url)). - There is no transcript scraping library (no
youtube-transcript-api, no Whisper, no.srtparsing). Gemini directly analyzes spoken explanations, on-screen slides, diagrams, equations, and code demonstrations in a single end-to-end call, outputting a structuredvideo_analysis.json.
- Gemini watches and listens to the public YouTube video directly via its native multimodal API (
- Timestamp Normalization & Boundary Clamping:
yt-dlpprobes the verified video duration upfront, constraining Gemini's prompt and programmatically clamping any overrunning timestamps (0 <= start_time < end_time <= total_duration).
- Physical Slide & Keyframe Extraction:
yt-dlptemporarily streams lightweight video fragments into an isolated temporary directory. OpenCV (cv2.VideoCapture) seeks to each timestamp identified by Gemini, writes high-resolution JPEGs to disk, and savesvisual_manifest.json. The temporary video is automatically deleted immediately afterward.
- Study Note Synthesis (From Analysis JSON, Not RAG):
- Comprehensive study notes, key concepts, visual explanations, and revision flashcards are synthesized directly from
video_analysis.jsonvia Gemini text generationβnotes are not built from fragmented RAG chunks. Extracted slide JPEGs are programmatically attached to corresponding sections.
- Comprehensive study notes, key concepts, visual explanations, and revision flashcards are synthesized directly from
- Local Vector RAG (Used Strictly for Interactive Q&A):
- Retrieval-Augmented Generation is used strictly for the interactive Q&A assistant tab. Chunks carrying section titles and timestamps are embedded locally using
sentence-transformers/all-MiniLM-L6-v2and indexed into an isolated FAISSIndexFlatIPstore. When a student asks a question, the retriever extracts evidence passages, the Relevance Guard checks for topic boundaries, and Gemini generates a grounded answer with[MM:SS]timestamp citations.
- Retrieval-Augmented Generation is used strictly for the interactive Q&A assistant tab. Chunks carrying section titles and timestamps are embedded locally using
- Direct Multimodal Video Understanding: Gemini analyzes the video directlyβunderstanding spoken explanations, whiteboard drawings, slide text, and terminal code together.
- Timestamp Integrity: Duration probing via
yt-dlpand post-analysis clamping ensure timestamps never exceed the real video length. - Physical Keyframe Extraction: OpenCV extracts physical slide images at verified moments into permanent JPEG assets.
- Grounded RAG Assistant (For Q&A):
- Topic-aware sentence-preserving chunking with section metadata and timestamps.
- Local dense vector embeddings via
sentence-transformers/all-MiniLM-L6-v2(384-d, normalized for cosine similarity). - Lecture-isolated FAISS (
faiss-cpu) vector indexes with synchronized metadata. - Dual-phase Relevance Guard detecting in-scope, insufficient-evidence, and out-of-scope inquiries.
- Revision & Self-Assessment Tools:
- Active-recall concept flashcards with interactive reveal.
- Grounded multiple-choice quizzes with automated grading, explanations, and timestamp references.
- Publication-Quality Export: Export notes to Markdown or styled PDF (using ReportLab) with cover headers, callout boxes, and embedded diagrams.
LectureLens/
βββ src/
β βββ main.py # Streamlit web application & multi-tab UI
β βββ video_analyzer.py # Gemini multimodal video analyzer & duration constraints
β βββ visual_extractor.py # OpenCV frame extraction & manifest generator
β βββ note_generator.py # Study note synthesizer & markdown converter
β βββ gemini_client.py # Gemini client factory with automated model failover
β βββ rag/
β β βββ document_builder.py # Section-to-document transformation
β β βββ chunker.py # Sentence-preserving deterministic chunker
β β βββ embeddings.py # Local SentenceTransformers (all-MiniLM-L6-v2) singleton
β β βββ vector_store.py # FAISS IndexFlatIP inner-product store
β β βββ retriever.py # Semantic retrieval & source citation
β β βββ relevance.py # Dual-phase relevance guard & refusal handler
β β βββ answer_generator.py # Grounded Gemini answer generator
β β βββ pipeline.py # End-to-end RAG coordinator (for Q&A)
β βββ services/
β β βββ lecture_service.py # Multi-lecture lifecycle & legacy path sync
β β βββ quiz_service.py # Flashcards and interactive quiz assessment
β β βββ export_service.py # Markdown and ReportLab PDF exporters
β βββ models/
β β βββ schemas.py # Pydantic contracts & data models
β βββ utils/
β β βββ config.py # Centralized configuration & standard paths
β β βββ logging_config.py # Secret-masked structured logging
β β βββ validation.py # URL parsing & timestamp normalization
β βββ evaluations/
β βββ evaluator.py # Single-lecture benchmark test runner
βββ evals/ # Empirical evaluation framework
β βββ measure_performance.py # Multi-lecture timing & stage breakdown benchmark
β βββ faithfulness_check.py # Auto-judged sampled evidence faithfulness suite
β βββ results/
β βββ performance_metrics.json# Raw per-stage latency & call counts
β βββ faithfulness_report.json# Raw statement-by-statement evidence verdicts
βββ data/
β βββ analysis/ # Active lecture analysis JSON
β βββ notes/ # Active study notes (JSON, MD, PDF)
β βββ visuals/ # Extracted slide images & visual_manifest.json
β βββ indexes/ # FAISS vector indexes (<lecture_id>/index.faiss)
β βββ lectures/ # Isolated multi-lecture archives (<lecture_id>/...)
β βββ evaluations/ # Evaluator metrics CSV and JSON
βββ tests/ # Automated unit, integration, and regression tests
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ EVALS.md # Complete benchmark reproduction guide
βββ AGENTS.md # Persistent engineering rules
For more details, see docs/architecture.md.
All benchmark metrics are generated by automated scripts in evals/ running on real, public YouTube educational lectures. Complete details and raw JSON outputs are documented in EVALS.md.
Measured using evals/measure_performance.py across technical lectures ranging from 2 to 22 minutes (Raw data: evals/results/performance_metrics.json):
| Lecture Topic | Duration | Total Time | 1. Metadata Probe | 2. Gemini Video Understanding | 3. Frame Extraction (OpenCV) | 4. Note Synthesis (Gemini Text) | 5. Local FAISS RAG Indexing | Frames Extracted | Chunks Indexed |
|---|---|---|---|---|---|---|---|---|---|
| Neuroscience Intro | 02:20 (140s) | 89.94s | 1.77s | 47.78s | 6.20s | 10.83s | 23.36s* | 5 | 3 |
| Agentic AI Architecture | 13:49 (829s) | 118.51s | 1.91s | 84.64s | 13.63s | 17.37s | 0.94s | 25 | 10 |
| Model Context Protocol | 21:57 (1,317s) | 116.13s | 1.76s | 71.63s | 21.20s | 20.75s | 0.78s | 23 | 10 |
| Aggregates (3 Lectures) | Median: 13:49 | Median: 116.13s | Median: 1.77s | Median: 71.63s | Median: 13.63s | Median: 17.37s | Median: 0.94s | Total: 53 | Total: 23 |
*Note: Stage 5 for Lecture 1 included cold-start memory allocation and model weight caching for SentenceTransformers.
- Completion Rate: 100.0% (3/3) successful end-to-end runs without errors.
- API Call Budget: Exactly 2 Gemini API calls per lecture (1 video call + 1 text call). Zero external embedding API calls.
Measured using evals/faithfulness_check.py by randomly sampling 10 factual statements per lecture (seed=42) across 4 lectures (evals/results/faithfulness_report.json):
| Lecture ID | Topic | Sampled Statements | Strictly Supported | Partially Supported (Extrapolations) | Unsupported (Hallucinations) | Faithfulness Rate (Strict) | Plausible Rate (Supported + Partial) |
|---|---|---|---|---|---|---|---|
sample_node_lecture |
Node.js Fundamentals | 10 | 10 | 0 | 0 | 100.0% | 100.0% |
yt_AUYtP6kVrQk |
Neuroscience Intro | 10 | 8 | 2 | 0 | 80.0% | 100.0% |
yt_GeVCpohRU8Y |
Model Context Protocol | 10 | 8 | 2 | 0 | 80.0% | 100.0% |
yt_15_pppse4fY |
Agentic AI Systems | 10 | 3 | 3 | 4 | 30.0% | 60.0% |
| Total / Macro Metric | Diverse Technical Lectures | 40 | 29 | 7 | 4 | 72.5% | 90.0% |
Audit Note on Weak Results: The Agentic AI lecture scored lower (30% strict / 60% plausible) because the note generator hallucinated an external 4-part agent taxonomy into Section 2 ("Tool-Augmented Chatbots"), where the instructor was actually explaining why tool-augmented chatbots are not agentic. The LLM blended external background knowledge about agents into early introductory sections.
- Dataset Scope: 13 hand-written questions on one 7-minute lecture (
sample_node_lecture), not a general benchmark. - Results on this specific sample: HitRate@4: 1.0, MRR: 1.0, Retrieval Latency: ~12.7 ms. Run via
python src/evaluations/evaluator.py.
- Operating System: Windows 10/11, macOS, or Linux.
- Python Version: Python 3.11 or 3.12 (Recommended). (Note: Python 3.13 on Windows has known OpenMP DLL initialization conflicts with
faiss-cpuunder test runners likepytest). - Memory (RAM): 4 GB minimum (8 GB recommended for local embedding model).
- Disk Space: ~500 MB for Python packages and local embedding model cache.
- Network: Internet access for YouTube metadata probing, Gemini API calls, and temporary frame extraction downloads.
git clone https://github.com/Bhakti-debug/LectureLens.git
cd LectureLensWindows (PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1macOS / Linux:
python3 -m venv .venv
source .venv/bin/activatepython -m pip install --upgrade pip
pip install -r requirements.txtCopy .env.example to create your local .env:
cp .env.example .envConfigure your API key and preferences:
# Gemini API Configuration
GEMINI_API_KEY=your_actual_gemini_api_key_here
GEMINI_MODEL=gemini-3.7-flash
# RAG & Local Embedding Configuration (Used strictly for Q&A)
EMBEDDING_MODEL=all-MiniLM-L6-v2
CHUNK_SIZE=400
CHUNK_OVERLAP=60
RETRIEVAL_TOP_K=4
RELEVANCE_SIMILARITY_THRESHOLD=0.35
# Application & Logging
LOG_LEVEL=INFOstreamlit run src/main.pyStreamlit will launch locally at http://localhost:8501.
- Analyze a New Lecture: Paste any public YouTube link in the top expander and click π Analyze Lecture.
- π Study Notes & Visuals: Read the lecture overview, chronological sections with timestamps, key concepts, and extracted slide images.
- π¬ Lecture Q&A Assistant: Ask conceptual questions grounded in the lecture. Inspect retrieved evidence passages and timestamp citations.
- ποΈ Revision Flashcards: Test memory recall with interactive concept flashcards.
- π Self-Assessment Quiz: Answer multiple-choice questions with automated grading and explanations.
- π₯ Export Study Material: Download publication-ready
.mdor styled.pdfdocuments. - Switch Lectures: Use the sidebar dropdown to switch between previously analyzed lectures without mixing indexes or chat history.
Run the unit, integration, and regression test suite:
pytest -v tests/test_validation.py tests/test_chunker.py tests/test_study_tools.py tests/test_export.py tests/test_regression.pyAll artifacts are persisted in lecture-scoped directories:
- Analysis:
data/lectures/<lecture_id>/video_analysis.json - Visuals:
data/lectures/<lecture_id>/visuals/andvisual_manifest.json - Notes:
data/lectures/<lecture_id>/study_notes.jsonandstudy_notes.md - Vector Indexes:
data/indexes/<lecture_id>/index.faissandmetadata.json
- Video Accessibility:
- Gemini analyzes public YouTube videos directly via URL. Age-restricted, private, or regional-blocked videos will fail with
403 PERMISSION_DENIED.
- Gemini analyzes public YouTube videos directly via URL. Age-restricted, private, or regional-blocked videos will fail with
- API Quota Management:
- Free-tier Gemini accounts have a limit of 15 RPM. The client includes automatic retry and model failover (
gemini_client.py) across candidate models to protect against429 RESOURCE_EXHAUSTED.
- Free-tier Gemini accounts have a limit of 15 RPM. The client includes automatic retry and model failover (
- No Closed-Caption Dependency:
- Because Gemini listens to the audio track directly, videos without spoken narration (pure background music or silent slides) will result in minimal spoken content.
- Local Vector Search Scope:
- The vector store indexes structured text representations (spoken content, slide descriptions, on-screen text). Direct visual vector search (CLIP / SigLIP) is a planned future enhancement.