# dsh-image-studio

> **Language:** [English](README.md) · [Česky](README.cs.md)

DeepSeek Harness plugin for local text-to-image and image editing, with a
settings GUI and a model-callable `dsh_image` tool.

## Features

- **Generate** images from a prompt — locally via Stable Diffusion
  (diffusers + PyTorch MPS on Apple Silicon) or an OpenAI-compatible image API.
- **Inpaint** — edit a region of an existing image using a mask.
- **Review** — check a generated image with a vision model: the DeepSeek vision
  API (`deepseek-v4-flash-vision-exp`) or a local Ollama vision model
  (`qwen2.5vl:3b`).
- **Settings section "Image Studio"** — backend, model, API key, vision model,
  and generation parameters.
- Cooperates with `dsh-resource-guard`: local generation reserves memory first.

## Requirements (local backend)

- macOS with Apple Silicon (MPS) or a CPU-only fallback.
- `python3` on PATH (creates `~/.dsh/image-studio-venv` automatically).
- First local run downloads model weights
  (`runwayml/stable-diffusion-v1-5`, `runwayml/stable-diffusion-inpainting`).

## Install

```sh
dsh plugin --profile web add dsh-image-studio
```

Then add `dsh-image-studio` to `dsh.profile.bundles` and `dependencies` in
`~/.dsh/profiles/web/package.json`, and run `dsh plugin --profile web install`.

## Usage

Ask the agent:

- `dsh_image action=generate prompt="a lighthouse at dusk"` — generate locally.
- `dsh_image action=inpaint prompt="a red door" image=/abs/img.png mask=/abs/mask.png` — edit a region.
- `dsh_image action=check image=/abs/img.png` — vision review.

Outputs are written to `~/.dsh/image-studio-outputs/`.

## Settings

| Field | Default | Meaning |
| --- | --- | --- |
| `backend` | `local` | `local` (Stable Diffusion) or `api` (OpenAI-compatible). |
| `model` | `runwayml/stable-diffusion-v1-5` | Local model id or API image model. |
| `apiBaseUrl` | `https://api.openai.com/v1` | API base URL (backend `api`). |
| `apiKey` | `` | Bearer token (backend `api` / vision). |
| `visionBackend` | `deepseek` | `deepseek` or `local`. |
| `visionModel` | `deepseek-v4-flash-vision-exp` | Vision model id. |
| `steps` / `guidanceScale` / `width` / `height` | `25` / `7.5` / `512` / `512` | Generation parameters. |

## Architecture

- **Host** (`lib/index.js`) — spawns `worker/image_worker.py` (a stdlib HTTP
  server on `127.0.0.1:7861`) into `~/.dsh/image-studio-venv`, calls its
  `/generate` and `/inpaint` endpoints, and implements the vision review.
- **Client** (`lib/client.js`) — `settings.section` with configuration, prompt
  input, and Generate / Inpaint / Review buttons (via the action namespace).

## License

MIT
