Commit Graph
15 Commits
Author SHA1 Message Date
Claude 9b895673eb feat: GPU capability display in UI + GTX 1060 6GB SDXL fix
Model selection:
- Add sdxl_offload tier (eff_vram ≥ 4.0 GB) for GTX 1060 6GB and Quadro
  6GB cards that were falling through to SD 2.1 despite SDXL fitting with
  model_cpu_offload. Cards with 5.3 GB effective VRAM now get SDXL quality.
- Update _tier_label(), _caps(), _build_warnings() for new tier.

Frontend GPU display:
- api.js: add getGpuStatus() fetching /api/gpu/status
- capabilities.js: add getGpuStatus() export with own LRU cache;
  refreshCapabilities() now also resets GPU status cache
- provider-badge.js: when AI_PROVIDER=local_gpu show green badge with
  GPU name, tier, VRAM, CC, feature flags, and capabilities in tooltip.
  Strip "NVIDIA GeForce" prefix so "GTX 1060 6GB" fits in badge.
- ai_provider_settings.js: add local_gpu to all provider dropdowns;
  show GPU info panel (device, VRAM, CC, features, tier, model table per
  operation) in the settings dialog when a GPU is detected.

https://claude.ai/code/session_01WVDg7amsy1TTtxvpku7bcM
2026-06-13 15:58:13 +00:00
Claude fe4d911a00 Dynamic GPU capability detection: probe CC, VRAM, feature flags, pick best model
Replaces fixed tier table with real hardware probing and dynamic model selection.

gpu_detect.py — complete rewrite:
- Reads torch.cuda.get_device_properties + mem_get_info for actual free VRAM
- Detects: fp16 (CC≥6.0), bf16 (CC≥8.0), fp8 (CC≥8.9 Ada/Hopper),
           int8 (CC≥7.0), tensor_cores (CC≥7.0), xformers presence
- Pre-Pascal (CC<6.0): effective_vram halved (fp32 weights are 2× larger)
- Subtracts 400MB driver overhead from free VRAM before model selection
- _select_txt2img / _select_inpaint / _select_img2img / _select_upscale:
    eff≥20GB  → FLUX.1-schnell (no offload)
    eff≥10GB  → FLUX.1-schnell (model_cpu_offload)
    eff≥7.5GB → SDXL
    eff≥5.5GB → SDXL + attention_slicing
    eff≥3.5GB → SD 2.1
    eff≥2.5GB → SD 2.1-base + attention_slicing
    eff≥1.7GB → SD 1.5
    else      → SD 1.5 + sequential_cpu_offload
- ModelSpec carries: model_id, family, memory_opt, native_res, vram_fp16_gb
- Warnings: old CC, pre-Pascal fp32, fp8 upgrade hint, xformers install tip
- Compatibility shim get_model_ids() retained for existing callers
- infer_spec_from_model_id() auto-detects family from HF_MODEL_* overrides

local_diffusion.py — refactored to use ModelSpec:
- Reads spec from GpuCapabilities.recommended[op] instead of tier table
- FLUX.1-schnell: FluxPipeline / FluxImg2ImgPipeline, 4 steps, guidance=0.0
- SD families: family-aware pipeline class selection (sd15/sd2x/sdxl)
- Memory opts applied per ModelSpec.memory_opt field
- xformers attention enabled automatically when xformers detected

gpu_status.py — richer response:
- Exposes all feature flags (fp16/bf16/fp8/int8/tensor_cores/xformers)
- Returns full ModelSpec per operation (model_id, family, memory_opt, native_res)

ai_tools.py — /api/config exposes:
- gpu_vram_total, gpu_vram_free, gpu_cc, gpu_fp16, gpu_bf16, gpu_fp8,
  gpu_tensor_cores, gpu_eff_vram, local_gpu_warnings

requirements.gpu.txt:
- diffusers bumped to >=0.29.0 (FLUX pipeline added in 0.29)
- transformers bumped to >=4.40.0
- sentencepiece added (FLUX T5 tokenizer)

scripts/gpu_setup.py:
- Prints full model table at startup (op → model_id, family, memory_opt, res)
- Shows all feature flags in one line

