How chrisvivasai/fraga works
Project type and purpose
• This is a full-stack, Streamlit-based web application (“OCR Fraga”) for reviewing Architectural & Engineering plan PDFs.
• It combines OCR (Tesseract), PDF parsing (PyMuPDF), image extraction, embedding generation, a Retrieval-Augmented Generation Q&A system, and persistence via Supabase (PostgreSQL + Storage).
• Users upload or load plan sets, the system extracts text/images, creates embeddings, stores data, and presents an interactive UI for text, image browsing, and AI-driven Q&A (optionally using local Ollama models or Google Gemini).
File structure
• Top-level:
• app.py – Streamlit entry point (UI control, tab layout).
• modules/ – Core logic subdivided by functionality:
– text_extractor.py (OCR, cleaning, embedding)
– image_handler.py (PDF image extraction, metadata, cloud storage)
– qa_analyzer.py (semantic search + LLM calls, context assembly)
– shared_resources.py (DB/Storage & model-loading utilities)
• requirements.txt & packages.txt – dependencies.
• README.md – documentation.
• Configuration: expects a .env file (Supabase URLs/keys, Tesseract path, optional Google API key, Ollama model name).
• No dedicated frontend vs. backend directories, but logically app.py is the “UI layer” and modules are the “service layer.”
Key insights from README
• Uses Streamlit’s multi-tab UI: Text/Project Info, Images, Q&A.
• Persistence via Supabase: projects, extracted text, embeddings, image metadata, raw PDFs.
• Two AI model options: local (Ollama/Gemma/LLaVA) or Google Gemini via API.
• OCR via Tesseract; PDF parsing via PyMuPDF; embeddings via sentence-transformers; semantic search; RAG pipeline.
Main components & their interactions
a. Frontend (Streamlit UI – app.py)
• File uploader & project selector
• Sidebar for AI model selection
• Three tabs: Text, Images, Q&A
– Displays results and takes user queries
b. Service layer (modules/)
• TextExtraction Service
• Reads PDF → Tesseract OCR → cleans/standardizes text → creates embeddings
• ImageExtraction Service
• Reads PDF → extracts images → stores in Supabase Storage → metadata in Supabase DB
• QA Service
• Accepts user query → retrieves relevant text embeddings + optional code DB → calls LLM (Ollama/Gemini) → returns answer
• SharedResources
• Manages Supabase DB & Storage connections
• Loads LLM clients (Ollama or Google API)
c. Database & Storage (Supabase)
• PostgreSQL: projects, document records, text chunks, embeddings, image metadata, QA logs
• Storage: raw PDFs, extracted images
d. External Services
• Tesseract OCR (local binary)
• Ollama (local LLM hosting) or Google Gemini API
• Supabase (cloud DB + Storage)
Architectural patterns & design principles
• MVC-like separation: UI (app.py) vs. business logic (modules/) vs. persistence (Supabase).
• Single-process monolith, but logically layered.
• RAG pattern: semantic search + LLM.
• Factory or provider pattern in shared_resources for model and DB clients.
• Streamlit event-driven UI.