# shreya0119/old-kannada-restorer architecture

> Architecture diagram of the GitHub repository shreya0119/old-kannada-restorer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shreya0119/old-kannada-restorer
- Repository: https://github.com/shreya0119/old-kannada-restorer

## Overview

#### Purpose and Entry Point
This is a Streamlit application for restoring one masked word in transliterated Old Kannada inscriptions and predicting dynasty/date ranges. `app.py` is the interactive entry point, exposing verified evaluation mode, free-text mode, and precomputed evaluation results.

#### Curated Corpus Boundary
The application is driven by a small, committed reference corpus rather than a database or trained model. `data/curated_inscriptions.json` contains verified inscription text plus dynasty and date metadata. Runtime behavior treats this corpus as the in-context example pool; changes require regenerating `results/eval_results.json`.

#### Restoration Pipeline
Masked-inscription restoration is orchestrated in `src/restore.py`. It accepts text containing a marked gap, selects supplied reference examples, builds a constrained LLM request through `src/prompts.py`, and parses ranked JSON candidates from the response. The output supports up to three candidates and associated reasoning.

#### Dynasty and Date Attribution
`src/dynasty.py` runs a parallel inference path for dynasty and date-range prediction. It uses the same curated examples and prompt-based reference pattern, but targets historical attribution rather than missing-word recovery. Restoration and attribution are separate model tasks surfaced together by `app.py`.

#### Prompt and Model Boundary
`src/prompts.py` defines the structured few-shot and zero-shot prompt contracts, including strict JSON-oriented response expectations. `src/llm_client.py` is the provider boundary: it reads API credentials from environment variables and performs multi-provider Gemini/Groq failover. No local model training, OCR pipeline, or persistent service is required at runtime.

#### Evaluation and Baseline
`scripts/evaluate.py` performs leave-one-out testing over the curated corpus: it masks a selected eligible word, compares frequency baseline, zero-shot LLM, and few-shot LLM outputs, then writes aggregate metrics to `results/eval_results.json`. `src/baseline.py` supplies the context-free word-frequency comparator. Text normalization and matching behavior are centralized in `src/text_utils.py`.

#### Primary Control Flows
In verified mode, `app.py` chooses an inscription, masks an eligible token, retains ground truth, calls restoration and dynasty prediction with the remaining corpus as examples, and scores/display results. In free-text mode, user-provided masked text is sent to the same inference layers using all curated entries as references; outputs are explicitly unverified. The external dependencies are Streamlit, Gemini/Groq APIs, and locally committed corpus/results artifacts.