https://claude.ai/code/session_01WVDg7amsy1TTtxvpku7bcM
2026-06-13 15:35:37 +00:00
Claude 46b9066bba Handle old/low-VRAM GPUs and document nvidia-container-toolkit requirement
GPU tier table extended:
  ultra   ≥16 GB → SDXL (unchanged)
  high    8-16 GB → SDXL (unchanged)
  medium  4-8 GB → SD 2.x (unchanged)
  legacy  2-4 GB → SD 1.5 (~1.7 GB fp16)  ← new: GTX 970/1060/RX 580 etc.
  minimal <2 GB  → SD 1.5 + sequential CPU offload  ← new: very old/integrated GPUs

gpu_detect.py:
- Detects CUDA compute capability (CC); fp16 disabled for CC < 6.0 (pre-Pascal)
- GpuInfo gains compute_capability and warnings fields
- _make_warnings() emits human-readable warnings for low VRAM and old CC
- model tier fallback updated from 'low' to 'legacy'

local_diffusion.py:
- minimal/legacy tiers use enable_sequential_cpu_offload() + enable_attention_slicing(1)
- target resolution per tier: ultra/high=1024, medium=768, legacy/minimal=512
- .to(device) skipped when sequential CPU offload is active

gpu_status.py:
- Response now includes compute_capability and warnings

docker-compose.gpu.yml:
- Full nvidia-container-toolkit install instructions in header comment
- nvidia-docker2 (legacy) fallback documented as comment block inline
- AMD ROCm swap-in instructions added
- GPU tier table documented in header

scripts/gpu_setup.py:
- Prints compute capability, fp16 status, tier, and model selection at startup
- Prints per-tier warnings (old CC, low VRAM)

https://claude.ai/code/session_01WVDg7amsy1TTtxvpku7bcM
2026-06-13 15:19:01 +00:00
Claude 8fe8498df2 Add local GPU inference: auto-detect GPU, auto-download best diffusion models
Adds AI_PROVIDER=local_gpu — a fully self-contained GPU inference engine
using HuggingFace Diffusers that requires zero InvokeAI/ComfyUI setup.
All existing providers (InvokeAI, ComfyUI, OpenAI, Replicate) remain intact
and can be mixed with local GPU via per-operation overrides.

New features:
- GPU auto-detection (CUDA/NVIDIA, MPS/Apple Silicon, CPU fallback)
- VRAM-tiered model selection:
    ultra ≥16 GB → SDXL inpaint + SDXL base
    high  8-16 GB → SDXL inpaint + SDXL base
    medium 4-8 GB → SD 2.x inpaint + SD 2.1
    low  <4 GB   → SD 2.x (small)
- Auto-download model weights to HuggingFace disk cache at startup
  (background task; first request loads from local disk, not internet)
- LRU pipeline cache evicts oldest GPU pipeline when VRAM limit reached
- Per-operation model overrides via HF_MODEL_INPAINT / HF_MODEL_TXT2IMG etc.
- Optional HF_TOKEN for gated/private HuggingFace models

New files:
- backend/app/services/gpu_detect.py   — GPU detection + tier/model mapping
- backend/app/services/local_diffusion.py — Diffusers provider + LRU cache
- backend/app/routers/gpu_status.py    — GET /api/gpu/status, POST /api/gpu/prefetch
- backend/requirements.gpu.txt         — Diffusers ecosystem deps (GPU only)
- docker-compose.gpu.yml               — NVIDIA GPU compose (one-command startup)
- Dockerfile.gpu                       — pytorch/pytorch:2.1.0-cuda12.1 base image
- scripts/gpu_setup.py                 — Startup GPU info logger

Modified:
- backend/app/config.py                — local_gpu settings added
- backend/app/services/remote_provider.py — local_gpu registered as provider
- backend/app/routers/ai_tools.py      — /api/config exposes GPU tier + caps
- backend/app/main.py                  — GPU router + background prefetch task
- backend/entrypoint.sh                — runs gpu_setup.py at container start
- .env.example                         — local_gpu documented as first option

Quick start with GPU:
  docker compose -f docker-compose.gpu.yml up --build

https://claude.ai/code/session_01WVDg7amsy1TTtxvpku7bcM
2026-06-13 15:08:41 +00:00
Claude 3746c02d44 Add SAM click-to-select with brush refinement in AI Edit tool
Backend:
- sam_service.py: auto-downloads SAM ViT-B (~375 MB) on first use with
  progress tracking; loads model to CUDA/MPS/CPU; predict_points() takes
  multi-point prompts (include/exclude labels) and returns best mask
- POST /api/segment/point: SAM point-prompt endpoint; returns mask PNG
- GET  /api/segment/install-status: poll download progress
- POST /api/segment/install: explicit trigger (also auto on first click)
- main.py: pre-download SAM on startup alongside NCNN

