Skip to content

About

Fully offline image generation pipeline: FastAPI orchestrates Gemma 4 (E2B/E4B via llama.cpp) for prompt rewriting and JuggernautXL (SDXL) via headless ComfyUI REST+WebSocket API for diffusion inference. Features E2B vs E4B latency benchmarking, image proxy, and editorial dark UI. Runs entirely on consumer NVIDIA GPUs with zero cloud dependency.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

PixelStudio Pro

Local AI image generation with LLM prompt intelligence

Watch the video

Click on the Preview to Watch Demo Video

Python 3.10 FastAPI ComfyUI llama.cpp CUDA License


A fully local, offline AI image generation pipeline that combines LLM-based prompt rewriting with a diffusion image model. Type a casual natural language description, Gemma 4 rewrites it into a rich diffusion prompt, and JuggernautXL generates a photorealistic image — all running locally on consumer hardware with zero cloud dependency.

Advanced successor to PixelStudio — adds FastAPI orchestration, LLM prompt intelligence, programmatic ComfyUI API control, a custom editorial frontend, and benchmark metrics.


Architecture

┌─────────────────────────────────────────────────────────────────────────────┐
│                            PixelStudio Pro Pipeline                          │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                             │
│   ┌──────────┐     ┌──────────────┐     ┌─────────────────┐               │
│   │  User    │────▶│   FastAPI    │────▶│  llama.cpp      │               │
│   │  Input   │     │   Backend    │     │  (Gemma E2B/E4B)│               │
│   └──────────┘     └──────┬───────┘     └────────┬────────┘               │
│                            │                      │                         │
│                            │◀─── rewritten prompt─┘                         │
│                            │                                                │
│                            ▼                                                │
│                    ┌───────────────┐     ┌─────────────────┐               │
│                    │  ComfyUI API  │────▶│  JuggernautXL   │               │
│                    │  (REST + WS)  │     │  (SDXL v9)      │               │
│                    └───────┬───────┘     └─────────────────┘               │
│                            │                                                │
│                            ▼                                                │
│                    ┌───────────────┐                                        │
│                    │   Frontend    │                                        │
│                    │  (Dark Theme) │                                        │
│                    └───────────────┘                                        │
│                                                                             │
└─────────────────────────────────────────────────────────────────────────────┘
sequenceDiagram
    participant User
    participant FastAPI
    participant LlamaCpp as llama.cpp (Gemma 4)
    participant ComfyUI as ComfyUI (JuggernautXL)

    User->>FastAPI: POST /api/generate {prompt, model}
    FastAPI->>LlamaCpp: Rewrite prompt via /v1/chat/completions
    LlamaCpp-->>FastAPI: {positive, negative} prompt
    FastAPI->>ComfyUI: Submit workflow via REST API
    FastAPI->>ComfyUI: Monitor progress via WebSocket
    ComfyUI-->>FastAPI: Generation complete + filename
    FastAPI-->>User: Image + benchmark metrics
Loading

Key Features

Feature Description
LLM Prompt Intelligence Gemma 4 rewrites casual descriptions into rich diffusion prompts with lighting, camera, style, and quality descriptors
E2B vs E4B Benchmarking Both model sizes available for A/B comparison with latency metrics
ComfyUI Headless API ComfyUI controlled entirely via REST + WebSocket — never touched directly
Image Proxy FastAPI proxies ComfyUI outputs for same-origin downloads
Benchmark Metrics Rewrite latency, generation latency, and total latency returned per request
Fully Offline Zero cloud dependency — all models run locally on consumer hardware
Editorial UI Dark theme with electric orange accent, Enerblock-inspired grid layout

Hardware Requirements

Component Minimum Recommended (Tested)
GPU RTX 3060 6GB RTX 4050 6GB GDDR6
RAM 16GB DDR4 24GB DDR5
CPU 6-core x86_64 Ryzen 7 7435HS
Storage 20GB free 40GB+ (models)
OS Ubuntu 22.04 Ubuntu 24.04 (dual boot)
CUDA 12.0+ 13.0