Main entry points: [`scripts/evaluate.py`](https://github.com/shreya0119/old-kannada-restorer/blob/main/scripts/evaluate.py) (Leave-one-out evaluation), [`src/restore.py`](https://github.com/shreya0119/old-kannada-restorer/blob/main/src/restore.py) (Restoration orchestration), [`data/curated_inscriptions.json`](https://github.com/shreya0119/old-kannada-restorer/blob/main/data/curated_inscriptions.json) (Curated inscriptions), [`app.py`](https://github.com/shreya0119/old-kannada-restorer/blob/main/app.py) (Streamlit app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Streamlit UI"]
  node_app["Streamlit app<br/>interactive entry point<br/>[app.py]"]
end

subgraph group_corpus["Reference Data"]
  node_corpus_data[("Curated inscriptions<br/>committed corpus")]
end

subgraph group_inference["LLM Inference"]
  node_restore["Restoration orchestration<br/>restoration pipeline<br/>[restore.py]"]
  node_dynasty["Dynasty/date inference<br/>attribution pipeline<br/>[dynasty.py]"]
  node_prompts["Prompt contracts<br/>few-shot prompts<br/>[prompts.py]"]
  node_llm_client{{"Provider client<br/>LLM gateway<br/>[llm_client.py]"}}
  node_gemini_groq{{"Gemini / Groq APIs<br/>external LLM providers"}}
  node_text_utils["Text normalization<br/>matching utilities<br/>[text_utils.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluate["Leave-one-out evaluation<br/>evaluation script<br/>[evaluate.py]"]
  node_baseline["Frequency baseline<br/>context-free baseline<br/>[baseline.py]"]
  node_eval_results["Evaluation results<br/>precomputed metrics<br/>[eval_results.json]"]
end

node_app -->|"loads entries"| node_corpus_data
node_app -->|"restores masked text"| node_restore
node_app -->|"attributes history"| node_dynasty
node_app -->|"displays metrics"| node_eval_results
node_restore -->|"selects references"| node_corpus_data
node_restore -->|"builds request"| node_prompts
node_restore -->|"normalizes candidates"| node_text_utils
node_dynasty -->|"uses references"| node_corpus_data
node_dynasty -->|"builds request"| node_prompts
node_prompts -->|"structured request"| node_llm_client
node_llm_client -->|"provider failover"| node_gemini_groq
node_evaluate -->|"leave-one-out inputs"| node_corpus_data
node_evaluate -->|"few-shot comparison"| node_restore
node_evaluate -->|"frequency comparison"| node_baseline
node_evaluate -->|"zero-shot comparison"| node_prompts
node_evaluate -->|"scores matches"| node_text_utils
node_evaluate -->|"writes metrics"| node_eval_results
node_corpus_data -.->|"changes require regeneration"| node_eval_results

click node_app "https://github.com/shreya0119/old-kannada-restorer/blob/main/app.py"
click node_corpus_data "https://github.com/shreya0119/old-kannada-restorer/blob/main/data/curated_inscriptions.json"
click node_restore "https://github.com/shreya0119/old-kannada-restorer/blob/main/src/restore.py"
click node_dynasty "https://github.com/shreya0119/old-kannada-restorer/blob/main/src/dynasty.py"
click node_prompts "https://github.com/shreya0119/old-kannada-restorer/blob/main/src/prompts.py"
click node_llm_client "https://github.com/shreya0119/old-kannada-restorer/blob/main/src/llm_client.py"
click node_text_utils "https://github.com/shreya0119/old-kannada-restorer/blob/main/src/text_utils.py"
click node_evaluate "https://github.com/shreya0119/old-kannada-restorer/blob/main/scripts/evaluate.py"
click node_baseline "https://github.com/shreya0119/old-kannada-restorer/blob/main/src/baseline.py"
click node_eval_results "https://github.com/shreya0119/old-kannada-restorer/blob/main/results/eval_results.json"

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_app toneBlue
class node_corpus_data toneAmber
class node_restore,node_dynasty,node_prompts,node_llm_client,node_gemini_groq,node_text_utils toneMint
class node_evaluate,node_baseline,node_eval_results toneRose
```

## Components

### Streamlit UI

- [Streamlit app](https://github.com/shreya0119/old-kannada-restorer/blob/main/app.py): interactive entry point · Provides verified, free-text, and results views. · `app.py`

### Reference Data

- [Curated inscriptions](https://github.com/shreya0119/old-kannada-restorer/blob/main/data/curated_inscriptions.json): committed corpus · Verified text with dynasty and date metadata. · `data/curated_inscriptions.json`

### LLM Inference

- [Restoration orchestration](https://github.com/shreya0119/old-kannada-restorer/blob/main/src/restore.py): restoration pipeline · Selects examples and returns ranked missing-word candidates. · `src/restore.py`
- [Dynasty/date inference](https://github.com/shreya0119/old-kannada-restorer/blob/main/src/dynasty.py): attribution pipeline · Predicts dynasty and date range independently of restoration. · `src/dynasty.py`
- [Prompt contracts](https://github.com/shreya0119/old-kannada-restorer/blob/main/src/prompts.py): few-shot prompts · Builds constrained structured JSON requests. · `src/prompts.py`
- [Provider client](https://github.com/shreya0119/old-kannada-restorer/blob/main/src/llm_client.py): LLM gateway · Uses environment credentials with Gemini/Groq failover. · `src/llm_client.py`
- **Gemini / Groq APIs**: external LLM providers
- [Text normalization](https://github.com/shreya0119/old-kannada-restorer/blob/main/src/text_utils.py): matching utilities · Centralizes normalization and comparison behavior. · `src/text_utils.py`

### Evaluation

- [Leave-one-out evaluation](https://github.com/shreya0119/old-kannada-restorer/blob/main/scripts/evaluate.py): evaluation script · Masks eligible words and compares restoration approaches. · `scripts/evaluate.py`
- [Frequency baseline](https://github.com/shreya0119/old-kannada-restorer/blob/main/src/baseline.py): context-free baseline · `src/baseline.py`
- [Evaluation results](https://github.com/shreya0119/old-kannada-restorer/blob/main/results/eval_results.json): precomputed metrics · Regenerated when the curated corpus changes. · `results/eval_results.json`

## Connections

- Streamlit app → Curated inscriptions: loads entries
- Streamlit app → Restoration orchestration: restores masked text
- Streamlit app → Dynasty/date inference: attributes history
- Streamlit app → Evaluation results: displays metrics
- Restoration orchestration → Curated inscriptions: selects references
- Restoration orchestration → Prompt contracts: builds request
- Restoration orchestration → Text normalization: normalizes candidates
- Dynasty/date inference → Curated inscriptions: uses references
- Dynasty/date inference → Prompt contracts: builds request
- Prompt contracts → Provider client: structured request
- Provider client → Gemini / Groq APIs: provider failover
- Leave-one-out evaluation → Curated inscriptions: leave-one-out inputs
- Leave-one-out evaluation → Restoration orchestration: few-shot comparison
- Leave-one-out evaluation → Frequency baseline: frequency comparison
- Leave-one-out evaluation → Prompt contracts: zero-shot comparison
- Leave-one-out evaluation → Text normalization: scores matches
- Leave-one-out evaluation → Evaluation results: writes metrics
- Curated inscriptions → Evaluation results: changes require regeneration