Frontend (ai_edit.js):
- Click mode (default): click object → SAM generates mask instantly
  Alt+click → subtract (deselect over-selected area)
  Multiple clicks accumulate for multi-object or refinement
- Brush + / Brush − modes: paint to add or erase from SAM mask by hand
- If SAM model is still downloading on first click: inline progress bar,
  user retries the click when done
- Unified action bar: Erase | Replace (inline prompt) | Upscale | Expand | Clear
- All modes share the same mask canvas; SAM and brush are fully composited

https://claude.ai/code/session_01B58MaJCU1R6KwBDJCp8AfN
2026-06-10 18:18:33 +00:00
Claude 717f482987 Skip NCNN install on headless/no-Vulkan machines
- Add _vulkan_available(): checks /dev/dri/renderD* on Linux, assumes
  true on macOS/Windows; set REALESRGAN_NCNN=force to override
- Add _test_ncnn_binary(): test-runs the binary after install and checks
  stderr for "no vulkan" — marks skipped if Vulkan init fails at runtime
- ensure_ncnn_installed() now returns early with state=skipped when no
  Vulkan detected, avoiding a wasted ~30MB download on CPU-only servers
- Recommend PyTorch CPU when available on headless (AI quality, slow but
  works); Lanczos as final fallback
- Frontend: handle state=skipped immediately (no polling needed), show
  brief informational toast; show "Headless server" note in dialog

https://claude.ai/code/session_01B58MaJCU1R6KwBDJCp8AfN
2026-06-10 00:50:09 +00:00
Claude ed2a0d7f0c Auto-install Real-ESRGAN NCNN Vulkan binary on first use
- upscale.py: add InstallStatus dataclass + ensure_ncnn_installed() async
  function that downloads and extracts the NCNN binary for the current
  platform (Linux/macOS/Windows), tracks progress (0-100%), and busts the
  caps cache when done
- main.py: trigger ensure_ncnn_installed() as a background task on app
  startup when no AI upscaler is detected
- print_tools.py: /upscale/available triggers install task when no AI
  upscaler found; new GET /upscale/install-status endpoint for polling
- upscale.js: if no AI upscaler on open, poll install-status showing a
  progress bar notification, then refresh caps and proceed when done

https://claude.ai/code/session_01B58MaJCU1R6KwBDJCp8AfN
2026-06-09 18:38:45 +00:00
Claude cea9ee9d6c Smart upscale: auto-detect hardware and pick best Real-ESRGAN path
Detection priority (probed once, cached):
  1. Real-ESRGAN PyTorch + CUDA GPU   → fastest, best quality
  2. Real-ESRGAN PyTorch + Apple MPS  → fast on Apple Silicon
  3. Real-ESRGAN NCNN Vulkan binary   → fast on any GPU via Vulkan (no CUDA needed)
  4. Real-ESRGAN PyTorch CPU          → works, slow (warned in UI)
  5. Lanczos                          → always available, instant fallback

Backend:
- services/upscale.py: full capability probe (probe_upscale_capabilities),
  implementations for PyTorch (CUDA/MPS/CPU auto-device) and NCNN binary,
  upscale_sync() resolves method with fallback chain,
  async upscale_image() runs in thread pool
- print_tools.py: /api/print/upscale uses new service; method="auto" by default;
  GET /api/print/upscale/available returns full capability map with device info
  and recommended_label; POST /api/print/upscale/refresh-caps busts cache
  without restart (useful after installing NCNN binary into container)

Frontend:
- upscale.js: fetches capability map on first open; builds method selector showing
  only available options; labels recommended method with ★; shows device info
  (CUDA/MPS/CPU/NCNN) in dialog; maps display label back to method key on submit;
  shows actual method used in success toast and undo history entry

Scripts:
- scripts/download_realesrgan.py: downloads NCNN Vulkan binary for current platform
  (Linux/macOS/Windows) to /app/data/models/realesrgan/; makes executable;
  run inside container or locally

https://claude.ai/code/session_01B58MaJCU1R6KwBDJCp8AfN
2026-06-09 18:32:32 +00:00
Claude d01c11f948 Add per-operation AI provider routing
Each operation (inpaint, txt2img, img2img, outpaint) can now use a different
provider. Resolution order: per-op override → global AI_PROVIDER default.

Example: txt2img→openai, inpaint→invokeai, everything else→invokeai default.

