How eshaanpra/document2flashcards works
Project Type and Purpose
• This is a monolithic, full-stack Streamlit application (“Document2Flashcards”) that allows users to upload documents (PDFs, images, text), runs OCR and AI to generate flashcards, persists them in a SQLite database, and presents an interactive flashcard UI.
File-Structure Analysis
• Top-level files only:
• FullProgram.py – the single entry point combining UI (Streamlit), business logic, data access, and external-service calls
• config.yaml – holds app‐wide settings (e.g. auth, model paths)
• requirements.txt – Python dependencies (Streamlit, pytesseract, llama-cpp-python, PyPDF2, etc.)
• .gitignore
• No separate “frontend” or “backend” folders; the code is a monolithic service, but internally it can be logically split into layers.
README Insights
• Describes OCR (Tesseract), PDF extraction (PyPDF2), AI model (Llama), SQLite DB, user auth, UI with CSS animation, session state.
• Indicates a chunk-based pipeline for processing large documents.
Core Components
a. Streamlit Frontend Layer (UI)
• File-upload widget
• Login/Signup flows (streamlit-authenticator)
• Interactive flashcard display (HTML/CSS flip animation)
• Sidebar for deck selection
b. Document Processing Layer
• PDF extractor (PyPDF2)
• Image OCR (pytesseract + PIL)
• Plain-text loader
c. Text Chunking & Preprocessing
• Splits large text into manageable chunks (< n_ctx)
• Normalization, tokenization
d. AI Flashcard Generator
• llama-cpp-python interface to Llama model
• Prompt construction, inference, JSON flashcard output
e. Data Access Layer
• SQLite database
• Tables: Users, Decks, Flashcards
• CRUD operations (save/retrieve decks and cards)
f. External Services & Resources
• Tesseract OCR binary (TESSERACT_PATH)
• Llama model file (MODEL_PATH)
g. Configuration & Environment
• config.yaml / environment variables for secrets and paths
Relationships & Interactions
• External services are called by Document Processing (Tesseract) and AI Generator (Llama).
Architectural Patterns & Principles
• Monolithic layered architecture: UI, business logic (document-OCR-AI pipeline), data access, external adapters
• Single responsibility per logical module
• Caching of LL model and Streamlit session state for performance
• Use of environment variables for configuration (12-factor)