Architecture Overview¶
System Architecture¶
BioCoursesGenerator follows a modular client-server architecture with the following main components:
1. Frontend Layer (Streamlit)¶
- User Interface: Web-based interface built with Streamlit
- File Upload: Handles scanned document input (PDF/images)
- Processing Control: Triggers OCR and API workflows
- Results Display: Shows progress and provides download links
2. OCR Processing Module¶
- Image Preprocessing: Automatic rotation correction for crooked/crookedly scanned images
- Tesseract Integration: Extracts text from scanned images with Romanian language support
- Text Preprocessing: Cleans and formats raw OCR output
- Document Types Supported: PDF documents, scanned images (JPEG/PNG/TIFF)
3. LLM API Integration Layer¶
- First API Call:
gpt_generate_book_toc_with_prompts - Input: OCR-extracted text + context instructions
- Output: TOC file link in hierarchical format
- Second API Call:
gpt_toc_to_pdf - Input: TOC file link
- Output: Generated PDF link
4. File Management System¶
- Output Directory:
/outputs/for storing generated PDFs - Temporary Storage: For intermediate files during processing
- Download Service: Serves generated files to users
Data Flow Architecture¶
1. Input Processing
User Uploads → File Validation → Storage → Metadata Extraction
2. OCR Pipeline
Document → Image Extraction (if PDF) → Tesseract OCR → Text Normalization
3. Content Structuring
Raw Text → LLM API Call #1 → TOC File Generation → Link Retrieval
4. PDF Generation
TOC Link → LLM API Call #2 → PDF Generation → Download Link
5. Output Management
PDF Link → Download File → Save to /outputs/ → User Download
Technology Stack¶
Frontend¶
- Streamlit: 1.28+
- Python: 3.9+
Backend Processing¶
- OCR: pytesseract 0.3+
- PDF Handling: PyPDF2 or pdfplumber
- Image Processing: Pillow, OpenCV (optional)
- HTTP Client: requests for API calls
- File Download: urllib or requests
External Services¶
- LLM API: Custom REST API running on
http://127.0.0.1:7998 - File Storage: External server for TOC/PDF storage
Component Interaction Diagram¶
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Streamlit UI │────│ OCR Processor │────│ LLM API #1 │
│ │ │ │ │ (TOC Generation)
│ • File Upload │ │ • Tesseract │ │ • Content Structuring
│ • Progress Display││ • Text Cleaning │ │ • Romanian Language
│ • Download Links │ │ • Error Handling │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ │ TOC File Link
│ │ │
│ └───────────────────────┘
│ │
│ v
│ ┌──────────────────┐ ┌─────────────────┐
│ │ LLM API #2 │────│ PDF Storage │
│ │ (PDF Generation) │ │ │
│ │ • Markdown to PDF│ │ • File Hosting │
│ │ • Content Filling│ │ • Link Generation│
│ │ │ │ │
│ └──────────────────┘ └─────────────────┘
│ │ │
│ │ PDF Direct Link
│ │ │
└─────────────────────────────┼───────────────────────┘
│
v
┌──────────────────┐
│ Output Directory │
│ (/outputs/) │
│ • PDF Storage │
│ • Archive Management│
│ • Download serving│
└──────────────────┘
Module Dependencies¶
Core Dependencies¶
- streamlit
- pytesseract
- pillow
- requests
Optional Dependencies¶
- opencv-python (for advanced image processing)
- pypdf2 (for PDF text extraction)
- python-docx (if Word support needed)
Error Handling and Resilience¶
- OCR Failures: Fallback to manual text input
- API Timeouts: Retry logic with exponential backoff
- Invalid Formats: Input validation and user feedback
- Storage Issues: Temporary file cleanup and error reporting
Scalability Considerations¶
- Processing Bottlenecks: OCR and API calls may be time-intensive
- Concurrent Users: Single-threaded processing limits
- File Sizes: Memory management for large documents
- External Dependencies: Reliability of LLM services