# worknestmajor/impression-generation-from-xray-images architecture

> Architecture diagram of the GitHub repository worknestmajor/impression-generation-from-xray-images, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/worknestmajor/impression-generation-from-xray-images
- Repository: https://github.com/worknestmajor/impression-generation-from-xray-images

## Overview

##### Project type and purpose
- This is a machine-learning application that automates generation of the “impression” section of chest X-ray medical reports.
- It consists of two main phases: a model-training pipeline (`create_model.py`) and a lightweight inference/serving UI (`final.py` built on Streamlit).
- It uses chest X-ray images + XML reports (Indiana University dataset) to train a deep learning model and then exposes the model for interactive demo.

##### File structure
Top-level files and folders:
- README.md         ← project description, demo link
- requirements.txt  ← Python dependencies
- create_model.py   ← data preprocessing & model training script
- final.py          ← Streamlit app for inference
- tokenizer.pkl     ← saved text tokenizer for report generation
- test_images/1–4   ← sample images to feed into the demo
- __pycache__/      ← Python bytecode cache

Patterns & hints:
- Single-repository, two logical components (train vs. serve)
- No separate “backend” or “frontend” folders, but clear separation by script
- No external databases; data lives in local filesystem

##### README for additional insights
- Purpose: reduce clinician time by auto-writing report impressions
- Demo hosted via Streamlit badge
- No mention of heavy infra (e.g., Kubernetes), so assume local or simple cloud deployment

##### Detailed capture of essential elements
- If desired, note external pre-trained backbones (e.g., ResNet) used inside create_model.py.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Training Pipeline
    subgraph "Training Pipeline"
        direction TB
        A["Raw Data (Chest X-ray Images + XML Reports)"]:::data
        B["Preprocessing"]:::process
        C["Model Training"]:::process
        D(("Model Weights")):::artifact
        E(("tokenizer.pkl")):::artifact
    end

    %% Inference Pipeline
    subgraph "Inference Pipeline"
        direction TB
        F["Streamlit UI (final.py)"]:::ui
        G["Load Model Weights + tokenizer.pkl"]:::process
        H["Upload/Select Test Image"]:::data
        I["Image Preprocessing"]:::process
        J["Generate Impression Text"]:::process
        K["Display Report"]:::ui
    end

    %% Dependencies & Project Info
    subgraph "Repository & Environment"
        direction TB
        L["requirements.txt"]:::env
        M["README.md"]:::doc
    end

    %% Sample Data
    subgraph "Sample Data"
        direction TB
        N["test_images/"]:::data
    end

    %% Connections Training
    A -->|"feed into"| B
    B -->|"prepared data"| C
    C -->|"saves"| D
    C -->|"saves"| E

    %% Handoff
    D -->|"model weights + tokenizer.pkl"| G
    E --> G

    %% Inference flow
    H -->|"input image"| I
    I -->|"processed image"| G
    G -->|"runs inference"| J
    J -->|"result"| K

    %% UI start
    F --> H
    F --> K

    %% Dependencies connections
    L --> B
    L --> I
    L --> F
    M --> F

    %% Sample Data usage
    N --> H

    %% Click Events
    click B "https://github.com/worknestmajor/impression-generation-from-xray-images/blob/main/create_model.py"
    click C "https://github.com/worknestmajor/impression-generation-from-xray-images/blob/main/create_model.py"
    click E "https://github.com/worknestmajor/impression-generation-from-xray-images/blob/main/tokenizer.pkl"
    click F "https://github.com/worknestmajor/impression-generation-from-xray-images/blob/main/final.py"
    click N "https://github.com/worknestmajor/impression-generation-from-xray-images/tree/main/test_images/"
    click L "https://github.com/worknestmajor/impression-generation-from-xray-images/blob/main/requirements.txt"
    click M "https://github.com/worknestmajor/impression-generation-from-xray-images/blob/main/README.md"

    %% Styles
    classDef process fill:#d4f1be,stroke:#2d572c,stroke-width:1px
    classDef data fill:#cde7f0,stroke:#1a5276,stroke-width:1px
    classDef artifact fill:#f7d6a5,stroke:#b35f00,stroke-width:1px
    classDef ui fill:#e8d4f8,stroke:#6a1b9a,stroke-width:1px
    classDef env fill:#e0e0e0,stroke:#424242,stroke-width:1px
    classDef doc fill:#f0f0f0,stroke:#333333,stroke-width:1px
```
