How stabrise/scaledp works
Project type and purpose
• ScaleDP is an open-source Python library (SDK) for AI/ML–driven document processing on Apache Spark.
• It provides Spark DataFrame readers, transformers (PDF → DataFrame, binary images, text), pipeline stages (OCR, detection, extraction, NER), schema definitions, and utilities to integrate with external model engines (LLM/VLM APIs, Hugging Face, OCR engines).
Main components
a. User application layer
• Your Python code or notebook that builds a Spark session (ScaleDPSession) and a PipelineModel with stages.
• Optional REST API wrapper for low-latency, no-Spark deployments.
b. Apache Spark layer
• Spark driver and executors running DataFrame operations.
• Spark data sources: PDF datasource (spark‐pdf) and binaryFile for images.
c. ScaleDP library core
• I/O modules: scaledp/pdf, scaledp/image, scaledp/text — convert raw bytes to structured DataFrame columns.
• Pipeline modules: in scaledp/pipeline/PandasPipeline.py and stage classes under scaledp/models/*
• Schemas: Pydantic and Dataclasses in scaledp/schemas for typed outputs.
• Utils for display and template rendering (HTML, JSON).
d. Model/processing engines
• OCR engines: Tesseract, EasyOCR, Surya, DocTR (local).
• CV detectors: YOLO, DocTR text detector.
• LLM/VLM extractors and NER: calls out to OpenAI-compatible endpoints, Google Gemini, Hugging Face Hub.
• DSPy, LLMVisualExtractor, LLMExtractor, NER modules.
e. External services and resources
• RESTful API endpoints (OpenAI, Google generativelanguage API).
• Hugging Face model hub.
• Local resource files (example PDFs/images) under scaledp/resources.
Relationships and data flow
• Data ingestion: PDF/image/text files → Spark DataFrame
→ series of pipeline stages (DataToImage → OCR/Detector → Extractor → Ner → ImageDrawBoxes)
→ output columns (binary image, text, JSON, visualizations) in the same DataFrame
→ user consumes structured data or writes to sinks.
• Inter-stage calls: each transformer stage takes one or more inputCols, produces an outputCol; some stages invoke external APIs or local engines.
• Control plane: pipeline orchestration via Spark DAG.
Architectural patterns and principles
• Layered modular design: I/O → processing stages → schemas → utils.
• Plugin-style extensibility: base classes (BaseDetector, BaseExtractor, BaseOcr, BaseRecognizer, BaseNer) allow adding new engines.
• Declarative pipeline: users compose stages; engine implementations are swappable.
• Data-centric flow: everything is a Spark DataFrame column; no global state.