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
75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
from pydantic_settings import BaseSettings
|
|
from typing import List
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# Database
|
|
database_url: str = "sqlite:///./data/ai_photo_edit.db"
|
|
|
|
# Security
|
|
secret_key: str = "your-secret-key-change-in-production"
|
|
algorithm: str = "HS256"
|
|
access_token_expire_minutes: int = 30
|
|
|
|
# AI Provider
|
|
# Local: blank or "mock" — always available, no config needed
|
|
# Remote default (used for any operation without a specific override):
|
|
# openai | invokeai | comfyui | replicate | stability
|
|
ai_provider: str = "mock"
|
|
|
|
# Per-operation provider overrides — blank means use ai_provider default.
|
|
# Operations: inpaint, txt2img, img2img, outpaint
|
|
# Example: AI_PROVIDER_TXT2IMG=openai (use OpenAI for text-to-image only)
|
|
ai_provider_inpaint: str = "" # remote inpaint / replace selection
|
|
ai_provider_txt2img: str = "" # text-to-image
|
|
ai_provider_img2img: str = "" # image-to-image
|
|
ai_provider_outpaint: str = "" # expand canvas
|
|
|
|
# Provider API Keys
|
|
openai_api_key: str = ""
|
|
openai_model: str = "dall-e-3"
|
|
stability_api_key: str = ""
|
|
replicate_api_key: str = ""
|
|
|
|
# InvokeAI (self-hosted)
|
|
invokeai_url: str = ""
|
|
invokeai_default_model: str = "flux-dev"
|
|
|
|
# ComfyUI (self-hosted)
|
|
comfyui_url: str = ""
|
|
comfyui_default_model: str = "v1-5-pruned-emaonly.ckpt"
|
|
|
|
# Model Selection (optional, provider-specific)
|
|
stability_model: str = "sdxl" # Options: sdxl, sd15, sd21
|
|
replicate_model: str = "sdxl-inpaint" # Options: sdxl-inpaint, lama, realistic-vision
|
|
|
|
# Allow per-edit model override
|
|
allow_model_override: bool = True
|
|
|
|
# Local GPU diffusion (AI_PROVIDER=local_gpu)
|
|
auto_download_models: bool = True # download HF models on first use
|
|
local_gpu_max_pipelines: int = 2 # max diffusion pipelines kept in GPU memory
|
|
hf_token: str = "" # HuggingFace token (only needed for gated models)
|
|
# Override auto-selected models per operation (leave blank = auto-pick by VRAM tier)
|
|
hf_model_inpaint: str = ""
|
|
hf_model_txt2img: str = ""
|
|
hf_model_img2img: str = ""
|
|
|
|
# File Storage
|
|
data_dir: str = "./data"
|
|
max_upload_size_mb: int = 50
|
|
|
|
# CORS
|
|
cors_origins: str = "http://localhost:3000,http://localhost:5173"
|
|
|
|
@property
|
|
def cors_origins_list(self) -> List[str]:
|
|
return [origin.strip() for origin in self.cors_origins.split(",")]
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
case_sensitive = False
|
|
|
|
|
|
settings = Settings()
|