# akshwin/intracranial_haemorrghe_detection architecture

> Architecture diagram of the GitHub repository akshwin/intracranial_haemorrghe_detection, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/akshwin/intracranial_haemorrghe_detection
- Repository: https://github.com/akshwin/intracranial_haemorrghe_detection

## Overview

##### Project Type and Purpose
- This is a single-page Streamlit application for deep-learning inference.
- Purpose: allow users to upload CT scan images and instantly receive a hemorrhage/no-hemorrhage prediction using a pre-trained Keras model (ich.h5).

##### File Structure
- app.py – the main application script (UI + inference logic).
- ich.h5 – the pre-trained Keras model file.
- requirements.txt – lists Streamlit, Pillow, NumPy, TensorFlow dependencies.
- upload_image/ – (if present) may hold sample images or utility scripts.
- README.md, .gitignore, LICENSE – documentation and metadata.

##### Extract Insights from README
- UI built with Streamlit – file uploader, buttons, display elements.
- Model inference uses TensorFlow/Keras.
- Input types: JPG, JPEG, PNG.
- No external databases or microservices – self-contained.

##### Main Components
a. User Interface Layer
– Streamlit Web App (app.py)
– FileUploader widget
– Result display (text + balloons)
b. Preprocessing Module
– Image loading (Pillow)
– Resizing/normalization (NumPy)
c. Inference Engine
– Keras/TensorFlow model loader (ich.h5)
– Prediction function
d. Model Artifact
– ich.h5 stored on disk
e. Hosting/Runtime
– Local/Streamlit Cloud server environment
– Python runtime

##### Relationships and Data Flow
- User clicks “Upload” → Streamlit UI reads file
- UI passes raw image to Preprocessing Module
- Preprocessing outputs an array to Inference Engine
- Inference Engine loads ich.h5 (on first run or cached) → returns prediction
- UI consumes prediction → displays result and balloons or error
- All steps occur within the same process, no external API calls

##### Architectural Patterns & Design Principles
- Monolithic single-process design – UI and inference co-located
- Lazy loading & caching of model to optimize performance
- Separation of concerns: clearly delineate UI, preprocessing, inference

##### Technologies & Libraries
- Streamlit – UI framework
- Python 3.x – runtime
- Pillow – image I/O
- NumPy – numerical processing
- TensorFlow/Keras – deep learning inference

##### Elements
- Component names and brief descriptions
- Arrowheads indicating request/response or data transformation flow

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interaction
    User["User"]:::ui

    %% Application Components
    StreamlitUI["Streamlit UI\n(app.py)"]:::ui
    Preprocessing["Preprocessing Module\n(Pillow & NumPy)"]:::processing
    Inference["Inference Engine\n(Keras/TensorFlow)"]:::processing
    Model["Model Artifact\n(ich.h5)"]:::model

    %% Hosting and Dependencies
    Hosting["Hosting Environment\n(Streamlit Cloud / Python Runtime)"]:::hosting
    Dependencies["Dependencies\n(requirements.txt)"]:::docs

    %% Project Files
    subgraph "Project Files"
        SampleImages["Sample/Utility Images\n(upload_image/)"]:::docs
        README["README.md"]:::docs
        LICENSE["LICENSE"]:::docs
        Gitignore[".gitignore"]:::docs
    end

    %% Data Flow
    User -->|"uploads image"| StreamlitUI
    StreamlitUI -->|"raw image"| Preprocessing
    Preprocessing -->|"array"| Inference
    Inference -->|"loads model & predicts"| Model
    Inference -->|"prediction result"| StreamlitUI
    StreamlitUI -->|"display result"| User

    %% Hosting Dependencies
    Hosting --> StreamlitUI
    Hosting --> Preprocessing
    Hosting --> Inference

    %% Library Dependencies
    StreamlitUI --> Dependencies
    Preprocessing --> Dependencies
    Inference --> Dependencies

    %% Click Events
    click StreamlitUI "https://github.com/akshwin/intracranial_haemorrghe_detection/blob/main/app.py"
    click Preprocessing "https://github.com/akshwin/intracranial_haemorrghe_detection/blob/main/app.py"
    click Inference "https://github.com/akshwin/intracranial_haemorrghe_detection/blob/main/app.py"
    click Model "https://github.com/akshwin/intracranial_haemorrghe_detection/blob/main/ich.h5"
    click Dependencies "https://github.com/akshwin/intracranial_haemorrghe_detection/blob/main/requirements.txt"
    click SampleImages "https://github.com/akshwin/intracranial_haemorrghe_detection/tree/main/upload_image/"
    click README "https://github.com/akshwin/intracranial_haemorrghe_detection/blob/main/README.md"
    click LICENSE "https://github.com/akshwin/intracranial_haemorrghe_detection/tree/main/LICENSE"
    click Gitignore "https://github.com/akshwin/intracranial_haemorrghe_detection/blob/main/.gitignore"

    %% Styles
    classDef ui fill:#D6E7FF,stroke:#3B78FF;
    classDef processing fill:#DFFFE0,stroke:#2E892E;
    classDef model fill:#FFE5CC,stroke:#FF8C00;
    classDef hosting fill:#E0E0E0,stroke:#A0A0A0;
    classDef docs fill:#FFF5CC,stroke:#D6AD00;
```