Project Structure

PixelStudio-Pro/
├── backend/
│   ├── main.py                  # FastAPI entry point
│   ├── config.py                # Central configuration
│   ├── routes/
│   │   ├── generate.py          # Single image generation endpoint
│   │   └── compare.py           # E2B vs E4B comparison endpoint
│   ├── services/
│   │   ├── prompt_rewriter.py   # LLM prompt rewriting via llama.cpp
│   │   ├── image_gen.py         # ComfyUI API orchestration
│   │   └── benchmark.py         # Performance metrics tracking
│   └── utils/
│       └── comfyui_workflow.py   # ComfyUI workflow JSON builder
├── frontend/
│   ├── index.html               # Main UI
│   ├── style.css                # Editorial dark theme
│   └── app.js                   # Frontend logic
├── workflows/                   # ComfyUI workflow templates
├── outputs/                     # Generated images
├── models/                      # Local model storage
├── requirements.txt             # Python dependencies
└── .gitignore

Installation

Prerequisites

  • Conda (Miniconda or Anaconda)
  • NVIDIA GPU with CUDA support (for Linux) or Apple Silicon (for Mac)

Step 1: Clone the Repository

git clone https://github.com/AdityaGuhaa/Pixel-Studio-Pro.git
cd Pixel-Studio-Pro

Step 2: Download Models

Before installing, download the required models and place them in the models/ directory:

Gemma 4 (LLM — prompt rewriting): Download the GGUF quantized models from HuggingFace and place them in models/:

  • gemma-4-E2B-it-Q4_K_M.gguf — 2B parameter model (faster)
  • gemma-4-E4B-it-Q4_K_M.gguf — 4B parameter model (higher quality)

JuggernautXL v9 (Image generation): Download Juggernaut-XL_v9_RunDiffusionPhoto_v2.safetensors from CivitAI and place it in the models/ directory.

Step 3: Run the Auto-Installer

PixelStudio Pro includes an automated installer that will create your conda environment, download llama.cpp for your specific OS (Linux or Mac), and clone/setup ComfyUI automatically.

bash install.sh

Running the Services

You no longer need to open multiple terminal windows! PixelStudio Pro includes a one-command launcher that automatically boots the LLM server, the ComfyUI backend, and the FastAPI orchestration layer.

bash launch.sh

Access the Application

The launcher will automatically open your default web browser. If it doesn't, navigate to:

http://127.0.0.1:8001

(Note: To gracefully shut down all background services, simply press Ctrl+C in the terminal where the launcher is running).


API Documentation

POST /api/generate/

Generates a single image using the full pipeline.

Request:

{
  "prompt": "a cat sitting on a beach at sunset",
  "model": "e2b"
}
Parameter Type Default Description
prompt string required Natural language image description
model string "e2b" LLM model to use: "e2b" or "e4b"

Response:

{
  "user_prompt": "a cat sitting on a beach at sunset",
  "positive_prompt": "photorealistic, a fluffy cat sitting peacefully on wet sand at the beach, dramatic sunset lighting, golden hour, warm tones, soft volumetric lighting, ocean waves in the background, highly detailed fur texture, cinematic shot, 8k, shallow depth of field, professional photography, hyperdetailed",
  "negative_prompt": "blurry, low quality, distorted face, bad anatomy, extra fingers, watermark, text, logo, oversaturated",
  "image_filename": "pixelstudio_pro_00001_.png",
  "rewrite_latency_seconds": 3.42,
  "image_gen_latency_seconds": 54.18,
  "total_latency_seconds": 57.60,
  "model_used": "e2b"
}

POST /api/compare/

Runs the pipeline with both E2B and E4B models and returns a side-by-side comparison.

Request:

{
  "prompt": "a cyberpunk city at night with neon lights"
}

Response:

