Bridge 图像生成技能: gs2-sdxl (GS-2 SDXL) + gs1-flux (GS-1 FLUX)
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
---
|
||||
name: gs2-sdxl
|
||||
description: 调用 GS-2 (192.168.9.116) Forge SDXL base 1.0 图像生成 API — txt2img/img2img,双实例 :7861/:7862 轮询。触发:生成图片/产品图/配图/场景图,SDXL 出图,文生图,图生图。
|
||||
---
|
||||
|
||||
# GS-2 SDXL 图像生成 (Forge API)
|
||||
|
||||
用 GS-2 的 SDXL base 1.0 生成图片。本机(任意节点)直连 `192.168.9.116` 即可,无需代理。
|
||||
|
||||
## 服务拓扑
|
||||
|
||||
| 项 | 值 |
|
||||
|----|----|
|
||||
| 节点 | GS-2 = 192.168.9.116 (2× RTX 3060 Laptop 12GB) |
|
||||
| 实例1 | `http://192.168.9.116:7861` (GPU0, systemd `forge-sdxl.service`) |
|
||||
| 实例2 | `http://192.168.9.116:7862` (GPU1, systemd `forge-sdxl-2.service`) |
|
||||
| 模型 | `sd_xl_base_1.0.safetensors` — **完整 SDXL base,不是 turbo!** + `sdxl_vae.safetensors` |
|
||||
| API | 标准 A1111/Forge: `/sdapi/v1/txt2img`, `/sdapi/v1/img2img`, `/sdapi/v1/sd-models` |
|
||||
|
||||
双实例轮询:优先 7861,失败/繁忙换 7862。
|
||||
|
||||
## 推荐参数 (SDXL base 完整版,2026-08-27 实测)
|
||||
|
||||
⚠️ 模型是完整 base(非 turbo),**steps 需要 24-30**,2 步会出糊图。
|
||||
|
||||
| 参数 | 值 |
|
||||
|------|----|
|
||||
| steps | 24-30 (出图约 10-25s@1024²) |
|
||||
| cfg_scale | 6-7.5 |
|
||||
| width/height | 768~1024 (SDXL 原生尺寸),默认 1024×1024 或 832×1216 |
|
||||
| sampler_name | `euler_a` 或 `dpmpp_2m_karras` |
|
||||
| negative_prompt | `lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, cropped, worst quality, low quality, jpeg artifacts, signature, watermark, username, blurry` |
|
||||
| 并发 | 单实例同时只处理 1 个请求 (12GB VRAM),批量任务轮询双实例 |
|
||||
|
||||
## 调用方式 (已验证)
|
||||
|
||||
### curl txt2img
|
||||
|
||||
```bash
|
||||
curl -s -X POST http://192.168.9.116:7861/sdapi/v1/txt2img \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"prompt":"a cute corgi wearing sunglasses, studio photo","negative_prompt":"lowres, blurry, watermark","steps":24,"cfg_scale":7,"width":1024,"height":1024,"sampler_name":"euler_a","seed":-1}'
|
||||
```
|
||||
|
||||
### Python (urllib,无 curl 依赖)
|
||||
|
||||
```python
|
||||
import json, base64, urllib.request
|
||||
|
||||
def sdxl_txt2img(prompt, negative_prompt="", steps=24, cfg=7.0,
|
||||
w=1024, h=1024, sampler="euler_a", seed=-1, port=7861):
|
||||
req = urllib.request.Request(
|
||||
f"http://192.168.9.116:{port}/sdapi/v1/txt2img",
|
||||
data=json.dumps({"prompt": prompt, "negative_prompt": negative_prompt,
|
||||
"steps": steps, "cfg_scale": cfg, "width": w, "height": h,
|
||||
"sampler_name": sampler, "seed": seed}).encode(),
|
||||
headers={"Content-Type": "application/json"})
|
||||
with urllib.request.urlopen(req, timeout=180) as r:
|
||||
data = json.loads(r.read())
|
||||
return base64.b64decode(data["images"][0]) # PNG bytes
|
||||
|
||||
# 保存
|
||||
png = sdxl_txt2img("a red apple on a wooden table, product photo", port=7861)
|
||||
open("/tmp/apple.png", "wb").write(png)
|
||||
```
|
||||
|
||||
### img2img (重绘/换风格/局部重绘)
|
||||
|
||||
```bash
|
||||
curl -s -X POST http://192.168.9.116:7862/sdapi/v1/img2img \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{"init_images":["<base64 PNG>"],"prompt":"same product, luxury studio background","denoising_strength":0.6,"steps":24,"cfg_scale":7,"width":1024,"height":1024,"sampler_name":"euler_a"}'
|
||||
```
|
||||
|
||||
要点:
|
||||
- `init_images` 传 **base64 编码的 PNG 字符串**(无 data: 前缀)
|
||||
- `denoising_strength` 0.5-0.7 重绘风格,0.3 以下基本保留原图,0.8+ 大改
|
||||
|
||||
## 健康检查
|
||||
|
||||
```bash
|
||||
# 模型列表 (返回 JSON 即服务正常)
|
||||
curl -s http://192.168.9.116:7861/sdapi/v1/sd-models
|
||||
# 实例间轮询: 7861 → 7862
|
||||
```
|
||||
|
||||
## 服务端排障 (需要时)
|
||||
|
||||
```bash
|
||||
sshpass -p 'Tt123456!' ssh admin9webs@192.168.9.116 \
|
||||
'export XDG_RUNTIME_DIR=/run/user/$(id -u); systemctl --user status forge-sdxl forge-sdxl-2 --no-pager | head -30'
|
||||
# 重启: systemctl --user restart forge-sdxl forge-sdxl-2
|
||||
```
|
||||
|
||||
## 陷阱
|
||||
|
||||
1. **是 base 模型不是 turbo**:steps 必须 24+,2-4 步出糊图/灰图。
|
||||
2. **双实例各绑一张卡**:单实例并发第 2 个请求会排队或 OOM,批量任务轮询两个端口。
|
||||
3. **12GB VRAM 上限**:1024×1024 稳定;超 1024 或加 ControlNet 可能 OOM,降 768。
|
||||
4. **seed=-1 随机**,固定 seed 可复现。
|
||||
5. 服务端 outputs 目录在 GS-2 (`~/stable-diffusion-webui-forge/outputs/`),但**推荐客户端解析 base64 直接存本地**,不依赖服务端目录。
|
||||
|
||||
## 相关
|
||||
|
||||
- 部署/版本排障细节见本地 `gpustack-cluster` 技能 (GS-2 Forge 双实例 systemd 章节)
|
||||
- FlairGS (AppServer-105 :7870) 也调这两个实例:FORGE_STEPS=24, CFG=7.5, denoise=0.70 (产品图场景生成)
|
||||
Reference in New Issue
Block a user