Backend:
- config.py: add AI_PROVIDER_INPAINT / TXT2IMG / IMG2IMG / OUTPAINT settings
- remote_provider.py: get_remote_provider(operation) resolves override then default;
  _build_provider() extracted as shared factory; _OP_FIELD maps op→setting name
- ai_tools.py: each endpoint passes its operation to _require_remote();
  GET /api/config runs per-op health checks concurrently, returns operations map
  and overrides; POST /api/config accepts and applies per-op override fields

Frontend:
- ai_provider_settings.js: four new selects (inpaint/txt2img/img2img/outpaint);
  persists to localStorage and sends per-op fields to POST /api/config
- provider-badge.js: shows override summary (e.g. "invokeai · txt2img→openai")
  and per-op health in tooltip
- .env.example: document per-op override env vars with examples

https://claude.ai/code/session_01B58MaJCU1R6KwBDJCp8AfN
2026-06-09 18:14:12 +00:00
Claude 27261c4ef4 Add LaMa magic eraser, remote provider abstraction, and AI tool infrastructure
Backend:
- requirements.txt: add simple-lama-inpainting, rembg[gpu]; upgrade opencv to 4.10+
- app/config.py: add InvokeAI (url, model) and ComfyUI (url, model) settings; OPENAI_MODEL
- app/services/local_inpaint.py: LaMa, OpenCV, rembg wrappers (auto GPU/CPU)
- app/services/remote_provider.py: abstract RemoteAIProvider + OpenAI, InvokeAI, ComfyUI drivers
- app/routers/ai_tools.py: new /api/* endpoints — /erase, /inpaint/lama, /inpaint/fast,
  /background/remove, /inpaint/remote, /generate/txt2img, /generate/img2img,
  /generate/outpaint, GET /config (capability flags)
- app/main.py: register ai_tools router

Frontend:
- services/api.js: add erase(), textToImage(), imageToImage(), remoteInpaint(), getConfig()
- api/capabilities.js: lazy-fetch /api/config singleton; hasRemote() helper
- tools/ai_lama_erase.js: brush-paint mask → LaMa erase → apply to layer
- tools/ai_smart_inpaint.js: brush mask + dialog (Fast/Quality mode + prompt) → inpaint
- core/components/provider-badge.js: shows active provider + health in toolbar
- config.js: register ai_lama_erase and ai_smart_inpaint tools
- main.js: mount provider badge on load
- .env.example: document InvokeAI, ComfyUI, OpenAI provider settings

https://claude.ai/code/session_01B58MaJCU1R6KwBDJCp8AfN
2026-06-09 17:42:48 +00:00
Claude 549a1a4e82 Fix AI tools and My Library, add U2net background removal
- Fix My Library: Add CSS styling for library browser, items now visible
- Integrate My Library into Shapes tool with tabbed interface
- Improve AI Inpaint: Add transform mode for scaling/sizing selections
- Add helpful guidance explaining inpaint vs transform modes
- Add U2net as alternative background removal (avoids rembg issues)
- Create U2net model definition and download script
- Improve Caddyfile with multiple options and troubleshooting guide

Note: Brush Select (AI Paint) tool was already implemented and working.

https://claude.ai/code/session_01CLedz6CanT9t46KBvng3vz
2026-01-27 22:29:35 +00:00
Claude 909bb41f8a Add advanced editing features: layers, background removal, smart selection
Backend:
- Add /tools router with background removal, smart select, color select
- Add rembg dependency for AI background removal
- Add layer management API (list, flatten)
- Fix transparency preservation in blend_patch (veil collapse fix)
- Preserve alpha channel when reverting/resetting images

Frontend:
- Add AdvancedTools panel with background removal, smart select, color select
- Add Layers panel with drag-to-reorder, visibility toggle, flatten
- Add toolsApi for new backend endpoints
- Make right panel scrollable for additional controls

This adds "Photoshop light" capabilities:
- Remove background and create layer
- Smart object selection (click to select)
- Color selection with tolerance
- Layer system with compositing
2026-01-25 15:20:11 +00:00
Claude 4b936b7a10 Add text-to-image generation support
Implemented complete text-to-image functionality across all AI providers:

Backend additions:
- Added text_to_image() method to AIProvider abstract class
- Implemented for all providers:
  * OpenAI: DALL-E generations API
  * Stability AI: SDXL text-to-image with negative prompts
  * Replicate: SDXL with full parameter control
  * Mock: Placeholder image generation for testing

New API endpoints (/generate):
- POST /generate/text-to-image
  * Generate image from prompt
  * Optional: create new project automatically
  * Configurable width/height (256-2048px)
  * Negative prompt support
  * Provider and model selection

- POST /generate/layer/text-to-image
  * Generate image as layer in existing project
  * Smaller dimensions for layer composition
  * Position control (x, y coordinates)
  * Saves to project layers directory

Features:
- Full provider support (OpenAI, Stability, Replicate, Mock)
- Negative prompts for better control
- Auto-project creation option
- Layer-based generation for compositing
- Dimension validation (256-2048px range)
- Model selection per request

Use cases:
- Create new images from scratch
- Generate elements to add as layers
- Quick ideation and iteration
- Base image creation for further editing

Next: Advanced canvas UI with layers and real-time preview
2026-01-24 04:06:19 +00:00
Claude fc394d76cf Add Replicate provider, model selection, and Patch Library features
Major additions:
1. Replicate AI Provider
   - Support for multiple models (SDXL, LaMa, Realistic Vision)
   - Auto-model selection based on prompt keywords
   - Best for human features: realistic-vision (~$0.020/image)
   - Best for removal: lama (~$0.002/image)
   - Best general purpose: sdxl-inpaint (~$0.025/image)
   - Smart keyword detection for automatic model selection

2. Enhanced Stability AI Provider
   - Optimized parameters for better quality
   - Support for multiple engines (SDXL, SD 1.5, SD 2.1)
   - Increased steps and CFG scale for improved results

3. Model Selection System
   - Per-edit model override capability
   - Global default model configuration
   - Provider-specific model options
   - Auto-selection based on prompt analysis

4. Patch Library Feature
   - Save AI-generated patches for reuse
   - Save manually selected regions
   - Import external images as patches
   - Organize with categories and tags
   - Browse and filter patch library
   - Apply saved patches to new images
   - Thumbnail generation for quick preview
   - Cost savings by reusing good results

5. Comprehensive Documentation
   - MODEL_SELECTION_GUIDE.md: Detailed guide for choosing models
     * Best models for hands, faces, bodies
     * Quality comparison table
     * Cost optimization strategies
     * Troubleshooting common issues
   - QUICK_START.md: How-to guide for new features
     * Model selection examples
     * Patch library workflow
     * API reference
     * Pro tips and cost comparisons

6. Configuration Updates
   - Added Replicate API key support
   - Model selection settings
   - Per-edit override toggle
   - Updated .env.example with all options

Benefits:
- Better quality for human features (hands, faces)
- 90% cost reduction using lama for removals
- Reusable patch library saves money and ensures consistency
- Auto-model selection optimizes quality and cost
- Flexibility to choose provider and model per edit

All backend changes are fully functional and ready for use.
Frontend UI for patch library pending.
2026-01-24 03:32:50 +00:00
Claude c8078d4652 Implement complete AI Photo Edit tool with mask-scoped regeneration
This commit implements a full-stack AI photo editing application that
allows users to regenerate only selected areas of images using AI.

Features implemented:
- Frontend (React + Fabric.js):
  * Interactive canvas with selection tools (rectangle, ellipse, lasso)
  * Real-time selection preview and editing
  * Mode toggle (A: patch only, B: patch + context)
  * Feather slider for edge blending (0-50px)
  * Prompt input for AI instructions
  * Edit history viewer with revert capability
  * Responsive UI with dark theme

- Backend (FastAPI):
  * RESTful API for projects and edits
  * SQLite database for metadata storage
  * Image processing pipeline with PIL/OpenCV
  * AI provider interface (pluggable)
  * Support for OpenAI, Stability AI, and mock providers
  * Feathered alpha blending for smooth compositing
  * Complete edit history tracking
  * File-based storage for images and edits

- Image Processing:
  * Patch extraction from bounding boxes
  * Mask generation for all selection types
  * Feathered edge blending
  * Patch compositing back to full image
  * No pixels modified outside selection
  * All edits reversible

- Infrastructure:
  * Docker Compose orchestration
  * Production and development configurations
  * Nginx reverse proxy for frontend
  * Hot-reload support for development
  * Volume persistence for data

Architecture follows specification exactly:
- Only selected regions are regenerated
- Full image pixels preserved outside mask
- Two-mode operation (cost vs quality)
- Complete edit history and reversibility
- Self-hosted with external AI API calls

All components are fully functional and ready for deployment.
2026-01-24 02:58:41 +00:00