Sari la conținut

FitzUICI Generator Architecture

Overview

FitzUICI Generator is a modular document processing pipeline designed for handling scanned educational materials, PDFs, and various document formats. The system is organized into core scripts (MAIN/), utility libraries (pyt_utils/, pyt_services/), and processing output (output/, _materials-to-process/).

Core Architecture

Directory Structure

fitzuici-generator/
├── MAIN/                    # Main executable scripts
├── pyt_services/           # Service modules and utilities
├── pyt_utils/              # Core utility libraries
├── _materials-to-process/  # Input processing queues
├── output/                 # Processed output files
├── docs/                   # Documentation
└── tests/                  # Test suite (if any)

Main Processing Pipeline

1. Document Ingestion and Normalization (normalize_docs.py)

  • Purpose: Standardize input documents to DOCX format
  • Conversions Supported:
  • TXT → DOCX
  • PDF → DOCX
  • DOC/DOCX → DOCX (validation/normalization)
  • Dependencies: docx, pdf2docx, subprocess

2. Automated Directory Processing (dir_automator.py)

Flow: 1. Scans input directory for documents 2. Validates file types and paths 3. Processes documents in batches 4. Handles document splitting via process_fitzuici_continously.py 5. Supports both plaintext and styled document processing

Key Features: - --split: Automatic section detection - --split-force-llm: LLM-enhanced splitting - --pdftype-is-image: Alternative processing for scanned PDFs

3. Document Preprocessing (borders.py)

Components:

Image Processing Pipeline:

  1. Page Detection: Identifies double/single scanned pages
  2. Text Zone Detection: Uses OpenCV for main content area detection
  3. Cropping: Removes margins and unwanted artifacts
  4. Rotation: Corrects page orientation
  5. PDF Reconstruction: Rebuilds PDFs from processed images

OCR Integration:

  • Uses Tesseract for text extraction
  • Confines scores and manual processing support
  • Page-level splitting for large documents

Key Algorithms: - detect_main_page_textzone(): Computer vision-based zone detection - detect_double_scanned_page(): Multi-page detection - Perspective correction for angled documents

4. Manual Interactive Processing (manual_lens.py)

GUI Components: - Perspective Transformation: Click-based point selection for correction - Rotation Control: Numerical angle adjustment - Live Preview: Real-time processing visualization - Output Export: Saves corrected images

Technical Stack: - Tkinter for GUI - OpenCV for image processing - NumPy for transformations - PIL for image handling

5. NLP Document Analysis (ml_doc_splitter.py)

Processing Steps: 1. Section Extraction: Uses lib_common.extract_sections() 2. False Positive Filtering: Removes TOC and invalid sections via LLM 3. Title Consolidation: Combines empty/similar titles 4. Semantic Filtering: Removes redundant/oversized/ignorable titles

Dependencies: - NLTK/Spacy for NLP processing - Custom filtering functions (is_redundant_title, is_oversized_title) - LLM integration for complex section detection

6. Input Generation (input_generator.py)

YAML Processing: - Schema validation via generate_example_yaml() - Batch processing of input configurations - Interactive mode for user verification

Utility Libraries

pyt_utils/ - Core Utilities

  • cli_utils.py: Command-line interface framework
  • opencv_utils.py: Computer vision helpers (crop, rotation detection)
  • llm_service_chatgpt.py: LLM integration wrapper
  • file_watchers.py: File monitoring utilities
  • email_utils.py, fb_storage_utils.py: Integration helpers

Key Algorithms

Document Splitting Logic:

plaintext_doc = not docx_has_styles(filename)
sections = extract_sections(mode="txt_mode" | "fulldocx")
sections = remove_toc_sections(sections)
sections = pp_combine_empty_titles(pp_fix_sublists(sections))
if plaintext_doc: sections = remove_false_sections_by_llm(sections)
sections = filter_sections(*multiple filters*)

PDF Processing:

for each page:
    if manual_mode: manual_lens.process()
    else: detect_automatic_crop()
    rotate if needed
    dock to output PDF

Dependencies and Environment

  • Python Requirements: Listed in requirements.txt
  • External Tools: Tesseract OCR, LibreOffice (for DOC→DOCX)
  • Virtual Environment: _myenv/ with custom installations
  • OCD Kit: Tesseract and Poppler binaries in kits/

Error Handling and Logging

  • CLI-based error reporting with traceback details
  • Debug modes with interactive visualization
  • Skip/manual processing for problematic pages
  • Confidence scoring for OCR quality assessment

Deployment and CI/CD

  • Makefile: Script automation and deployment
  • docs-deploy target: Automatic documentation syncing to MkDocs server
  • PROJECT_NAME: Dynamic naming via basename $PWD

This architecture supports both automated batch processing and interactive manual intervention, making it suitable for complex document processing workflows involving scanned materials and educational content.