How santhosh790/ecomsenseai works
Purpose and entry point
ecomSenseAI is a Streamlit-based document-processing application that extracts vegetable items and quantities from PDF, image, and Excel orders, lets users validate results, and saves date-scoped order outputs. The composition/UI entry point is ecomSenseAI.py; domain and service layers support its upload-to-confirm workflow.
Domain model and catalog
Extracted items are represented as typed domain records, including detection status and confidence, in domain/models.py. Vegetable normalization and lookup are driven by catalog/alias data in data/vegetables.json and data/aliases.json, accessed through infrastructure/vegetable_catalog_repository.py. This catalog boundary separates source-document wording, OCR noise, and canonical output names.
Extraction pipeline
application/extraction_service.py is the central parsing and decision layer. It selects/handles document text formats, identifies item/quantity candidates, performs fuzzy catalog matching, and applies confidence/status policy. It produces domain detections rather than coupling parser logic directly to the Streamlit UI. Client- or supplier-specific interpretation is supported through data such as data/clients.json.
Document and OCR ingress
Document-specific text acquisition is isolated from extraction rules. infrastructure/document_readers.py handles PDF/Excel-style input reading, while infrastructure/ocr_engine.py handles image preprocessing and OCR. The OCR engine prefers PaddleOCR with OpenCV preprocessing and falls back to Tesseract; Tesseract additionally requires a host-installed binary. Extracted text is returned to the application layer for parsing and user preview.
Validation and order lifecycle
The primary control flow is: upload → read/OCR → extract detections → user validation/editing → confirm → persist and optionally publish. ecomSenseAI.py presents confidence controls and review states so low-confidence detections remain human-verifiable. application/reporting_service.py forms individual and consolidated order views, while application/vegetable_detection_service.py supports detection-oriented application operations.
Persistence, reporting, and saved-order boundaries
Confirmed rows are saved locally as dated CSV outputs and can be reloaded/revalidated by date and source file. infrastructure/persistence_service.py owns this storage boundary; infrastructure/assets_service.py supports stored upload/original-asset handling. Consolidation aggregates quantities across confirmed files for a selected date rather than treating each upload as an isolated final report.
External integrations and deployment runtime
Google Sheets publishing is optional and isolated in infrastructure/google_sheets_service.py, using Streamlit secrets for a GCP service account and target worksheet. Address-related data/services are separate (infrastructure/address_service.py, data/addresses.json), likely supporting order/report organization. Python dependencies are declared in requirements.txt; deployment-level system OCR/font requirements are captured in packages.txt, with Streamlit Cloud as the documented hosting target.
Main entry points: ecomSenseAI.py ecomSenseAI · extraction_service.py Extraction service · vegetable_catalog_repository.py Vegetable catalog · ocr_engine.py OCR engine
Components 18
Streamlit UI
- ecomSenseAI · Runs the upload-to-confirm workflow.
ecomSenseAI.py - Uploaded orders
Application services
- Detection records · Typed items include status and confidence.
domain/models.py - Extraction service · Finds item quantities, matches catalog names, and assigns confidence.
application/extraction_service.py - Detection service
application/vegetable_detection_service.py - Reporting service · Builds individual and consolidated order views.
application/reporting_service.py
Infrastructure and data
- Document readers
infrastructure/document_readers.py - OCR engine · OpenCV preprocessing with PaddleOCR and Tesseract fallback.
infrastructure/ocr_engine.py - Vegetable catalog · Normalizes source wording to canonical vegetable names.
infrastructure/vegetable_catalog_repository.py - Vegetable catalog data
data/vegetables.json - Vegetable aliases
data/aliases.json - Client rules data
data/clients.json - Order persistence · Saves, reloads, and revalidates confirmed orders.
infrastructure/persistence_service.py - Asset storage
infrastructure/assets_service.py - Google Sheets publisher · Publishes confirmed outputs using Streamlit secrets.
infrastructure/google_sheets_service.py - Address service
infrastructure/address_service.py - Address data
data/addresses.json - Deployment requirements · Includes OCR and font requirements for Streamlit Cloud.
requirements.txt
Connections 20
- Uploaded orders → ecomSenseAI: upload
- ecomSenseAI → Document readers: PDF/Excel text
- ecomSenseAI → OCR engine: image text
- Document readers → Extraction service: text
- OCR engine → Extraction service: OCR text
- Extraction service → Vegetable catalog: fuzzy lookup
- Vegetable catalog → Vegetable catalog data: canonical names
- Vegetable catalog → Vegetable aliases: aliases
- Extraction service → Client rules data: client interpretation
- Extraction service → Detection records: detections
- Detection records → ecomSenseAI: review and edit
- ecomSenseAI → Detection service: detection operations
- ecomSenseAI → Order persistence: confirm and reload
- ecomSenseAI → Asset storage: store originals
- Order persistence → Reporting service: dated confirmed orders
- Reporting service → ecomSenseAI: order views
- ecomSenseAI → Google Sheets publisher: optional publish
- ecomSenseAI → Address service: address organization
- Address service → Address data: lookup
- Deployment requirements → OCR engine: OCR dependencies