# girijesh-s001/palm-leaf-project architecture

> Architecture diagram of the GitHub repository girijesh-s001/palm-leaf-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/girijesh-s001/palm-leaf-project
- Repository: https://github.com/girijesh-s001/palm-leaf-project

## Overview

This repository implements an OCR service for historical Tamil palm-leaf images. A user submits an image through the web API; the OCR orchestrator optionally crops the manuscript, segments lines and glyphs, classifies characters, and returns Unicode text, line details, confidence/accuracy metrics, and visualizations. Separate model-training and vision-model comparison capabilities are also present. The graph follows the documented pipeline and sampled calls; some internal OCR details and comparison wiring are unsampled, so uncertain links are omitted.

Main entry points: [`ocr_pipeline.py`](https://github.com/girijesh-s001/palm-leaf-project/blob/main/ocr_pipeline.py) (OCR orchestrator), [`app.py`](https://github.com/girijesh-s001/palm-leaf-project/blob/main/app.py) (Flask API), [`Model/predict.py`](https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/predict.py) (Model inference), [`Model/dataset_loader.py`](https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/dataset_loader.py) (Dataset loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_api["Flask API<br/>[app.py]"]
  node_ui["Web page<br/>[index.html]"]
end

subgraph group_ocr["OCR processing"]
  node_orchestrator["OCR orchestrator<br/>[ocr_pipeline.py]"]
  node_paragraph["Paragraph crop<br/>[paragraph_seg.py]"]
  node_line["Line segmentation<br/>[line_seg.py]"]
  node_characters["Glyph segmentation<br/>[char_seg.py]"]
  node_result["OCR response<br/>[ocr_pipeline.py]"]
end

subgraph group_model["CNN recognition"]
  node_preprocess["Image preprocessing<br/>[preprocess.py]"]
  node_classifier["CNN classifier<br/>[cnn_model.py]"]
  node_prediction["Model inference<br/>[predict.py]"]
  node_training["Model training<br/>[train.py]"]
  node_data_loader["Dataset loader<br/>[dataset_loader.py]"]
  node_dataset[("Labeled glyph data")]
end

subgraph group_research["Model comparisons"]
  node_visualizations["CNN evaluation plots"]
  node_vlm["Vision-model evaluation<br/>[hf_vlm_models.py]"]
end

node_user(("Image submitter"))
node_external_models{{"External vision APIs"}}

node_user -->|"opens"| node_ui
node_user -->|"submits image"| node_api
node_ui -.->|"uses"| node_api
node_api -->|"calls OCR"| node_orchestrator
node_orchestrator -->|"optionally crops"| node_paragraph
node_orchestrator -->|"segments lines"| node_line
node_line -->|"uses glyph slicing"| node_characters
node_orchestrator -->|"refines glyphs"| node_characters
node_orchestrator -->|"prepares crops"| node_preprocess
node_orchestrator -->|"classifies batch"| node_prediction
node_prediction -->|"prepares image"| node_preprocess
node_prediction -->|"loads model"| node_classifier
node_orchestrator -->|"assembles text"| node_result
node_api -->|"returns JSON"| node_result
node_training -->|"loads samples"| node_data_loader
node_data_loader -->|"reads annotations and crops"| node_dataset
node_data_loader -->|"normalizes crops"| node_preprocess
node_training -->|"builds model"| node_classifier
node_visualizations -->|"loads evaluation data"| node_data_loader
node_visualizations -->|"loads predictions"| node_prediction
node_vlm -->|"uses preprocessing"| node_preprocess
node_vlm -.->|"optionally evaluates"| node_external_models

click node_api "https://github.com/girijesh-s001/palm-leaf-project/blob/main/app.py"
click node_ui "https://github.com/girijesh-s001/palm-leaf-project/blob/main/templates/index.html"
click node_orchestrator "https://github.com/girijesh-s001/palm-leaf-project/blob/main/ocr_pipeline.py"
click node_paragraph "https://github.com/girijesh-s001/palm-leaf-project/blob/main/LINE_SEG/paragraph_seg.py"
click node_line "https://github.com/girijesh-s001/palm-leaf-project/blob/main/LINE_SEG/line_seg.py"
click node_characters "https://github.com/girijesh-s001/palm-leaf-project/blob/main/LINE_SEG/char_seg.py"
click node_result "https://github.com/girijesh-s001/palm-leaf-project/blob/main/ocr_pipeline.py"
click node_preprocess "https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/preprocess.py"
click node_classifier "https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/cnn_model.py"
click node_prediction "https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/predict.py"
click node_training "https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/train.py"
click node_data_loader "https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/dataset_loader.py"
click node_dataset "https://github.com/girijesh-s001/palm-leaf-project/tree/main/dataset"
click node_visualizations "https://github.com/girijesh-s001/palm-leaf-project/blob/main/cnn_baseline_visualizations.py"
click node_vlm "https://github.com/girijesh-s001/palm-leaf-project/blob/main/hf_vlm_models.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api,node_ui toneBlue
class node_orchestrator,node_paragraph,node_line,node_characters,node_result toneAmber
class node_preprocess,node_classifier,node_prediction,node_training,node_data_loader,node_dataset,node_external_models toneMint
class node_visualizations,node_vlm toneRose
class node_user toneIndigo
```

## Components

### Web interface

- [Flask API](https://github.com/girijesh-s001/palm-leaf-project/blob/main/app.py): `app.py`
- [Web page](https://github.com/girijesh-s001/palm-leaf-project/blob/main/templates/index.html): `templates/index.html`

### OCR processing

- [OCR orchestrator](https://github.com/girijesh-s001/palm-leaf-project/blob/main/ocr_pipeline.py): `ocr_pipeline.py`
- [Paragraph crop](https://github.com/girijesh-s001/palm-leaf-project/blob/main/LINE_SEG/paragraph_seg.py): `LINE_SEG/paragraph_seg.py`
- [Line segmentation](https://github.com/girijesh-s001/palm-leaf-project/blob/main/LINE_SEG/line_seg.py): `LINE_SEG/line_seg.py`
- [Glyph segmentation](https://github.com/girijesh-s001/palm-leaf-project/blob/main/LINE_SEG/char_seg.py): `LINE_SEG/char_seg.py`
- [OCR response](https://github.com/girijesh-s001/palm-leaf-project/blob/main/ocr_pipeline.py): `ocr_pipeline.py`

### CNN recognition

- [Image preprocessing](https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/preprocess.py): `Model/preprocess.py`
- [CNN classifier](https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/cnn_model.py): `Model/cnn_model.py`
- [Model inference](https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/predict.py): `Model/predict.py`
- [Model training](https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/train.py): `Model/train.py`
- [Dataset loader](https://github.com/girijesh-s001/palm-leaf-project/blob/main/Model/dataset_loader.py): `Model/dataset_loader.py`
- [Labeled glyph data](https://github.com/girijesh-s001/palm-leaf-project/tree/main/dataset): `dataset`

### Model comparisons

- [CNN evaluation plots](https://github.com/girijesh-s001/palm-leaf-project/blob/main/cnn_baseline_visualizations.py): `cnn_baseline_visualizations.py`
- [Vision-model evaluation](https://github.com/girijesh-s001/palm-leaf-project/blob/main/hf_vlm_models.py): `hf_vlm_models.py`

### Other components

- **Image submitter**
- **External vision APIs**

## Connections

- Image submitter → Web page: opens (evidence: `README.md`)
- Image submitter → Flask API: submits image (evidence: `app.py`)
- Web page → Flask API: uses
- Flask API → OCR orchestrator: calls OCR (evidence: `app.py`)
- OCR orchestrator → Paragraph crop: optionally crops (evidence: `ocr_pipeline.py`)
- OCR orchestrator → Line segmentation: segments lines (evidence: `ocr_pipeline.py`)
- Line segmentation → Glyph segmentation: uses glyph slicing (evidence: `LINE_SEG/line_seg.py`)
- OCR orchestrator → Glyph segmentation: refines glyphs (evidence: `ocr_pipeline.py`)
- OCR orchestrator → Image preprocessing: prepares crops (evidence: `ocr_pipeline.py`)
- OCR orchestrator → Model inference: classifies batch (evidence: `ocr_pipeline.py`)
- Model inference → Image preprocessing: prepares image (evidence: `Model/predict.py`)
- Model inference → CNN classifier: loads model (evidence: `Model/predict.py`)
- OCR orchestrator → OCR response: assembles text (evidence: `ocr_pipeline.py`)
- Flask API → OCR response: returns JSON (evidence: `app.py`)
- Model training → Dataset loader: loads samples (evidence: `Model/train.py`)
- Dataset loader → Labeled glyph data: reads annotations and crops (evidence: `Model/dataset_loader.py`)
- Dataset loader → Image preprocessing: normalizes crops (evidence: `Model/dataset_loader.py`)
- Model training → CNN classifier: builds model (evidence: `Model/train.py`)
- CNN evaluation plots → Dataset loader: loads evaluation data (evidence: `cnn_baseline_visualizations.py`)
- CNN evaluation plots → Model inference: loads predictions (evidence: `cnn_baseline_visualizations.py`)
- Vision-model evaluation → Image preprocessing: uses preprocessing (evidence: `hf_vlm_models.py`)
- Vision-model evaluation → External vision APIs: optionally evaluates (evidence: `hf_vlm_models.py`)
