# sefaburakokcu/autodetectify architecture

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

- Interactive diagram: https://gitdiagram.com/sefaburakokcu/autodetectify
- Repository: https://github.com/sefaburakokcu/autodetectify

## Overview

##### Project Type and Purpose
- Type: A full-stack, single‐page web app (no separate HTTP server/process) built on Streamlit.
- Purpose:
- Compare multiple zero‐shot object detection prompts side by side on user-uploaded images.
- Auto-label images with a chosen prompt and export labels in YOLOv5, YOLOv8, or COCO formats.

##### File Structure
- Top level:
- assets/ (static UI images)
- inputs/ (user or demo images)
- requirements.txt (dependencies: Streamlit, transformers, streamlit-image-comparison, etc.)
- Core ML code:
- autodetectify/models/zero_shot_detection/models.py → implements prompt handling & inference using HuggingFace transformers.
- UI code:
- ui/🤗_Home.py → entry point (Streamlit “Home” page)
- ui/pages/1_👀_Compare_Prompts.py → “Prompt Comparison” page
- ui/pages/2_📥_Autolabel_Images.py → “Auto-Label & Export” page
- ui/ui_utils.py → shared helpers (file uploaders, progress bars, export utilities)

##### Key README Insights
- Two main user flows: Prompt Comparison and Auto-Label + Export
- Supports up to 50 images or ZIP uploads
- Exports in multiple dataset formats
- Relies on streamlit-image-comparison for visual diff, HuggingFace transformers for zero-shot detection

##### Main Components & Their Relationships

A. User Interface Layer (Streamlit)
- HomePage Component
- ComparePromptsPage Component
- AutolabelPage Component
- UIUtils Module

B. Application Logic Layer
- InputHandler
– Receives image uploads (single/join ZIP)
– Saves into inputs/ folder (in-memory or temp)
- PromptManager
– Accepts user prompts (strings)
– Passes them to the inference engine
- InferenceEngine (ZeroShotDetector)
– Loads model from autodetectify/models/...
– Calls HuggingFace transformer pipeline
- ComparisonService
– Takes two or more inference results
– Uses streamlit-image-comparison widget for side-by-side display
- AutoLabelService
– Processes batch inference
– Applies chosen prompt across all images
- ExportService
– Converts results into YOLOv5, YOLOv8, COCO formats
– Packages into a downloadable ZIP

C. Data Layer
- Raw Images Store (inputs/ or in-memory stream)
- Processed Results (in-memory objects → visual display)
- Exported Dataset Files (written to disk/ZIP)

D. External Dependencies & Services
- HuggingFace Transformers (zero-shot models)
- streamlit-image-comparison widget
- Local File System (for assets, inputs, exports)

##### Architectural Patterns & Design Principles
- Modular separation of concerns: UI vs business logic vs data handling
- Stateless request handling: each user action triggers a fresh Streamlit “run”
- Single process (Streamlit) but logically layered
- Reusable utilities (ui_utils, ExportService) for consistent behavior

1. User & Browser
2. Streamlit UI Layer
3. Application Logic Layer
4. Data & External Services Layer
- Use rectangles for modules (e.g., ComparePromptsPage)
- User → UI (uploads images, types prompts)
- UI → InputHandler → Raw Images Store
- UI → InferenceEngine → HuggingFace → InferenceEngine → UI
- UI → ComparisonService → Display
- AutolabelPage → AutoLabelService → ExportService → Disk/ZIP → UI (download link)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Layer 1: User
    User["User & Browser"]:::user

    %% Layer 2: Streamlit UI Layer
    subgraph "Streamlit UI Layer"
        HomePage["HomePage"]:::ui
        ComparePage["ComparePromptsPage"]:::ui
        AutoLabelPage["AutolabelPage"]:::ui
        UIUtils["UIUtils Module"]:::ui
    end

    %% Layer 3: Application Logic Layer
    subgraph "Application Logic Layer"
        InputHandler["InputHandler"]:::logic
        PromptManager["PromptManager"]:::logic
        InferenceEngine["ZeroShotDetector"]:::logic
        ComparisonService["ComparisonService"]:::logic
        AutoLabelService["AutoLabelService"]:::logic
        ExportService["ExportService"]:::logic
    end

    %% Layer 4: Data & External Services Layer
    subgraph "Data & External Services Layer"
        RawStore["Raw Images Store"]:::dataStore
        DemoImages["Demo Images"]:::dataStore
        ProcessedResults["Processed Results"]:::dataStore
        ExportedData["Exported Dataset Files"]:::dataStore
        HF["HuggingFace Transformers"]:::external
        SIC["streamlit-image-comparison"]:::external
        LocalFS["Local File System"]:::external
    end

    %% Connections
    User --> HomePage
    User --> ComparePage
    User --> AutoLabelPage

    HomePage --> InputHandler
    ComparePage -->|"upload images / select prompts"| InputHandler
    AutoLabelPage --> InputHandler

    DemoImages -.-> InputHandler

    InputHandler -->|stores images| RawStore

    ComparePage --> PromptManager
    AutoLabelPage --> PromptManager

    PromptManager --> InferenceEngine

    InferenceEngine -->|"calls"| HF
    HF -->|"returns results"| InferenceEngine

    InferenceEngine --> ProcessedResults
    ProcessedResults --> ComparePage
    ProcessedResults --> ComparisonService
    ComparisonService --> ComparePage
    ComparisonService -->|"displays side-by-side"| ComparePage

    AutoLabelPage --> AutoLabelService
    AutoLabelService --> InferenceEngine
    AutoLabelService --> ProcessedResults
    AutoLabelService --> ExportService

    ExportService --> ExportedData
    ExportService --> LocalFS
    ExportedData --> AutoLabelPage

    UIUtils -.-> HomePage
    UIUtils -.-> ComparePage
    UIUtils -.-> AutoLabelPage
    UIUtils -.-> ExportService

    %% Click Events
    click HomePage "https://github.com/sefaburakokcu/autodetectify/blob/main/ui/🤗_Home.py"
    click ComparePage "https://github.com/sefaburakokcu/autodetectify/blob/main/ui/pages/1_👀_Compare_Prompts.py"
    click AutoLabelPage "https://github.com/sefaburakokcu/autodetectify/blob/main/ui/pages/2_📥_Autolabel_Images.py"
    click UIUtils "https://github.com/sefaburakokcu/autodetectify/blob/main/ui/ui_utils.py"
    click InferenceEngine "https://github.com/sefaburakokcu/autodetectify/blob/main/autodetectify/models/zero_shot_detection/models.py"
    click RawStore "https://github.com/sefaburakokcu/autodetectify/tree/main/inputs/"
    click DemoImages "https://github.com/sefaburakokcu/autodetectify/tree/main/inputs/demo_images/"

    %% Styles
    classDef user fill:#D6E9FE,stroke:#3B8ED0,stroke-width:1px
    classDef ui fill:#E8F1FF,stroke:#4A90E2,stroke-width:1px
    classDef logic fill:#E6F4EA,stroke:#34A853,stroke-width:1px
    classDef dataStore fill:#FFEACC,stroke:#F2994A,stroke-width:1px
    classDef external fill:#F2F2F2,stroke:#9B9B9B,stroke-width:1px
```
