Metadata-Version: 2.3
Name: confyui
Version: 0.1.0
Summary: KpihX sovereign local image generation and editing daemon over ComfyUI (txt2img, img2img, inpaint; XPU-first)
Author: KpihX
Author-email: KpihX <kapoivha@gmail.com>
Requires-Dist: fastapi>=0.159.1
Requires-Dist: httpx>=0.28.1
Requires-Dist: huggingface-hub>=2.2.0
Requires-Dist: pillow>=13.0.0
Requires-Dist: psutil>=7.2.2
Requires-Dist: python-dotenv>=1.2.4
Requires-Dist: rich>=15.0.0
Requires-Dist: typer>=0.27.3
Requires-Dist: uvicorn>=0.54.0
Requires-Dist: torch>=2.8 ; extra == 'cpu'
Requires-Dist: torchvision>=0.23 ; extra == 'cpu'
Requires-Dist: torch>=2.8 ; extra == 'cuda'
Requires-Dist: torchvision>=0.23 ; extra == 'cuda'
Requires-Dist: transformers>=4.56 ; extra == 'cuda'
Requires-Dist: accelerate>=1.10.1 ; extra == 'cuda'
Requires-Dist: huggingface-hub>=0.34.4 ; extra == 'cuda'
Requires-Dist: safetensors>=0.6.2 ; extra == 'cuda'
Requires-Dist: torch>=2.8 ; extra == 'xpu'
Requires-Dist: torchvision>=0.23 ; extra == 'xpu'
Requires-Dist: transformers>=4.56 ; extra == 'xpu'
Requires-Dist: accelerate>=1.10.1 ; extra == 'xpu'
Requires-Dist: huggingface-hub>=0.34.4 ; extra == 'xpu'
Requires-Dist: safetensors>=0.6.2 ; extra == 'xpu'
Requires-Python: >=3.12
Provides-Extra: cpu
Provides-Extra: cuda
Provides-Extra: xpu
Description-Content-Type: text/markdown

# confyui

KπX sovereign local image generation and editing daemon over ComfyUI.

Hardware-accelerated on Intel Arc (XPU) via PyTorch XPU wheels, with portable CPU and CUDA extras.

## Philosophy

- **0 Magic:** The CLI talks to ComfyUI's standard REST API via structured JSON graphs.
- **0 Manual Start:** The first call (`generate`, `edit`, `inpaint`) automatically starts ComfyUI in the background.
- **0 Wasted RAM:** An idle watchdog shuts ComfyUI down after `CONFYUI_IDLE_TIMEOUT` seconds of inactivity (default: 30 minutes).
- **0 Hardcoding:** Paths expand `$HOME` at runtime and are 100% overridable via environment variables.

---

## Installation

```bash
# Clone or navigate to the repository
cd ~/Labs/KpihX-Labs/AI/confyui

# Intel Arc workstation (XPU)
make sync-xpu
# or: uv sync --extra xpu

# Generic CPU fallback
make sync-cpu

# NVIDIA CUDA host
make sync-cuda
```

---

## Environment Variables

| Variable | Default | Description |
|---|---|---|
| `CONFYUI_DIR` | `~/RAW/comfyui-local/ComfyUI` | Path to the ComfyUI checkout |
| `CONFYUI_PYTHON` | `$CONFYUI_DIR/.venv/bin/python` | Python interpreter used to run ComfyUI |
| `CONFYUI_HOST` | `127.0.0.1` | Bind address |
| `CONFYUI_PORT` | `8188` | Port |
| `CONFYUI_IDLE_TIMEOUT` | `1800` | Seconds of inactivity before auto-shutdown |
| `CONFYUI_SPAWN_TIMEOUT` | `90` | Max seconds to wait for daemon readiness |
| `CONFYUI_STATE_DIR` | `~/.cache/confyui` | Directory for PID, logs, and heartbeat |
| `CONFYUI_DEFAULT_CKPT` | `Realistic_Vision_V5.1_noVAE.safetensors` | Default checkpoint for txt2img & img2img |
| `CONFYUI_INPAINT_CKPT` | `Realistic_Vision_V5.1_fp16-no-ema-inpainting.safetensors` | Default inpainting checkpoint |

---

## Usage

### 1. Text-to-Image (`generate`)

```bash
# Minimal
uv run confyui generate "a red panda wearing a top hat on the moon, cinematic lighting"

# Full options
uv run confyui generate "a red panda wearing a top hat on the moon" \
    --negative "blurry, low quality, artifacts" \
    --width 512 \
    --height 512 \
    --steps 20 \
    --cfg 7.0 \
    --seed 42 \
    --sampler euler \
    --scheduler normal \
    --model "Realistic_Vision_V5.1_noVAE.safetensors" \
    --out panda_moon.png
```

### 2. Image-to-Image (`edit`)

Modifies an existing image based on a prompt. The source image is kept and only altered proportionally to `--denoise` (0.0 = unchanged, 0.45-0.60 = balanced modification, 1.0 = total repaint):

```bash
uv run confyui edit panda_moon.png "make the red panda wear a golden astronaut suit" \
    --denoise 0.50 \
    --steps 20 \
    --out panda_astronaut.png
```

### 3. Inpainting (`inpaint`)

Repaints only the masked region (white pixels in the mask are regenerated, black pixels preserved):

```bash
uv run confyui inpaint portrait.png torso_mask.png "she wears a long red silk dress" \
    --denoise 1.0 \
    --steps 25 \
    --out portrait_red_dress.png
```

### 4. Daemon Management

```bash
# Inspect status, uptime, PID, and idle time remaining
uv run confyui status

# List installed checkpoints
uv run confyui models

# Stop the daemon immediately to free RAM and VRAM
uv run confyui stop
```

---

## Development

```bash
make help     # Show available targets
make check    # Lint (ruff), format check, compile, pyright, pytest
make smoke    # Fast sanity check of CLI and imports
make demo     # Run a real 12-step test generation
```
