An open API service indexing awesome lists of open source software.

https://github.com/abra5umente/auto1111

terminal based wrapper for Stable Diffusion Web UI, written in Go
https://github.com/abra5umente/auto1111

automatic1111 automation cli-tool generative-ai-projects go image-generation stable-diffusion stable-diffusion-webui

Last synced: 24 days ago
JSON representation

terminal based wrapper for Stable Diffusion Web UI, written in Go

Awesome Lists containing this project

README

          

# Go Auto1111 Launcher & Web GUI

A unified toolkit for Stable Diffusion on your own hardware. Run it **headless** from the desktop or via a **browser‑friendly Web GUI**—both now share one code‑base and identical JSON‑driven settings.

---

## ✨ What’s New (July 2025)

| Area | Added / Changed |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Desktop CLI** | • *Automatic* PNG naming in `/output`
• Robust error handling (non‑zero exit codes bubble up) |
| **Web GUI** | • Drag‑and‑drop **`.json` settings** upload
• Dropdown recall of uploaded presets
• Generates images with a single click (prompt + selected JSON) |
| **Config split** | • `.env` → **system‑level** stuff (paths, model folders, env BATs)
• `settings.json` → **generation parameters** (sampler, scheduler, width × height, steps, cfg scale) |

---

## 1. Directory Layout

```text
project/
│ README.md
│ requirements.txt ← Python deps (legacy FastAPI)
│ webapp.exe ← built full-Go web server (optional)

├─ backend/ ← generator.exe + legacy FastAPI
│ ├─ generator.exe ← built Go generator
│ ├─ settings.json ← symlink / copy chosen preset
│ └─ settings/ ← uploaded *.json presets

├─ output/ ← generated PNGs (auto‑timestamped)

├─ source/
│ ├─ *.go ← generator sources
│ └─ cmd/webapp/ ← full-Go web server (serves UI + API)

└─ auto1111_webapp/
├─ frontend/ ← React + Vite + Tailwind (shadcn/ui)
└─ app/ ← build output served at /app
```

---

## 2. Installation & Build

### ⚙️ Prerequisites

* **Go 1.21+** (for the CLI generator)
* **Python 3.10+** (for FastAPI & AUTOMATIC1111)
* **Stable Diffusion WebUI** (AUTOMATIC1111) cloned locally
* *Windows users*: `ENVIRONMENT_BAT` & `AUTO1111_BAT` paths configured in `.env`

### 🐍 Python deps (Web GUI)

```bash
python -m venv venv
venv\Scripts\activate # or `source venv/bin/activate`
pip install -r requirements.txt
```

`requirements.txt` generated today:

```text
fastapi
uvicorn[standard]
python-multipart
pydantic
```

### 🛠️ Build & Run — Desktop CLI

```bash
cd backend
# Build once
go build -o generator.exe .

# Single image
./generator.exe --prompt "a cat in space" --settings settings/sample.json
```

Images appear in `output/`.

### 🌐 Build & Run — Web GUI (legacy FastAPI)

```bash
cd backend
# 1. build Go binary (same as above)
# 2. start FastAPI server (reload disabled for Go exe stability)
uvicorn main:app --host 0.0.0.0 --port 8000
```

Open [http://localhost:8000/app/](http://localhost:8000/app/) in your browser.

On Windows, you can use `startup.bat` to launch both the frontend (Vite dev server) and backend together. It installs frontend deps if missing and opens the dev server in a new window.

```bat
startup.bat
```

#### Frontend (React + shadcn/ui)

The frontend lives in `auto1111_webapp/frontend` and builds into `auto1111_webapp/app` (served by FastAPI at `/app`). The legacy static HTML has been removed.

Setup and build:

```bash
cd auto1111_webapp/frontend
npm install
npm run build # outputs to ../app with base /app/
```

For local development (hot reload) without the batch script:

```bash
cd auto1111_webapp/frontend
npm run dev # http://localhost:5173
```

The dev server hits the same API endpoints (`/generate`, `/history`, etc.).

### 🖱️ One‑click Windows app (full Go)

Build a single Go web server that serves the UI, exposes the API, and shells out to `generator.exe`. No Python needed at runtime.

1) Build frontend (once, or whenever you change it):

