# debasmitabose0/debai architecture

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

- Interactive diagram: https://gitdiagram.com/debasmitabose0/debai
- Repository: https://github.com/debasmitabose0/debai

## Overview

DebAI is a single-module Streamlit assistant for document extraction and contextual chat. Users upload images or PDFs, review extracted text, and ask questions; OCR text joins the chat session before model inference, and the conversation can be exported as a PDF. The README also describes image preprocessing, language-aware OCR, Ollama/Gemini inference, theme switching, and hotkeys. These capabilities share AI.py rather than separate modules; links for unsampled implementation details are based on README documentation.

Main entry points: [`AI.py`](https://github.com/debasmitabose0/debai/blob/main/AI.py) (Chat session)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App and chat"]
  node_streamlit["Streamlit app<br/>[AI.py]"]
  node_chat_session["Chat session<br/>[AI.py]"]
end

subgraph group_documents["Document processing"]
  node_image_input["Image upload<br/>[AI.py]"]
  node_pdf_input["PDF upload<br/>[AI.py]"]
  node_preprocess["Image preprocessing<br/>[AI.py]"]
  node_pdf_extract["PDF extraction<br/>[AI.py]"]
  node_ocr["OCR engine<br/>[AI.py]"]
  node_language["Language detection<br/>[AI.py]"]
end

subgraph group_inference["AI inference"]
  node_inference["Model selection<br/>[AI.py]"]
  node_ollama{{"Ollama"}}
  node_gemini{{"Google Gemini"}}
  node_response["Assistant response<br/>[AI.py]"]
end

subgraph group_presentation["Presentation and export"]
  node_theme["Theme and hotkeys<br/>[AI.py]"]
  node_pdf_export["PDF report export<br/>[AI.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_streamlit
node_streamlit -->|"accepts upload"| node_image_input
node_streamlit -->|"accepts upload"| node_pdf_input
node_image_input -->|"preprocesses"| node_preprocess
node_preprocess -->|"provides image"| node_ocr
node_pdf_input -->|"extracts text"| node_pdf_extract
node_pdf_extract -->|"adds context"| node_chat_session
node_ocr -->|"detects language"| node_language
node_language -->|"selects OCR language"| node_ocr
node_ocr -->|"adds context"| node_chat_session
node_user -->|"submits prompt"| node_chat_session
node_chat_session -->|"sends prompt"| node_inference
node_inference -->|"uses local model"| node_ollama
node_inference -.->|"falls back"| node_gemini
node_inference -->|"returns answer"| node_response
node_response -->|"renders response"| node_streamlit
node_user -->|"switches theme"| node_theme
node_user -->|"requests report"| node_pdf_export
node_pdf_export -->|"exports history"| node_chat_session

click node_streamlit "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_chat_session "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_image_input "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_pdf_input "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_preprocess "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_pdf_extract "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_ocr "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_language "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_inference "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_response "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_theme "https://github.com/debasmitabose0/debai/blob/main/AI.py"
click node_pdf_export "https://github.com/debasmitabose0/debai/blob/main/AI.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_streamlit,node_chat_session,node_user toneBlue
class node_image_input,node_pdf_input,node_preprocess,node_pdf_extract,node_ocr,node_language toneAmber
class node_inference,node_ollama,node_gemini,node_response toneMint
class node_theme,node_pdf_export toneRose
```

## Components

### App and chat

- [Streamlit app](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- [Chat session](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`

### Document processing

- [Image upload](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- [PDF upload](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- [Image preprocessing](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- [PDF extraction](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- [OCR engine](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- [Language detection](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`

### AI inference

- [Model selection](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- **Ollama**
- **Google Gemini**
- [Assistant response](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`

### Presentation and export

- [Theme and hotkeys](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`
- [PDF report export](https://github.com/debasmitabose0/debai/blob/main/AI.py): `AI.py`

### Other components

- **User**

## Connections

- User → Streamlit app: uses (evidence: `README.md`)
- Streamlit app → Image upload: accepts upload (evidence: `README.md`)
- Streamlit app → PDF upload: accepts upload (evidence: `README.md`)
- Image upload → Image preprocessing: preprocesses (evidence: `README.md`)
- Image preprocessing → OCR engine: provides image (evidence: `README.md`)
- PDF upload → PDF extraction: extracts text (evidence: `README.md`)
- PDF extraction → Chat session: adds context (evidence: `README.md`)
- OCR engine → Language detection: detects language (evidence: `README.md`)
- Language detection → OCR engine: selects OCR language (evidence: `README.md`)
- OCR engine → Chat session: adds context (evidence: `README.md`)
- User → Chat session: submits prompt (evidence: `README.md`)
- Chat session → Model selection: sends prompt (evidence: `README.md`)
- Model selection → Ollama: uses local model (evidence: `README.md`)
- Model selection → Google Gemini: falls back (evidence: `README.md`)
- Model selection → Assistant response: returns answer (evidence: `AI.py`)
- Assistant response → Streamlit app: renders response (evidence: `README.md`)
- User → Theme and hotkeys: switches theme (evidence: `README.md`)
- User → PDF report export: requests report (evidence: `README.md`)
- PDF report export → Chat session: exports history (evidence: `README.md`)
