Edit photos by describing the change, on your own GPU. A free, open-source alternative to Nano Banana and ChatGPT image editing: photos stay on your computer, no daily limit. One installer for Windows, Mac and Linux sets up the best open model (Qwen-Image 2.1). MCP server for AI agents.
TypeScript ai-photo-editorcomfyui-alternativegenerative-fillimage-editingimage-generationinpaintinglinuxlocal-aimacosmcpmcp-servernano-banana-alternativeofflinephoto-editorprivacyqwen-imageqwen-image-2-1stable-diffusion-cppvulkanwindows
Rewrite README for launch
Gabriele Lozuponeb6f7d6737dda
diff --git a/README.md b/README.mdindex e5bedd2..c56b80d 100644--- a/README.md+++ b/README.md@@ -1,196 +1,272 @@-# Qwen Local Studio+<!-- Replace OWNER with the GitHub user or org before publishing (also in crates/qls-core/src/catalog.rs ISSUES_URL). -->++<p align="center">+ <picture>+ <source media="(prefers-color-scheme: dark)" srcset="assets/brand/logo/kokon-logo-white.svg">+ <img src="assets/brand/logo/kokon-logo.svg" alt="Kokon" width="300">+ </picture>+</p>++<h3 align="center">Edit photos by describing the change, on your own GPU.</h3>++<p align="center">+ One installer, no Python, no cloud. Powered by Qwen-Image 2.1, and ready for your AI agent.+</p>++<p align="center">+ <a href="https://github.com/OWNER/kokon/releases/latest"><img src="https://img.shields.io/github/v/release/OWNER/kokon?style=flat-square&color=6b6b6b&labelColor=333&label=release" alt="Latest release"></a>+ <a href="https://github.com/OWNER/kokon/releases"><img src="https://img.shields.io/github/downloads/OWNER/kokon/total?style=flat-square&color=6b6b6b&labelColor=333" alt="Downloads"></a>+ <img src="https://img.shields.io/badge/Windows-10%20%7C%2011-6b6b6b?labelColor=333&style=flat-square&logo=windows&logoColor=white" alt="Windows 10 and 11">+ <img src="https://img.shields.io/badge/NVIDIA-12%20GB%2B-6b6b6b?labelColor=333&style=flat-square&logo=nvidia&logoColor=76B900" alt="NVIDIA, 12 GB or more">+ <a href="#use-it-from-your-ai-agent"><img src="https://img.shields.io/badge/MCP-server%20included-6b6b6b?labelColor=333&style=flat-square" alt="MCP server included"></a>+ <a href="LICENSE"><img src="https://img.shields.io/github/license/OWNER/kokon?style=flat-square&color=6b6b6b&labelColor=333" alt="License"></a>+ <a href="https://github.com/OWNER/kokon/stargazers"><img src="https://img.shields.io/github/stars/OWNER/kokon?style=flat-square&color=6b6b6b&labelColor=333" alt="Stars"></a>+</p>++<p align="center">+ <a href="#install">Install</a> ·+ <a href="#what-you-can-do">Features</a> ·+ <a href="#examples">Examples</a> ·+ <a href="#use-it-from-your-ai-agent">AI agents</a> ·+ <a href="#faq">FAQ</a> ·+ <a href="docs/engineering-notes.md">How it works</a>+</p>++<p align="center">+ <img src="docs/media/demo.gif" alt="Kokon: open a photo, type a sentence, get the edited photo" width="860">+</p>++<p align="center">+ <a href="https://github.com/OWNER/kokon/releases/latest">+ <picture>+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/badge/Download%20for%20Windows-F7F6F2?style=for-the-badge&logo=windows&logoColor=0D0D0D">+ <img src="https://img.shields.io/badge/Download%20for%20Windows-0D0D0D?style=for-the-badge&logo=windows&logoColor=white" alt="Download for Windows" height="44">+ </picture>+ </a>+ <br>+ <sub>Free and open source · about 12 GB of models downloaded on first run · nothing leaves your PC</sub>+</p>++---++## Why Kokon++<table>+ <tr>+ <td width="33%" valign="top">+ <h3>✍️ Just describe it</h3>+ “Remove the people in the background.” “Make it golden hour.” Kokon picks the mode, the+ resolution and the memory settings for you. There are no sliders to learn.+ </td>+ <td width="33%" valign="top">+ <h3>🔒 Private by design</h3>+ Everything runs on your own GPU. No account, no uploads, no telemetry. After setup,+ Kokon talks only to <code>127.0.0.1</code>. A private mode keeps nothing at all.+ </td>+ <td width="33%" valign="top">+ <h3>📦 One installer</h3>+ A native app built on <a href="https://github.com/leejet/stable-diffusion.cpp">stable-diffusion.cpp</a>.+ No Python, no ComfyUI, no node graphs. The first run detects your GPU and downloads the+ right model, then verifies it.+ </td>+ </tr>+ <tr>+ <td width="33%" valign="top">+ <h3>🎯 Edits that stay in place</h3>+ Paint over an area and choose Change, Remove, Replace or Add. Kokon shows the model+ exactly where to work, so the rest of the photo stays untouched.+ </td>+ <td width="33%" valign="top">+ <h3>🖼️ Full-size results</h3>+ Kokon keeps your photo's size and aspect ratio, and enlarges with an AI upscaler+ instead of blurry resizing. It also opens iPhone HEIC photos, HDR included.+ </td>+ <td width="33%" valign="top">+ <h3>🤖 Works with your AI agent</h3>+ A built-in MCP server and local HTTP API let Claude, Cursor or your own scripts create+ and edit images on your machine.+ </td>+ </tr>+</table>++## Examples++Every result below came from one sentence in Kokon, with default settings.++| | |+| :---: | :---: |+| <img src="docs/media/examples/remove.jpg" alt="Remove people from the background"><br>**Remove** · *“Remove the people in the background”* | <img src="docs/media/examples/replace.jpg" alt="Replace an object"><br>**Replace** · *“Replace the red car with a blue vintage bicycle”* |+| <img src="docs/media/examples/relight.jpg" alt="Relight a scene"><br>**Relight** · *“Make it golden hour, warm low sunlight”* | <img src="docs/media/examples/restyle.jpg" alt="Restyle a photo"><br>**Restyle** · *“Turn it into a watercolor illustration”* |+| <img src="docs/media/examples/text.jpg" alt="Change text in a photo"><br>**Text** · *“Change the shop sign to say ‘OPEN LATE’”* | <img src="docs/media/examples/expand.jpg" alt="Expand a photo"><br>**Expand** · *“Expand to 16:9, continue the beach”* |++## Install++**1. Download** `Kokon Setup.exe` from the [latest release](https://github.com/OWNER/kokon/releases/latest) and run it. It installs for your user only, so you don't need administrator rights.++**2. Set up models.** On first launch Kokon shows your GPU, VRAM and RAM, recommends a preset+and downloads everything it needs. The download resumes if it is interrupted and every file+is checked against its SHA-256 checksum. On a fast connection the whole thing takes a few minutes.++**3. Edit.** Drop or paste a photo, describe the change and press <kbd>Enter</kbd>.++### Requirements++| | Minimum | Recommended |+| --- | --- | --- |+| **OS** | Windows 10 64-bit | Windows 11 |+| **GPU** | NVIDIA, 12 GB VRAM (RTX 3060 12 GB, 4070) | NVIDIA, 16 GB+ VRAM (RTX 4080, 5070 Ti, 5080, 4090, 5090) |+| **RAM** | 16 GB | 32 GB |+| **Disk** | 15 GB free | 25 GB free on an SSD |+| **Time per edit** <!-- TODO re-measure at CFG 1 before launch --> | Fast mode: about half of Balanced | About 1 minute at Balanced on a 16 GB RTX 5070 Ti |-Local image generation and editing for Windows, built on-[stable-diffusion.cpp](https://github.com/leejet/stable-diffusion.cpp) and Qwen-Image 2.1.-Everything runs on this PC: no telemetry, no uploads, no cloud calls. All services-listen on `127.0.0.1` only.+> [!NOTE]+> Kokon needs an NVIDIA GPU for now. AMD and Intel support (Vulkan) is on the [roadmap](#roadmap).-- Text to image, edit, multi-reference, inpaint, outpaint (expand), upscale-- One diffusion pass per image, then ESRGAN (UltraSharp by default) instead of plain- resizing whenever the result is enlarged to its final size-- Automatic mode, resolution and memory decisions; advanced controls stay hidden-- Persistent local gallery with metadata (also embedded in the PNGs)-- MCP server for Claude Code and other MCP hosts, plus a stable local HTTP API+<details>+<summary><b>Model presets: what gets downloaded</b></summary>+<br>-## Architecture+The setup screen picks a preset from your VRAM. You can change it later from Settings → Models → **Set up models…**-```-Qwen Local Studio.exe (Tauri 2 + React) qls-mcp.exe (MCP, stdio) scripts- │ loopback HTTP + SSE, token │ │- └──────────────────────────────┬────────────┴────────────────────────┘- ▼- qls-service.exe — stable API http://127.0.0.1:39151/api/v1- (engine: planner · preprocessing · job queue · gallery)- │ native async API /sdcpp/v1/*- ▼- sd-server.exe (stable-diffusion.cpp) 127.0.0.1:39150-```+| Preset | Diffusion model | Text encoder (in RAM) | Download | Tested on real hardware |+| --- | --- | --- | --- | --- |+| 12 GB | Qwen-Image 2.1 Q4_K_M (4.2 GB) | Qwen3-VL 8B Q4_K_M | ~12 GB | in beta (emulated on a 16 GB card) |+| 16 GB | Qwen-Image 2.1 Q4_K_M | Qwen3-VL 8B Q4_K_M | ~12 GB | ✅ RTX 5070 Ti |+| 24 GB | Qwen-Image 2.1 Q8_0 (7.6 GB) | Qwen3-VL 8B Q4_K_M | ~15 GB | not yet |+| 32 GB+ | Qwen-Image 2.1 Q8_0 | Qwen3-VL 8B Q8_0 (8.7 GB) | ~19 GB | not yet |-| Crate / package | Responsibility |-| --- | --- |-| `crates/qls-core/src/geometry.rs` | Pure dimension math: 32-alignment, working canvas, outpaint/inpaint geometry |-| `imaging.rs` | EXIF orientation, alpha-safe resize, padding, masks, compositing, PNG metadata/ICC |-| `planner.rs` | Mode detection, resolution policy, upscale targets, VRAM budget |-| `pipeline.rs` | Builds backend requests, post-processes results (crop back, ESRGAN tiling, composite) |-| `sdcpp.rs` | Inference adapter — the only code that knows sd-server's schema |-| `process.rs` | sd-server launch/reuse/stop, log capture, truthful progress parsing |-| `engine.rs` | Async job queue, cancellation, OOM retry, saving |-| `store.rs` | SQLite gallery + content-addressed inputs |-| `paths.rs` | Path validation (no UNC/device/ADS/traversal, never overwrite) |-| `crates/qls-service` | Headless service and stable HTTP API; single instance; lifecycle |-| `src-tauri`, `src/` | Desktop shell (Rust) and UI (React + TypeScript) |-| `mcp/` | MCP server (TypeScript, official SDK) |--### Verified backend facts (stable-diffusion.cpp commit `3f8527a`)--- Native async API: `POST /sdcpp/v1/img_gen` → `GET /sdcpp/v1/jobs/{id}`; cancel works only for- queued jobs (`cancel_generating: false`). Cancelling a running job therefore restarts the- server when this app launched it.-- Qwen-Image 2.1 editing uses `ref_images` (labelled `<image1>`, `<image2>`… in order);- references and canvas must be multiples of 32. Inpainting uses `init_image` + binary- `mask_image` (white = regenerate).-- Recommended settings follow the official Qwen-Image 2.1 release (QwenLM/Qwen-Image-2.1- README, diffusers `QwenImage21Pipeline`): `euler`, **no CFG** (1.0, "meant to be sampled- without guidance"), 40 steps, native 2K sizes; sd-server picks the same resolution-dependent- flow schedule (exponential shift 0.5–0.9, terminal 0.02). sd.cpp's own docs use CFG 6, which- runs a second, unconditional model pass every step; the app used that until 2026-10-07.- At CFG 1 the negative prompt is ignored.- Presets: Fast 20 steps at ~1 MP (a shortcut, not official); Balanced 40 steps at ~1 MP;- Quality 40 steps at the official 2K buckets (2048², 2752×1536…; edits share that budget- with their reference images, so they land near 2 MP on 16 GB).-- Default launch: `--backend cuda0 --params-backend te=cpu --fa --sage-attn --vae-tiling- --vae-tile-size 768 --vae-tile-overlap 0.125 --max-vram -1` plus `--hires-upscalers-dir`- when the upscalers folder exists (text-encoder weights in RAM, computed on the GPU). Measured- on an RTX 5070 Ti: running the text encoder fully on the CPU made a one-image edit take 240 s- versus 61 s; SageAttention makes 2K steps ~32 % faster; untiled 2K VAE decodes OOM and fall- back to 256 px tiles (~22 s), 768 px tiles take ~4 s.-- Request objects are merged field by field over the server's launch options, so omitted- fields keep the CLI values (per-request VAE tiling is only sent to turn it off).-- `img_gen` accepts a `hires` object (second pass: upscale with a built-in filter or an ESRGAN- model from `--hires-upscalers-dir`, then re-sample at `denoising_strength`); reference- latents and inpaint masks are carried into that pass. `cache_mode`/`cache_option`- (e.g. `easycache`, `threshold=0.2`) work per request. `POST /sdcpp/v1/upscale`- (`{image, upscaler}`) runs ESRGAN synchronously, up to 8192 px per side.-- Qwen-Image 2.1 always decodes an alpha channel (≈1 % of pixels at alpha 247–254 on opaque- images); outputs are made opaque unless transparency is requested.--## Using the app--Drop, paste (Ctrl+V) or add images, describe the result, press Enter.--- **No image** → text to image (aspect from the prompt or the aspect menu)-- **One image** → edit; the original size and aspect ratio are kept-- **Several images** → combine; refer to them as image 1, image 2… (drag to reorder)-- **Brush** → paint a mask, then describe what goes there (inpainting)-- **Expand** → drag the edges or type pixel/percent values (outpainting)--Results offer Edit, Variation, Use as reference, Inpaint, Expand, Upscale, Favorite, Save, Copy-and Show in Explorer. The gallery (grid icon) reopens any previous generation with its recipe.--### Large images and upscaling--Every job runs a single diffusion pass at the working size (Auto: ~1 MP for Fast/Balanced,-native 2K for Quality; or the 1K/1.5K/2K/Source/Custom choice), capped by the VRAM token budget-that the target shares with its reference images. The earlier two-pass mode (≈1 MP render →-ESRGAN → low-denoise refine at 2K) was removed on 2026-10-06: in A/B tests the refine made-edits look worse than a single pass.--Whenever a result is larger than what the model rendered (edits restored to the source size,-outpaint, sizes above the VRAM budget) it is enlarged with ESRGAN ×4 and then resized down to the exact-size; Lanczos is only used for shrinking or factors below 1.1×.--The **Upscale** button (on results and inputs) offers 2×, 4K, the original source size or a-custom width, with two methods:--- **Quick**: ESRGAN only, a few seconds; adds no new content.-- **Detailed**: re-renders fine detail with a low-denoise (0.3) img2img pass at about 2K, then- ESRGAN to the target. About a minute.--The result is saved as a new gallery item linked to its source. The Details panel shows the-pipeline (e.g. `1376×768 → 5120×2880 (UltraSharp)`).--**HEIC and HDR.** HEIC/HEIF photos can be opened like any other image (picker, drag & drop);-they are decoded by Windows' HEIF codec, so Microsoft's "HEIF Image Extensions" and "HEVC Video-Extensions" must be installed. iPhone photos with an HDR gain map (ISO 21496-1, iOS 18+) show a-**Keep HDR** switch in Advanced (on by default): edits, inpainting and upscales of such a photo are-saved as an **Ultra HDR JPEG** (SDR image + gain map), which Chrome/Edge, Android and recent-Apple systems show in HDR and every other viewer as a normal JPEG. The model itself works in SDR;-the source's gain map is reused and faded out where the edit changed brightness by more than-~¼ stop (gone at 1 stop). Reading the gain map needs `ffmpeg` (7.1+) on PATH; without it, or-when the result's framing differs from the source (outpaint, other aspect ratios), the result is-saved in SDR and the job's notes say why.--**Upscaler model.** Settings → Models offers two ESRGAN models (64 MB each), used for-enlarging results and for the Upscale button: **UltraSharp** (default,-`4x-UltraSharp.pth`) and **Superscale-SP** (`4x_NMKD-Superscale-SP_178000_G.pth`). Both keep-fine texture that RealESRGAN_x4plus smooths away. Put them in-`<stable-diffusion.cpp folder>\models\upscalers\`. The app does not download models: get them-from <https://huggingface.co/uwg/upscaler/tree/main/ESRGAN>. UltraSharp is licensed-CC BY-NC-SA 4.0 (non-commercial). Without the selected model everything still works, with-Lanczos instead of ESRGAN; the setup screen reports whether the model was found.--Data locations:+Every preset also gets stable-diffusion.cpp (CUDA 12 build), the Qwen-Image 2.1 VAE, the+Qwen3-VL vision projector and, optionally, the 4x-UltraSharp upscaler. The sources are the+official [Qwen-Image 2.1](https://huggingface.co/Qwen/Qwen-Image-2.1) weights through+[unsloth/Qwen-Image-2.1-GGUF](https://huggingface.co/unsloth/Qwen-Image-2.1-GGUF),+[Qwen/Qwen3-VL-8B-Instruct-GGUF](https://huggingface.co/Qwen/Qwen3-VL-8B-Instruct-GGUF) and+[Comfy-Org/Qwen-Image-2.1](https://huggingface.co/Comfy-Org/Qwen-Image-2.1).-| What | Where |-| --- | --- |-| Images | `%USERPROFILE%\Pictures\Qwen Local Studio\<date>\` (configurable) |-| Settings | `%APPDATA%\Qwen Local Studio\config.json` |-| Gallery DB, inputs, thumbnails, logs | `%LOCALAPPDATA%\QwenLocalStudio\` |-| API port + token | `%LOCALAPPDATA%\QwenLocalStudio\service.json` |+Files go to `%LOCALAPPDATA%\KokonData\sdcpp` by default. You can point the setup screen at an+existing stable-diffusion.cpp folder instead; files that are already there are kept.+Other weights, such as fine-tunes, can be selected in Settings → Models.-## MCP (Claude Code)+</details>-The installer places `qls-mcp.exe` next to the app. Register it once (user scope, available in-every project):+## What you can do-```powershell-claude mcp add --scope user qwen-local -- "$env:LOCALAPPDATA\Qwen Local Studio\qls-mcp.exe"+| You give Kokon | It does | |+| --- | --- | --- |+| A sentence | **Create** a new image | Aspect ratio from the prompt or the aspect menu |+| A photo + a sentence | **Edit** it | Original size and aspect ratio are kept |+| Several photos + a sentence | **Combine** them | Refer to them as “image 1”, “image 2”… and drag to reorder |+| A brushed area + an action | **Inpaint**: Change, Remove, Replace or Add | Remove needs no prompt |+| Dragged edges | **Expand** the photo (outpainting) | Or type pixel or percent values |+| Any result | **Upscale** to 2×, 4K, the source size or a custom width | Quick (seconds) or Detailed (about a minute) |++<p align="center">+ <img src="docs/media/screenshot-app.png" alt="The Kokon window with a result and the before/after slider" width="860">+</p>++Every result can be edited again, varied, used as a reference, upscaled, saved, copied or+opened in Explorer. A few things make that loop fast:++- **Before/after**: compare with Slider, Flicker or Changes, or hold <kbd>B</kbd> to see the original.+- **Undo/redo between versions** with <kbd>Ctrl</kbd>+<kbd>Z</kbd> / <kbd>Ctrl</kbd>+<kbd>Y</kbd>.+ Undo returns to the version the current one came from, and nothing is ever deleted.+- **Gallery**: every image keeps its full recipe (prompt, seed, settings, pipeline) and reopens+ with one click. The recipe is also embedded in the PNG.+- **Quality presets**: Fast, Balanced and Quality (native 2K). They follow the official+ Qwen-Image 2.1 settings, so you never need to tune steps or guidance.++## How it works++```mermaid+flowchart LR+ A["📷 Your photo<br>+ a sentence"] --> B["Planner<br><sub>mode · size · VRAM budget</sub>"]+ B --> C["Qwen-Image 2.1<br><sub>stable-diffusion.cpp<br>on your GPU</sub>"]+ C --> D["AI upscaler<br><sub>ESRGAN, back to<br>full size</sub>"]+ D --> E["🖼️ Result<br><sub>gallery + recipe</sub>"]+ M["🤖 Claude · Cursor · scripts"] -. "MCP / local API" .-> B```-Equivalent JSON form:+The planner decides what kind of job your request is, picks a working size that fits your GPU+and runs a single diffusion pass. When the result has to be larger than what the model rendered,+it is enlarged with ESRGAN instead of a plain resize. For brushed edits, Kokon marks the area on+a second reference image so the model knows exactly where to work. Without that, Qwen-Image 2.1+cannot see the mask.++Want the details? The [engineering notes](docs/engineering-notes.md) cover the architecture,+the measured backend settings and the reasons behind each default.++## Use it from your AI agent++Kokon ships `kokon-mcp.exe`, an [MCP](https://modelcontextprotocol.io) server. Register it once+with Claude Code:```powershell-claude mcp add-json --scope user qwen-local '{"type":"stdio","command":"C:\\Users\\<you>\\AppData\\Local\\Qwen Local Studio\\qls-mcp.exe","args":[]}'+claude mcp add --scope user kokon -- "$env:LOCALAPPDATA\Kokon\kokon-mcp.exe"```-Project-scoped `.mcp.json` example:+Then ask: *“Generate a hero image for this README and save it in docs/”* or *“Remove the+background clutter from screenshot.png”*. The app doesn't need to be open, because the MCP server+starts the engine on demand. The first call takes about a minute while the model loads.++**Tools:** `generate_image` · `edit_image` · `edit_images` · `inpaint_image` · `outpaint_image` · `upscale_image` · `get_image_info` · `get_generator_status`++<details>+<summary><b>Other MCP hosts (JSON config)</b></summary>+<br>++Project-scoped `.mcp.json`, or any host that takes the standard format:```json{"mcpServers": {- "qwen-local": {+ "kokon": {"type": "stdio",- "command": "C:\\Users\\<you>\\AppData\\Local\\Qwen Local Studio\\qls-mcp.exe",+ "command": "C:\\Users\\<you>\\AppData\\Local\\Kokon\\kokon-mcp.exe","args": []}}}```-Tools: `generate_image`, `edit_image`, `edit_images`, `outpaint_image`, `inpaint_image`,-`upscale_image`, `get_image_info`, `get_generator_status`. Every result includes the absolute-path of the saved file, its size, seed and generation metadata (including the-ESRGAN pipeline when used). `upscale_image` takes `scale` (default 2) or `width`/`height`-(up to 8192 px) and `method` (`quick` | `detailed`).--Notes:--- The app does not need to be open. The MCP server starts the service, which starts or reuses- sd-server (first call ≈ 1 min to load the model). Without the desktop window, the model is- unloaded after 15 idle minutes (Settings → General).-- Paths may be absolute or relative to the project (`CLAUDE_PROJECT_DIR`). Reads and writes- are limited to the project folder, the app's output folder, and folders listed in- `QLS_MCP_ALLOWED_DIRS` (semicolon-separated). Existing files are never overwritten.-- Images are **not** returned to the model by default (they stay local). Pass+Same thing from the command line:++```powershell+claude mcp add-json --scope user kokon '{"type":"stdio","command":"C:\\Users\\<you>\\AppData\\Local\\Kokon\\kokon-mcp.exe","args":[]}'+```++</details>++<details>+<summary><b>MCP behavior and safety</b></summary>+<br>++- Every result returns the absolute path of the saved file, its size, seed and generation metadata.+- Paths may be absolute or relative to the project (`CLAUDE_PROJECT_DIR`). Reads and writes are+ limited to the project folder, Kokon's output folder and folders listed in+ `QLS_MCP_ALLOWED_DIRS` (separated by semicolons). Existing files are never overwritten.+- Images are **not** sent back to the model by default; they stay on disk. Pass`include_preview: true` to include a small JPEG preview.-- Claude Code's default stdio tool timeout is 30 minutes (`MCP_TOOL_TIMEOUT`). Progress is- reported through MCP progress notifications.+- `upscale_image` takes `scale` (default 2) or `width`/`height` (up to 8192 px), and+ `method` (`quick` | `detailed`).+- Progress is reported through MCP progress notifications. Claude Code's default tool timeout is+ 30 minutes (`MCP_TOOL_TIMEOUT`).+- Without the desktop window open, the model is unloaded after 15 idle minutes (Settings → General).++</details>-## Stable local API+<details>+<summary><b>Local HTTP API</b></summary>+<br>-Base URL: `http://127.0.0.1:39151/api/v1`. Every call except `/ping` needs-`Authorization: Bearer <token>`, where the token comes from `service.json`. Requests carrying a-browser `Origin` header are refused.+Base URL `http://127.0.0.1:39151/api/v1`. Every call except `/ping` needs+`Authorization: Bearer <token>`, with the token from `%LOCALAPPDATA%\KokonData\service.json`.+Requests that carry a browser `Origin` header are refused.++```powershell+$i = Get-Content "$env:LOCALAPPDATA\KokonData\service.json" | ConvertFrom-Json+$h = @{ Authorization = "Bearer $($i.token)" }+Invoke-RestMethod -Method Post "http://127.0.0.1:$($i.port)/api/v1/generate" -Headers $h `+ -ContentType 'application/json' -Body '{"prompt":"a lighthouse at dusk, 16:9","quality":"fast"}'+```| Method | Path | Purpose || --- | --- | --- |@@ -205,33 +281,249 @@ browser `Origin` header are refused.| GET | `/gallery`, `/gallery/{id}`, `/gallery/{id}/image` | Gallery || POST | `/image-info` | Size, aspect, type, embedded generation metadata |-Example (PowerShell):+Simple-operation fields: `prompt`, `image` / `images[]`, `mask`, `action`+(`edit|remove|replace|add`, inpainting), `width`, `height`, `aspect_ratio`, `quality`+(`fast|balanced|quality`), `seed`, `output_path`, `preserve_dimensions`, `private`,+`left/right/top/bottom` + `units` (`pixels|percent`) for outpainting, `scale` and `method`+(`quick|detailed`) for upscaling. Full requests (`/jobs`) also accept `"mode": "upscale"` with+`"upscale": {"method", "scale" | "width"/"height"}` and `"advanced": {"refine": "fast|best"}`.-```powershell-$i = Get-Content "$env:LOCALAPPDATA\QwenLocalStudio\service.json" | ConvertFrom-Json-$h = @{ Authorization = "Bearer $($i.token)" }-Invoke-RestMethod -Method Post "http://127.0.0.1:$($i.port)/api/v1/generate" -Headers $h `- -ContentType 'application/json' -Body '{"prompt":"a lighthouse at dusk, 16:9","quality":"fast"}'-```+</details>++## Privacy++Kokon makes network requests **only from the setup screen**: to `github.com` for the+stable-diffusion.cpp release and to `huggingface.co` for the models. Creating, editing, the+gallery, the MCP server and the API talk to `127.0.0.1` only. Logs never contain your prompts.++You can check this yourself. While you work, watch `Kokon.exe`, `kokon-service.exe` and+`sd-server.exe` in Resource Monitor (Network tab), or run+`Get-NetTCPConnection -OwningProcess <pid>`.++**Private mode** (the eye icon in the top bar) keeps images and prompts out of the gallery, the+output folder and the project list. They are deleted when you turn private mode off, close the+window, or restart the service. **Save as…** still writes a copy wherever you choose.++## How it compares++Kokon does one thing: editing photos with Qwen-Image 2.1, with as little setup as possible.+If you want full control over every node, ComfyUI is the better tool.++| | **Kokon** | ComfyUI + Qwen workflow | Krita AI Diffusion | Other Qwen web UIs |+| --- | :---: | :---: | :---: | :---: |+| Install | One `.exe` | Python environment + nodes | Krita + plugin + ComfyUI | Python or ComfyUI |+| Picks size and memory settings for you | ✅ | ❌ | partly | partly |+| Brush edits the model can see | ✅ | depends on the workflow | ✅ | rarely |+| MCP server for AI agents | ✅ | community nodes | ❌ | ❌ |+| AMD / Intel GPUs | 🔜 [roadmap](#roadmap) | ✅ | ✅ | varies |+| Custom pipelines, node graphs | ❌ | ✅ | partly | ❌ |+| Painting and layers | ❌ | ❌ | ✅ | ❌ |++## FAQ++<details>+<summary><b>Windows says “Windows protected your PC”</b></summary>+<br>++SmartScreen shows this for new apps that don't have a download history yet. Click+**More info → Run anyway**. You can check the installer against the SHA-256 hash listed in the+release notes, or [build it yourself](#build-from-source).++</details>++<details>+<summary><b>Do I need an internet connection?</b></summary>+<br>++Only once, to download the models. After that Kokon works fully offline.-Simple-operation fields: `prompt`, `image` / `images[]`, `mask`, `width`, `height`,-`aspect_ratio`, `quality` (`fast|balanced|quality`), `seed`, `output_path`,-`preserve_dimensions`, `left/right/top/bottom` + `units` (`pixels|percent`) for outpainting,-`scale` and `method` (`quick|detailed`) for upscaling. Full requests (`/jobs`) also accept-`"mode": "upscale"` with `"upscale": {"method", "scale" | "width"/"height"}` and-`"advanced": {"refine": "fast|best"}` (effort of a Detailed upscale).+</details>-New settings in `config.json`: `refineMode` (`fast|best`, Detailed upscale effort; `off` is legacy), `upscalersDir` (null = default-folder), `upscalerModel` (`4x-UltraSharp`; configs on the old `RealESRGAN_x4plus` default move to it), `upscaleTileSize` (0 = backend default 128).+<details>+<summary><b>Does it work on AMD or Intel GPUs, or on a Mac?</b></summary>+<br>-## Building+Not yet. stable-diffusion.cpp also runs on Vulkan and Metal, so AMD and Intel support is the+next big item on the [roadmap](#roadmap), with macOS and Linux after that.-Requirements: Rust (stable, MSVC), Node 22+, VS Build Tools, WebView2.+</details>++<details>+<summary><b>My GPU has 8 GB. Can I still use it?</b></summary>+<br>++Not with good results today. Qwen-Image 2.1 is a large model, and 12 GB is the smallest size+Kokon is designed for. Smaller cards may come with lighter models in the future.++</details>++<details>+<summary><b>Can I use Kokon commercially?</b></summary>+<br>++Kokon's code is open source (see [License](#license)). The models have their own licenses:+Qwen-Image 2.1 is released under the Qwen license (see the+[model page](https://huggingface.co/Qwen/Qwen-Image-2.1)), and the optional 4x-UltraSharp+upscaler is CC BY-NC-SA 4.0, which means non-commercial use only. Check each license for your+use case.++</details>++<details>+<summary><b>iPhone photos (HEIC) and HDR</b></summary>+<br>++HEIC/HEIF photos open like any other image. They are decoded by Windows, so Microsoft's+**HEIF Image Extensions** and **HEVC Video Extensions** must be installed.++iPhone photos with an HDR gain map (iOS 18+) show a **Keep HDR** switch in Advanced, which is on+by default. Edits of such photos are saved as **Ultra HDR JPEG**: Chrome, Edge, Android and+recent Apple systems show them in HDR, and every other viewer shows a normal JPEG. This needs+`ffmpeg` 7.1+ on PATH; without it the result is saved in SDR and the job's notes say why.++</details>++<details>+<summary><b>Which upscaler is used, and can I change it?</b></summary>+<br>++Settings → Models offers two ESRGAN models: **UltraSharp** (default, downloaded by the setup+screen) and **Superscale-SP**. To use Superscale-SP, put+`4x_NMKD-Superscale-SP_178000_G.pth` from+[uwg/upscaler](https://huggingface.co/uwg/upscaler/tree/main/ESRGAN) into+`<stable-diffusion.cpp folder>\models\upscalers\`. Without an upscaler everything still works,+with a plain resize instead.++</details>++<details>+<summary><b>Where are my images and settings stored?</b></summary>+<br>++| What | Where |+| --- | --- |+| Images | `%USERPROFILE%\Pictures\Kokon\<date>\` (configurable) |+| Settings | `%APPDATA%\Kokon\config.json` |+| Gallery database, inputs, thumbnails, logs | `%LOCALAPPDATA%\KokonData\` |+| Models (default) | `%LOCALAPPDATA%\KokonData\sdcpp\` |+| API port and token | `%LOCALAPPDATA%\KokonData\service.json` |++</details>++<details>+<summary><b>I used Qwen Local Studio before</b></summary>+<br>++That is Kokon's old name. On its first start Kokon moves your settings, gallery and installed+models from `%APPDATA%\Qwen Local Studio` and `%LOCALAPPDATA%\QwenLocalStudio` to the new+folders. Images you already saved stay where they are. If you registered the MCP server,+register it again under its new name with the [command above](#use-it-from-your-ai-agent).++</details>++<details>+<summary><b>How do I uninstall it?</b></summary>+<br>++Use **Settings → Apps → Installed apps → Kokon → Uninstall**. Your images stay in your Pictures+folder. To free the model space too, delete `%LOCALAPPDATA%\KokonData`.++</details>++<details>+<summary><b>Something went wrong</b></summary>+<br>++If a download fails, the setup screen shows the file's download page and target folder so you+can fetch it by hand. For anything else, please+[open an issue](https://github.com/OWNER/kokon/issues/new) with your GPU, driver version and+the log from `%LOCALAPPDATA%\KokonData\logs`.++</details>++## Roadmap++- [x] Create, edit, combine, brush edits, expand, upscale+- [x] First-run setup with GPU detection and verified, resumable downloads+- [x] MCP server and local HTTP API+- [x] Before/after, version undo, private mode, HEIC and HDR+- [ ] Fast mode with a turbo LoRA (an edit in about 15 seconds)+- [ ] AMD and Intel GPUs through Vulkan+- [ ] Background removal and transparent cutouts+- [ ] Batch edits: one instruction for a whole folder+- [ ] Plugins for Krita, GIMP and Photoshop through the local API+- [ ] macOS and Linux++Have an idea? [Start a discussion](https://github.com/OWNER/kokon/discussions) or 👍 an existing one.++## Build from source++<details>+<summary><b>Requirements and commands</b></summary>+<br>++You need Rust (stable, MSVC), Node 22+, Visual Studio Build Tools and WebView2.```powershell+npm installcargo test -p qls-core # core unit testsnpx vitest run # UI logic testscd mcp; npx vitest run; cd .. # MCP tests (includes a stdio protocol test)npx tauri dev # run the desktop app in developmentpowershell -ExecutionPolicy Bypass -File scripts\build-release.ps1 # installer```++</details>++<details>+<summary><b>Architecture</b></summary>+<br>++```mermaid+flowchart TB+ UI["<b>Kokon.exe</b><br>Tauri 2 + React"]+ MCP["<b>kokon-mcp.exe</b><br>MCP over stdio"]+ S["Scripts and other apps"]+ SVC["<b>kokon-service.exe</b><br>planner · preprocessing · job queue · gallery<br><code>127.0.0.1:39151/api/v1</code>"]+ SD["<b>sd-server.exe</b><br>stable-diffusion.cpp<br><code>127.0.0.1:39150</code>"]+ UI -- "HTTP + SSE, token" --> SVC+ MCP -- "HTTP, token" --> SVC+ S -- "HTTP, token" --> SVC+ SVC -- "native async API" --> SD+```++The Rust core (`crates/qls-core`) holds all the logic: geometry, image processing, planning,+the inference adapter, the job queue and the gallery. The service, the desktop app and the+MCP server are thin layers on top. See the [engineering notes](docs/engineering-notes.md)+for a module map and the backend facts each default is based on.++</details>++## Contributing++Bug reports, translations, example prompts and pull requests are all welcome. Issues tagged+[good first issue](https://github.com/OWNER/kokon/labels/good%20first%20issue) are a good+place to start. Please run the tests above before opening a pull request.++## Responsible use++Kokon edits real photos. Don't use it to deceive, harass or impersonate people, or to make+images of someone without their consent. You are responsible for what you create and share.++## License++Kokon's source code is released under the [GNU Affero General Public License v3.0](LICENSE) (AGPL-3.0-only). Model weights and the+upscaler are downloaded from their authors and keep their own licenses (see the+[FAQ](#faq)).++Kokon builds on [stable-diffusion.cpp](https://github.com/leejet/stable-diffusion.cpp) by+leejet, [Qwen-Image 2.1](https://huggingface.co/Qwen/Qwen-Image-2.1) by the Qwen team,+[Unsloth](https://huggingface.co/unsloth)'s GGUF conversions, [Tauri](https://tauri.app) and+4x-UltraSharp by Kim2091. Thank you.++<p align="center">+ <br>+ <img src="assets/brand/icon/kokon-icon-256.png" alt="" width="48">+ <br>+ <sub>Made for people who would rather type a sentence than wire up a pipeline.</sub>+</p>diff --git a/docs/engineering-notes.md b/docs/engineering-notes.mdnew file mode 100644index 0000000..d5bb685--- /dev/null+++ b/docs/engineering-notes.md@@ -0,0 +1,125 @@+# Engineering notes++How Kokon works inside, and the backend facts its design depends on. For using the app, see the+[README](../README.md).++## Architecture++```+Kokon.exe (Tauri 2 + React) kokon-mcp.exe (MCP, stdio) scripts+ │ loopback HTTP + SSE, token │ │+ └──────────────────────────────┬────────────┴────────────────────────┘+ ▼+ kokon-service.exe — stable API http://127.0.0.1:39151/api/v1+ (engine: planner · preprocessing · job queue · gallery)+ │ native async API /sdcpp/v1/*+ ▼+ sd-server.exe (stable-diffusion.cpp) 127.0.0.1:39150+```++| Crate / package | Responsibility |+| --- | --- |+| `crates/qls-core/src/geometry.rs` | Pure dimension math: 32-alignment, working canvas, outpaint/inpaint geometry |+| `imaging.rs` | EXIF orientation, alpha-safe resize, padding, masks, compositing, PNG metadata/ICC |+| `planner.rs` | Mode detection, resolution policy, upscale targets, VRAM budget |+| `pipeline.rs` | Builds backend requests, post-processes results (crop back, ESRGAN tiling, composite) |+| `sdcpp.rs` | Inference adapter — the only code that knows sd-server's schema |+| `process.rs` | sd-server launch/reuse/stop, log capture, truthful progress parsing |+| `engine.rs` | Async job queue, cancellation, OOM retry, saving |+| `store.rs` | SQLite gallery + content-addressed inputs |+| `paths.rs` | Path validation (no UNC/device/ADS/traversal, never overwrite) |+| `catalog.rs`, `installer.rs` | Pinned downloads (URLs, sizes, SHA-256), hardware presets, parallel resumable downloader |+| `crates/qls-service` | Headless service and stable HTTP API; single instance; lifecycle |+| `src-tauri`, `src/` | Desktop shell (Rust) and UI (React + TypeScript) |+| `mcp/` | MCP server (TypeScript, official SDK) |++Internal names (`qls-core`, `qls-service`, `QLS_*` environment variables) date from the project's+earlier name, Qwen Local Studio, and are kept on purpose.++## Verified backend facts (stable-diffusion.cpp commit `3f8527a`)++- Native async API: `POST /sdcpp/v1/img_gen` → `GET /sdcpp/v1/jobs/{id}`; cancel works only for+ queued jobs (`cancel_generating: false`). Cancelling a running job therefore restarts the+ server when this app launched it.+- Qwen-Image 2.1 editing uses `ref_images` (labelled `<image1>`, `<image2>`… in order);+ references and canvas must be multiples of 32. Inpainting uses `init_image` + binary+ `mask_image` (white = regenerate). For Qwen 2.1 that mask is only a latent blend (it+ discards changes outside it; the model never sees it), so the app also sends the area+ marked in color on a second reference and prompts "the area marked in red in `<image2>`"+ (the official 2.1 way to point at a region). Removals blur the content out of `<image1>`+ first so the model rebuilds background instead of copying the object back.+- Recommended settings follow the official Qwen-Image 2.1 release (QwenLM/Qwen-Image-2.1+ README, diffusers `QwenImage21Pipeline`): `euler`, **no CFG** (1.0, "meant to be sampled+ without guidance"), 40 steps, native 2K sizes; sd-server picks the same resolution-dependent+ flow schedule (exponential shift 0.5–0.9, terminal 0.02). sd.cpp's own docs use CFG 6, which+ runs a second, unconditional model pass every step; the app used that until 2026-10-07.+ At CFG 1 the negative prompt is ignored.+ Presets: Fast 20 steps at ~1 MP (a shortcut, not official); Balanced 40 steps at ~1 MP;+ Quality 40 steps at the official 2K buckets (2048², 2752×1536…; edits share that budget+ with their reference images, so they land near 2 MP on 16 GB).+- Default launch: `--backend cuda0 --params-backend te=cpu --fa --sage-attn --vae-tiling+ --vae-tile-size 768 --vae-tile-overlap 0.125 --max-vram -1` plus `--hires-upscalers-dir`+ when the upscalers folder exists (text-encoder weights in RAM, computed on the GPU). Measured+ on an RTX 5070 Ti: running the text encoder fully on the CPU made a one-image edit take 240 s+ versus 61 s; SageAttention makes 2K steps ~32 % faster; untiled 2K VAE decodes OOM and fall+ back to 256 px tiles (~22 s), 768 px tiles take ~4 s.+- Request objects are merged field by field over the server's launch options, so omitted+ fields keep the CLI values (per-request VAE tiling is only sent to turn it off).+- `img_gen` accepts a `hires` object (second pass: upscale with a built-in filter or an ESRGAN+ model from `--hires-upscalers-dir`, then re-sample at `denoising_strength`); reference+ latents and inpaint masks are carried into that pass. `cache_mode`/`cache_option`+ (e.g. `easycache`, `threshold=0.2`) work per request. `POST /sdcpp/v1/upscale`+ (`{image, upscaler}`) runs ESRGAN synchronously, up to 8192 px per side.+- Qwen-Image 2.1 always decodes an alpha channel (≈1 % of pixels at alpha 247–254 on opaque+ images); outputs are made opaque unless transparency is requested.++## Resolution and upscaling policy++Every job runs a single diffusion pass at the working size (Auto: ~1 MP for Fast/Balanced,+native 2K for Quality; or the 1K/1.5K/2K/Source/Custom choice), capped by the VRAM token budget+that the target shares with its reference images. The earlier two-pass mode (≈1 MP render →+ESRGAN → low-denoise refine at 2K) was removed on 2026-10-06: in A/B tests the refine made+edits look worse than a single pass.++Whenever a result is larger than what the model rendered (edits restored to the source size,+outpaint, sizes above the VRAM budget) it is enlarged with ESRGAN ×4 and then resized down to+the exact size; Lanczos is only used for shrinking or factors below 1.1×.++The **Upscale** action has two methods: **Quick** (ESRGAN only) and **Detailed** (a low-denoise+0.3 img2img pass at about 2K, then ESRGAN to the target).++## HDR++The source's ISO 21496-1 gain map is reused and faded out where the edit changed brightness by+more than ~¼ stop (gone at 1 stop). Reading the gain map needs `ffmpeg` 7.1+ on PATH; without+it, or when the result's framing differs from the source (outpaint, other aspect ratios), the+result is saved in SDR and the job's notes say why.++## Downloads++Sources, sizes and SHA-256 sums are pinned in `crates/qls-core/src/catalog.rs`. Files ≥ 16 MB+download over 8 parallel connections in 8 MB pieces (HTTP Range, positional writes into a+preallocated `.part`, finished pieces recorded in `.part.segments` so pause or a crash can+resume). When nothing is left to start, idle connections also fetch the piece with the most+left; the first to finish wins. A server without range support falls back to one connection.+A file that fails twice, or a link that moved, is reported with its download page and target+path so it can be fetched by hand.++## Settings not shown in the UI++In `%APPDATA%\Kokon\config.json`: `hardwarePreset` (`12gb|16gb|24gb|32gb`, written by the+setup screen), `vramOverrideMib` (plan sizes as if the GPU had this much VRAM; 0 = detect;+for testing), `refineMode` (`fast|best`, Detailed upscale effort; `off` is legacy),+`upscalersDir` (null = default folder), `upscalerModel` (`4x-UltraSharp`; configs on the old+`RealESRGAN_x4plus` default move to it), `upscaleTileSize` (0 = backend default 128),+`prefixCacheType`, `eagerLoad`, `sageAttention`.++## Testing smaller cards on a bigger one++`scripts\dev\vram-ballast.py --card-mib 12282` holds the VRAM a 12 GB card does not have (it+writes the memory every 0.5 s so Windows keeps it resident), and `vramOverrideMib` makes the+planner size images for 12 GB. `scripts\dev\test-12gb.ps1` does both and runs text to image,+edit, inpaint, outpaint, multi-reference and upscale through an isolated service, recording+time, working size, peak VRAM, memory spilled to shared GPU memory and out-of-memory retries+into `docs\test-results\`. Bandwidth and compute stay those of the bigger card, so times are+optimistic: a real 12 GB card (RTX 3060/4070) has to confirm them.diff --git a/docs/media/README.md b/docs/media/README.mdnew file mode 100644index 0000000..fedb8b1--- /dev/null+++ b/docs/media/README.md@@ -0,0 +1,11 @@+# README media++The files in this folder are placeholders. Replace each one with a real capture before launch, keeping the same file names and sizes.++| File | What to capture | Size |+| --- | --- | --- |+| `demo.gif` | Drop a photo → type one sentence → result appears → before/after slider. Under 10 s, cut out the waiting. | 1280×720, < 8 MB |+| `screenshot-app.png` | Main window with a finished edit and the Slider view | 1600×1000 |+| `examples/remove.jpg` … `expand.jpg` | Before (left) and after (right) side by side, with the exact prompt from the README caption | 1200×600 |++Rules: use neutral, non-NSFW photos you have the rights to (your own photos, or CC0 from Unsplash or Pexels), default settings only, and no cherry-picked seeds you couldn't reproduce. If a result needs a different prompt, update its caption in the README too.diff --git a/docs/media/demo.gif b/docs/media/demo.gifnew file mode 100644index 0000000..76f7874Binary files /dev/null and b/docs/media/demo.gif differdiff --git a/docs/media/examples/expand.jpg b/docs/media/examples/expand.jpgnew file mode 100644index 0000000..fb033e7Binary files /dev/null and b/docs/media/examples/expand.jpg differdiff --git a/docs/media/examples/relight.jpg b/docs/media/examples/relight.jpgnew file mode 100644index 0000000..98ecef0Binary files /dev/null and b/docs/media/examples/relight.jpg differdiff --git a/docs/media/examples/remove.jpg b/docs/media/examples/remove.jpgnew file mode 100644index 0000000..8b80377Binary files /dev/null and b/docs/media/examples/remove.jpg differdiff --git a/docs/media/examples/replace.jpg b/docs/media/examples/replace.jpgnew file mode 100644index 0000000..c075b8eBinary files /dev/null and b/docs/media/examples/replace.jpg differdiff --git a/docs/media/examples/restyle.jpg b/docs/media/examples/restyle.jpgnew file mode 100644index 0000000..78202c1Binary files /dev/null and b/docs/media/examples/restyle.jpg differdiff --git a/docs/media/examples/text.jpg b/docs/media/examples/text.jpgnew file mode 100644index 0000000..4984b68Binary files /dev/null and b/docs/media/examples/text.jpg differdiff --git a/docs/media/screenshot-app.png b/docs/media/screenshot-app.pngnew file mode 100644index 0000000..879a63fBinary files /dev/null and b/docs/media/screenshot-app.png differ