```bash
cd auto1111_webapp/frontend
npm install
npm run build # outputs to ../app with base /app/
```

2) Build server (from repo root):

```bash
go build -o webapp.exe ./source/cmd/webapp
```

3) Run:

- Double‑click `webapp.exe` (or run it from a terminal)
- Opens http://127.0.0.1:8000/app/
- Press Ctrl+C to quit

Runtime requirements:

- `backend/generator.exe` present (build with `go build -o backend/generator.exe ./source`)
- `backend/.env` for AUTO1111 paths and keys (the generator reads `.env` beside itself)
- By default, the server serves UI from disk at `auto1111_webapp/app`.
- To bake the UI into the binary, first copy the built assets into `source/cmd/webapp/app`, then build with a tag:

```bash
REM after running npm run build (which outputs ../app)
xcopy /E /I /Y auto1111_webapp\app source\cmd\webapp\app
go build -tags embedui -o webapp.exe ./source/cmd/webapp
```

With `-tags embedui`, the binary contains the UI and does not need the `auto1111_webapp/app` folder at runtime.

---

## 3. Using the Web GUI

1. **Upload** a `*.json` preset via **Settings → Upload**. The file is saved to `backend/settings/` and instantly appears in the dropdown.
2. **Select** the preset from the dropdown. Its parameters (sampler, width, etc.) are shown for confirmation.
3. Type your **prompt** (or leave blank to auto‑enhance) and press **Generate**.
4. The resulting PNG streams back and is also written to `output/`.

> **Tip:** presets can be version‑controlled. Commit the `settings/` folder to Git for easy sharing.

---

## 4. Roadmap (July 2025)

| Feature | Status |
| ------------------------------------------ | --------------------------------------------------------------------------- |
| **Prompt History** | ✅ Planned – quick recall in GUI |
| **Style Presets** | 🚧 Expanding – now driven by uploaded JSON; will ship with curated defaults |
| **Negative Prompt Generation** | ✅ Keeps bad stuff out automatically |
| **Model Selection** | ✅ Currently relies on whatever is set in Automatic1111, but will obey `.env` / JSON overrides soon |
| **GUI Interface** | 🚧 MVP shipped; polishing UI & auth next |
| **Prompt Templates (JSON import)** | ✅ Core to new workflow |
| **Social Features** (share prompts / PNGs) | ✅ Still on the slate |
| **Containerisation** (Docker) | ✅ Working on this |

---

## 5. Troubleshooting

| Symptom | Likely Cause | Fix |
| ---------------------------------- | -------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `generator.exe failed: …` | Invalid JSON (missing comma or wrong key) | Validate with `jq . settings/your.json` |
| Image 512×512 despite bigger width | JSON keys wrong *or* values saved as strings | Keys are `IMAGE_WIDTH/IMAGE_HEIGHT` or `width/height` (caps or lower). Numbers **must not** be quoted. |
| `No .env file found` from AUTO1111 | Working dir incorrect for the child process | Confirm `start_auto1111()` sets `cmd.Dir` to `backend/` |
| PNG missing but no error | Output path invalid | Ensure `output/` exists & that you have write permissions |

---

## 6. FAQ

> **Q:** Do I need both `.env` *and* `settings.json`?
>
> **A:** Yes. Think of `.env` as *system settings* (where Python lives, which SD model to load, API keys). `settings.json` is *per‑image parameters* (sampler, size, steps). Separate files keep your secrets out of Git while letting you share artistic presets.

---

© 2025 MIT‑licensed. Happy rendering! 🚀