# fal-ai/f-lite architecture

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

- Interactive diagram: https://gitdiagram.com/fal-ai/f-lite
- Repository: https://github.com/fal-ai/f-lite

## Overview

##### Project type and purpose
- This is an open-source Python library/toolkit centered on the “F Lite” family of diffusion models.
- It provides:
- A core model & inference pipeline (f_lite package)
- Command-line interface (generate.py)
- Gradio GUI (f_lite_gradio_gui.py)
- ComfyUI node integrations & example workflows
- Training & embedding precomputation utilities

##### File structure
- Top-level scripts & configurations:
- generate_requirements.py, pyproject.toml, requirements.txt
- FINE-TUNING.md, NEGATIVE_PROMPT.md, LICENSE
- assets/ (technical report, prompts folder, sample images)
- workflows/ (JSON definitions for ComfyUI)
- Core library (f_lite/):
- model.py, pipeline.py: defines FLitePipeline & underlying diffusion model
- generate.py: shared logic imported by CLI & conversion scripts
- comfyui.py: adapter exposing ComfyUI nodes
- f_lite_to_hf.py: conversion to HuggingFace diffusers format
- precompute_embeddings.py, precomputed_utils.py: support for prompt embeddings
- train.py, pt.py: training loop & utilities

##### README insights
- Describes three user-facing entry points: CLI, Gradio GUI, ComfyUI workflows
- Highlights external dependencies: PyTorch, diffusers, Gradio, HuggingFace Hub, ComfyUI extensions, Fal.ai demos
- Notes fine-tuning and embedding workflows

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library Module
    subgraph "Core Library Module"
        CL_init["__init__.py"]:::core
        CL_model["model.py"]:::core
        CL_pipeline["pipeline.py"]:::core
        CL_convert["f_lite_to_hf.py"]:::core
    end

    %% User Interfaces
    subgraph "User Interfaces"
        CLI["CLI: generate.py"]:::ui
        GUI["Gradio GUI: f_lite_gradio_gui.py"]:::ui
        subgraph "ComfyUI Integration"
            CU_adapter["Adapter: comfyui.py"]:::ui
            CU_wf1["Workflow JSON: F-lite-simple.json"]:::ui
            CU_wf2["Workflow JSON: F-lite-superprompt.json"]:::ui
        end
    end

    %% Training & Embedding Precompute
    subgraph "Training & Embedding Precompute"
        Train["train.py"]:::training
        PT["pt.py"]:::training
        Precompute["precompute_embeddings.py"]:::training
        PUtils["precomputed_utils.py"]:::training
        EmbStore["embeddings/"]:::training
    end

    %% Documentation & Assets
    subgraph "Documentation & Assets"
        ReqGen["generate_requirements.py"]:::docs
        PP["pyproject.toml"]:::docs
        RTxt["requirements.txt"]:::docs
        FTguide["FINE-TUNING.md"]:::docs
        NPrompt["NEGATIVE_PROMPT.md"]:::docs
        Report["F Lite Technical Report.pdf"]:::docs
        Prompts["assets/ng_prompt/"]:::docs
        WorkflowsDir["workflows/"]:::docs
    end

    %% External Services
    subgraph "External Services"
        Hub["HuggingFace Hub"]:::ext
        Fal["Fal.ai API"]:::ext
        CUIExt["ComfyUI Extensions"]:::ext
    end

    %% Connections
    CLI -->|"uses"| CL_pipeline
    GUI -->|"uses"| CL_pipeline
    CU_adapter -->|"wraps pipeline"| CL_pipeline
    CU_wf1 -->|"wires nodes"| CU_adapter
    CU_wf2 -->|"wires nodes"| CU_adapter
    CL_pipeline -->|"loads model"| CL_model
    CL_pipeline -->|"conversion"| CL_convert
    CL_pipeline -->|"pulls from"| Hub
    CL_pipeline -->|"optional use"| Fal
    Train -->|"trains model"| CL_model
    Train -->|"uses utils"| PT
    Train -->|"push checkpoint"| Hub
    Precompute -->|"generates"| PUtils
    Precompute -->|"outputs"| EmbStore
    EmbStore -->|"used by"| CL_pipeline

    %% Click Events
    click CL_init "https://github.com/fal-ai/f-lite/blob/main/f_lite/__init__.py"
    click CL_model "https://github.com/fal-ai/f-lite/blob/main/f_lite/model.py"
    click CL_pipeline "https://github.com/fal-ai/f-lite/blob/main/f_lite/pipeline.py"
    click CL_convert "https://github.com/fal-ai/f-lite/blob/main/f_lite/f_lite_to_hf.py"
    click CLI "https://github.com/fal-ai/f-lite/blob/main/f_lite/generate.py"
    click GUI "https://github.com/fal-ai/f-lite/blob/main/f_lite_gradio_gui.py"
    click CU_adapter "https://github.com/fal-ai/f-lite/blob/main/f_lite/comfyui.py"
    click CU_wf1 "https://github.com/fal-ai/f-lite/blob/main/workflows/F-lite-simple.json"
    click CU_wf2 "https://github.com/fal-ai/f-lite/blob/main/workflows/F-lite-superprompt.json"
    click Train "https://github.com/fal-ai/f-lite/blob/main/f_lite/train.py"
    click PT "https://github.com/fal-ai/f-lite/blob/main/f_lite/pt.py"
    click Precompute "https://github.com/fal-ai/f-lite/blob/main/f_lite/precompute_embeddings.py"
    click PUtils "https://github.com/fal-ai/f-lite/blob/main/f_lite/precomputed_utils.py"
    click ReqGen "https://github.com/fal-ai/f-lite/blob/main/generate_requirements.py"
    click PP "https://github.com/fal-ai/f-lite/blob/main/pyproject.toml"
    click RTxt "https://github.com/fal-ai/f-lite/blob/main/requirements.txt"
    click FTguide "https://github.com/fal-ai/f-lite/blob/main/FINE-TUNING.md"
    click NPrompt "https://github.com/fal-ai/f-lite/blob/main/NEGATIVE_PROMPT.md"
    click Report "https://github.com/fal-ai/f-lite/blob/main/assets/F Lite Technical Report.pdf"
    click Prompts "https://github.com/fal-ai/f-lite/tree/main/assets/ng_prompt/"
    click WorkflowsDir "https://github.com/fal-ai/f-lite/tree/main/workflows/"

    %% Styles
    classDef core fill:#E3F2FD,stroke:#90CAF9;
    classDef ui fill:#E8F5E9,stroke:#66BB6A;
    classDef training fill:#FFF3E0,stroke:#FFA726;
    classDef ext fill:#ECEFF1,stroke:#B0BEC5;
    classDef docs fill:#F3E5F5,stroke:#CE93D8;
```
