# aniketshinde8483/yolov8_streamlit_safety-detection architecture

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

- Interactive diagram: https://gitdiagram.com/aniketshinde8483/yolov8_streamlit_safety-detection
- Repository: https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection

## Overview

##### Project type and purpose
- This is a single‐service, full-stack (monolithic) Streamlit application for YOLOv8‐based object detection.
- Purpose: Load a pre-trained YOLOv8 model (.pt file), accept image/video/webcam streams, perform inference, and render/display the annotated results in the browser (and optionally save to disk).

##### File structure
- Top-level files:
– app.py: Streamlit entrypoint (defines UI layout, handles user input, orchestrates model inference).
– settings.py: Configuration constants (paths, parameters such as confidence thresholds, default camera settings).
– best_150.pt (weights): The YOLOv8 model.
– requirements.txt / packages.txt: Python dependencies.
– outputs/: Directory where processed videos/images are saved.
– test_img_video/: Example media assets for manual testing.
– .devcontainer/: Docker/VSCode-DevContainer configuration for reproducible development environment.

##### README for additional insights
- Describes three use cases: image, video, live webcam object detection.
- Instructs to place model in weights/best.pt (in practice your repo uses best_150.pt).
- Entrypoint is `streamlit run app.py`.

##### Main components and relationships
a. Streamlit UI Layer (app.py)
– User selects input type (upload image, upload video, or webcam).
– UI widgets trigger controller logic.
b. Controller / Orchestration (app.py & settings.py)
– Reads settings, dispatches to the appropriate pipeline: image, video, or live.
c. Inference Engine
– Model Loader (loads best_150.pt via Ultralytics YOLOv8 API).
– Preprocessing Module (in helper.py: resizing, normalization).
– Inference Module (runs model.predict).
d. Storage & Artifacts
– Input Sources: Uploaded files or webcam stream.
– Output Sink: Annotated frames written to outputs/ (images or video).
– Temporary in-memory buffers for streaming.
e. Development Infrastructure
– .devcontainer (Dockerfile or devcontainer.json) for environment setup.
– requirements.txt for pip environment.

##### Architectural patterns and tech stack
- Pattern: Simple MVC-like separation
– View = Streamlit front end
– Controller = Main app logic in app.py
– Model = YOLOv8 model + helper functions
- Tech / Libraries:
– Python 3.x, Streamlit, Ultralytics YOLOv8, OpenCV or PIL for image/video I/O, ffmpeg (if video encoding), Docker (devcontainer).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External User
    User["User"]:::external

    %% Input Sources
    subgraph "Inputs" 
        direction TB
        ExampleMedia["Example Media\n(test_img_video/)"]:::storage
        Webcam["Webcam Stream"]:::external
    end

    %% UI Layer
    subgraph "UI / Streamlit" 
        direction TB
        StreamlitUI["Streamlit UI\n(app.py)"]:::frontend
    end

    %% Controller & Settings
    subgraph "Controller & Settings"
        direction TB
        Controller["Controller Logic\n(app.py)"]:::frontend
        Settings["Settings\n(settings.py)"]:::frontend
    end

    %% Inference Engine
    subgraph "Inference Engine"
        direction TB
        ModelLoader["Model Loader\n(helper.py)"]:::compute
        Weights["YOLOv8 Weights\n(best_150.pt)"]:::compute
        Preprocessing["Preprocessing\n(helper.py)"]:::compute
        Inference["Inference Module\n(helper.py)"]:::compute
        Postprocessing["Postprocessing\n(helper.py)"]:::compute
    end

    %% Storage / Outputs
    subgraph "Storage / Outputs"
        direction TB
        Outputs["Annotated Outputs\n(outputs/)"]:::storage
    end

    %% Dev Infrastructure
    subgraph "Dev Infrastructure"
        direction TB
        DevContainer["DevContainer Config\n(.devcontainer/devcontainer.json)"]:::infra
        Requirements["Requirements\n(requirements.txt\npackages.txt)"]:::infra
    end

    %% Data Flows
    User -->|selects input| StreamlitUI
    ExampleMedia -->|upload file| StreamlitUI
    Webcam -->|live stream| StreamlitUI

    StreamlitUI -->|triggers| Controller
    Settings -->|provides config| Controller

    Controller -->|load model| ModelLoader
    ModelLoader -->|loads weights| Weights
    ModelLoader -->|provide model| Preprocessing
    Preprocessing -->|processed data| Inference
    Inference -->|predictions| Postprocessing
    Postprocessing -->|render results| StreamlitUI
    Postprocessing -->|save files| Outputs

    DevContainer -->|environment| StreamlitUI
    Requirements -->|dependencies| StreamlitUI

    %% Click Events
    click StreamlitUI "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/app.py"
    click Controller "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/app.py"
    click Settings "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/settings.py"
    click ModelLoader "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/helper.py"
    click Preprocessing "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/helper.py"
    click Inference "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/helper.py"
    click Postprocessing "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/helper.py"
    click Weights "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/best_150.pt"
    click Outputs "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/tree/main/outputs/"
    click ExampleMedia "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/tree/main/test_img_video/"
    click DevContainer "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/.devcontainer/devcontainer.json"
    click Requirements "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/requirements.txt"
    click Requirements "https://github.com/aniketshinde8483/yolov8_streamlit_safety-detection/blob/main/packages.txt"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#3182BD,stroke-width:1px;
    classDef compute fill:#DFF5D1,stroke:#2F8F00,stroke-width:1px;
    classDef storage fill:#FFF4C1,stroke:#D4A017,stroke-width:1px;
    classDef infra fill:#E0E0E0,stroke:#6E6E6E,stroke-width:1px;
    classDef external fill:#F0F0F0,stroke:#999999,stroke-width:1px,stroke-dasharray: 2 2;
```