{
  "user_prompt": "a cyberpunk city at night with neon lights",
  "e2b": {
    "model_used": "e2b",
    "positive_prompt": "...",
    "negative_prompt": "...",
    "rewrite_latency_seconds": 3.21,
    "image_gen_latency_seconds": 52.40,
    "total_latency_seconds": 55.61,
    "image_filename": "pixelstudio_pro_00002_.png"
  },
  "e4b": {
    "model_used": "e4b",
    "positive_prompt": "...",
    "negative_prompt": "...",
    "rewrite_latency_seconds": 6.85,
    "image_gen_latency_seconds": 53.10,
    "total_latency_seconds": 59.95,
    "image_filename": "pixelstudio_pro_00003_.png"
  },
  "comparison": {
    "faster_rewrite": "e2b",
    "faster_total": "e2b",
    "rewrite_diff_seconds": 3.64,
    "total_diff_seconds": 4.34
  }
}

GET /api/image/{filename}

Proxies an image from ComfyUI output for same-origin download.

curl -O http://127.0.0.1:8000/api/image/pixelstudio_pro_00001_.png

GET /health

Health check endpoint.

{
  "status": "PixelStudio Pro is running"
}

Sample Output

Input:

a cat sitting on a beach at sunset

Gemma 4 E2B Rewritten Prompt:

photorealistic, a fluffy cat sitting peacefully on wet sand at the beach,
dramatic sunset lighting, golden hour, warm tones, soft volumetric lighting,
ocean waves in the background, highly detailed fur texture, cinematic shot,
8k, shallow depth of field, professional photography, hyperdetailed

Negative Prompt:

blurry, low quality, distorted face, bad anatomy, extra fingers, watermark,
text, logo, oversaturated, cartoon, anime, illustration

Performance (RTX 4050 6GB):

Stage Latency
Prompt Rewrite (E2B) ~3.4s
Image Generation (JuggernautXL, 25 steps) ~54s
Total Pipeline ~58s

Configuration Reference

All configuration lives in backend/config.py:

# llama.cpp server ports
LLAMACPP_PORT_E2B = 8080        # Gemma 4 E2B
LLAMACPP_PORT_E4B = 8081        # Gemma 4 E4B

# ComfyUI
COMFYUI_PORT = 8188

# Generation defaults (JuggernautXL optimized)
DEFAULT_STEPS = 25
DEFAULT_CFG = 7.0               # SDXL sweet spot: 7-8
DEFAULT_WIDTH = 832
DEFAULT_HEIGHT = 1216           # Portrait resolution
DEFAULT_SAMPLER = "dpmpp_2m"
DEFAULT_SCHEDULER = "karras"

Future Scope

  • Flux.1 Schnell GGUF — Upgrade path already scaffolded in config and workflow builder
  • Side-by-side comparison UI — Visual E2B vs E4B image comparison in the frontend
  • Docker deployment — nvidia/cuda base image with all services containerized
  • LoRA & ControlNet — Extended ComfyUI workflow support for style transfer and pose control
  • Prompt history & gallery — Persistent storage with searchable generation history
  • Batch generation — Queue multiple prompts for overnight runs

Predecessor

PixelStudio — A basic ComfyUI setup with SDXL for local image generation.

PixelStudio Pro extends this with:

  • FastAPI orchestration layer
  • LLM-based prompt intelligence (Gemma 4)
  • Programmatic ComfyUI API control (REST + WebSocket)
  • Custom editorial frontend
  • E2B vs E4B benchmark comparison
  • Structured performance metrics

Author

Aditya Guha — AI & ML Engineer

2022-26 B.Tech CSE (AI & ML) · Ex-DRDO R&DE(E) Robotics & Machine Learning Intern

LinkedIn GitHub


License

This project is licensed under the Apache License 2.0. See LICENSE for details.

Copyright 2025 Aditya Guha

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Built with local compute. No cloud. No API keys. No compromises.

About

Fully offline image generation pipeline: FastAPI orchestrates Gemma 4 (E2B/E4B via llama.cpp) for prompt rewriting and JuggernautXL (SDXL) via headless ComfyUI REST+WebSocket API for diffusion inference. Features E2B vs E4B latency benchmarking, image proxy, and editorial dark UI. Runs entirely on consumer NVIDIA GPUs with zero cloud dependency.

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages