# yownas/shift-attention architecture

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

- Interactive diagram: https://gitdiagram.com/yownas/shift-attention
- Repository: https://github.com/yownas/shift-attention

## Overview

##### Main Components
- User Interface (Web UI Extension): Represent this as the integration point within the AUTOMATIC1111 web UI. Include elements that let the user input parameters such as “Steps”, “FPS”, “SSIM threshold”, etc.
- Prompt Parser & Interpreter: Component responsible for parsing the customized prompt formats (“(token:start~end)”, “AND”, “THEN”, etc.). This is core to capturing the intended transitions.
- Frame Generator: The process that takes the parsed prompt and the input parameters to generate the sequence of images.
- SSIM Evaluator & Interpolator: Module that evaluates inter-frame similarity using the Structural Similarity Index Metric and, if necessary, triggers a “second pass” to fill in any gaps.
- RIFE-based Video Interpolator: Module integrated via scripts (see “scripts/rife”) which uses Real-Time Intermediate Flow Estimation to interpolate additional frames.
- Upscaler: Optional component for image upscaling prior to video generation.
- Video Assembler: A component that takes the generated images (and interpolated frames) and assembles the final video output, considering parameters like “Lead in/out”, “FPS”, etc.
- Integration/Installation Scripts: Represented by files like “install.py” and the folder structure in “scripts/” (which includes both “shift_attention.py” and the RIFE-related modules). These outline how the extension hooks into the Stable Diffusion web UI.

##### Relationships and Data Flow
- The user initiates the process by entering a prompt with the specialized token weights and setting parameters via the web UI extension.
- The Prompt Parser interprets this input and passes the relevant instructions to the Frame Generator.
- The Frame Generator uses the base generation capabilities (from stable diffusion) to produce the initial set of images.
- If SSIM is enabled, the SSIM Evaluator assesses the difference between adjacent frames and, if required, requests additional “in-between” images from the Frame Generator.
- Independently or subsequently, the RIFE module may be applied to the generated frames to smooth the transitions entirely by interpolating new frames.
- Optionally, the Upscaler applies to the frames before final assembly.
- Finally, the Video Assembler gathers and encodes the final video output.
- The overall extension is integrated into the stable-diffusion-webui environment via standard extension installation methods as detailed in the README.

##### Important Architectural Patterns and Design Principles
- Modularity: Each functionality (prompt parsing, image generation, SSIM evaluation, RIFE interpolation, upscaling, and video assembly) is kept separate, easing maintenance and further extension.
- Extensibility and Integration: The extension’s design is meant to plug directly into an existing system (the stable-diffusion-webui) and interact with its underlying generation pipeline.
- Pipeline Processing: There is a clear sequential or multi-stage data processing flow, where image frames are produced, enhanced, and finally composed into a video.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "User Interface Layer"
        UI["Web UI Extension (Integration with AUTOMATIC1111 Web UI)"]:::frontend
    end

    %% Backend Processing Layer
    subgraph "Processing Pipeline"
        PP["Prompt Parser & Interpreter"]:::backend
        FG["Frame Generator"]:::backend
        SSIM["SSIM Evaluator & Interpolator"]:::backend
        RIFE["RIFE-based Video Interpolator"]:::external
        UPS["Upscaler (Optional)"]:::backend
        VA["Video Assembler"]:::backend
    end

    %% Installation & Integration Layer
    subgraph "Installation & Integration"
        IS1["Install Script"]:::integration
        SCRIPTS["Scripts Directory"]:::integration
    end

    %% Data Flow
    UI -->|"sendsPromptWithParameters"| PP
    PP -->|"parsedInstructions"| FG
    FG -->|"generatesInitialFrames"| SSIM
    SSIM -->|"ifNeededCalls"| FG
    SSIM -->|"triggersInterpolation"| RIFE
    FG -->|"finalFrames"| UPS
    RIFE -->|"smoothedFrames"| UPS
    UPS -->|"upscaledFrames"| VA
    VA -->|"outputsFinalVideo"| UI

    %% Integration connections
    IS1 -.->|"integrationHook"| UI
    IS1 -.->|"integrationHook"| PP
    IS1 -.->|"integrationHook"| FG
    IS1 -.->|"integrationHook"| RIFE
    SCRIPTS -.->|"containsModules"| PP
    SCRIPTS -.->|"containsModules"| FG
    SCRIPTS -.->|"containsModules"| RIFE

    %% Click Events
    click UI "https://github.com/yownas/shift-attention/blob/main/install.py"
    click PP "https://github.com/yownas/shift-attention/blob/main/scripts/shift_attention.py"
    click FG "https://github.com/yownas/shift-attention/blob/main/scripts/shift_attention.py"
    click SSIM "https://github.com/yownas/shift-attention/blob/main/scripts/rife/ssim.py"
    click RIFE "https://github.com/yownas/shift-attention/tree/main/scripts/rife/"
    click IS1 "https://github.com/yownas/shift-attention/blob/main/install.py"
    click SCRIPTS "https://github.com/yownas/shift-attention/tree/main/scripts/"

    %% Styles
    classDef frontend fill:#f9c,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbf,stroke:#333,stroke-width:2px;
    classDef integration fill:#dfd,stroke:#333,stroke-width:2px;
    classDef external fill:#ffd,stroke:#333,stroke-width:2px;
```
