Add Image v2 Generate for Klein text-to-image.
New sibling graph and mode so T2I does not borrow Edit, Compose, or Refine. Stills are ignored; size is width x height only. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+22
-5
@@ -6,10 +6,11 @@ Image edit (v1) and Image v2 are siblings. v1 is unchanged. Do not mute-fix `wor
|
|||||||
|---|---|---|
|
|---|---|---|
|
||||||
| Tab | Image edit | Image v2 |
|
| Tab | Image edit | Image v2 |
|
||||||
| Route | `POST /api/edit` | `POST /api/v2/generate` and `POST /v2/generate` |
|
| Route | `POST /api/edit` | `POST /api/v2/generate` and `POST /v2/generate` |
|
||||||
| Graphs | One file, prune unused branch | `klein_v2_edit.json`, `klein_v2_compose.json`, or `klein_v2_refine.json` |
|
| Graphs | One file, prune unused branch | `klein_v2_edit.json`, `klein_v2_compose.json`, `klein_v2_refine.json`, or `klein_v2_generate.json` |
|
||||||
| Second still | Optional; switches branch | Compose only; required. Mismatch is a 400 |
|
| Second still | Optional; switches branch | Compose only; required. Mismatch is a 400 |
|
||||||
| Mask | — | Refine only; required. Missing mask is a 400, not an Edit fallback |
|
| Mask | — | Refine only; required. Missing mask is a 400, not an Edit fallback |
|
||||||
| LoRAs | Optional user picker | SNOFS + Consistency, four strengths |
|
| Input still | Required | Edit / Compose / Refine required. Generate ignores stills |
|
||||||
|
| LoRAs | Optional user picker | SNOFS + Consistency, four strengths. Generate defaults Consistency off |
|
||||||
| Defaults | 20 steps, CFG 1 | 24 steps, CFG 4 (turbo: 8 / 1) |
|
| Defaults | 20 steps, CFG 1 | 24 steps, CFG 4 (turbo: 8 / 1) |
|
||||||
|
|
||||||
Poll v2 jobs the same way as v1: `GET /api/generate/{id}/stream` and `GET /api/generate/{id}`.
|
Poll v2 jobs the same way as v1: `GET /api/generate/{id}/stream` and `GET /api/generate/{id}`.
|
||||||
@@ -19,6 +20,7 @@ Poll v2 jobs the same way as v1: `GET /api/generate/{id}/stream` and `GET /api/g
|
|||||||
- **edit** — one image + text. Task is `scene`. Sending `image_b` is rejected. Use this to change lighting, background, or the whole frame from a single still.
|
- **edit** — one image + text. Task is `scene`. Sending `image_b` is rejected. Use this to change lighting, background, or the whole frame from a single still.
|
||||||
- **compose** — two images + text. `image_b` is required. No silent one-image fallback. Use this to lock a person from A and pull a face or outfit from B.
|
- **compose** — two images + text. `image_b` is required. No silent one-image fallback. Use this to lock a person from A and pull a face or outfit from B.
|
||||||
- **refine** — one canvas + a painted mask + text. `image_a` and `mask` are required. `image_b` is ignored. Prompt only what should change inside the mask. Strength is denoise in that region (not CFG). Use this for face / hand / chest fixes without opening Comfy.
|
- **refine** — one canvas + a painted mask + text. `image_a` and `mask` are required. `image_b` is ignored. Prompt only what should change inside the mask. Strength is denoise in that region (not CFG). Use this for face / hand / chest fixes without opening Comfy.
|
||||||
|
- **generate** — text only. No `image_a`, `image_b`, or mask. Size is width × height (768 / 1024 / 1280), not megapixels from a still. Use this to make a new Klein still from a prompt.
|
||||||
|
|
||||||
Compose tasks:
|
Compose tasks:
|
||||||
|
|
||||||
@@ -27,12 +29,13 @@ Compose tasks:
|
|||||||
- **face_lock** — body/pose/scene from A; face from B
|
- **face_lock** — body/pose/scene from A; face from B
|
||||||
- **scene** — A is the edit image; B is style/background
|
- **scene** — A is the edit image; B is style/background
|
||||||
|
|
||||||
Refine does not prepend Edit/Compose role headers.
|
Refine and Generate do not prepend Edit/Compose role headers. The user prompt is the whole prompt.
|
||||||
|
|
||||||
Dummy tests:
|
Dummy tests:
|
||||||
|
|
||||||
- Compose + two unrelated photos + “keep everything the same” must change the output. If it matches old v1 gens, still B is not connected.
|
- Compose + two unrelated photos + “keep everything the same” must change the output. If it matches old v1 gens, still B is not connected.
|
||||||
- Refine + last good gen + mask on the left breast + “red X painted on the left breast” at strength 0.4. Pass = X on the breast, face/pose/background stay. Fail = whole image regenerates, or nothing changes.
|
- Refine + last good gen + mask on the left breast + “red X painted on the left breast” at strength 0.4. Pass = X on the breast, face/pose/background stay. Fail = whole image regenerates, or nothing changes.
|
||||||
|
- Generate + “a red cube on a white table, studio light” and no stills. Pass = a new image of that. Fail = missing-image error, or the output equals the last Edit/Compose still.
|
||||||
|
|
||||||
## Nodes the mapper patches
|
## Nodes the mapper patches
|
||||||
|
|
||||||
@@ -72,6 +75,18 @@ Refine only (`klein_v2_refine.json`):
|
|||||||
| `17` | `BasicScheduler.denoise` — this is Strength, not CFG |
|
| `17` | `BasicScheduler.denoise` — this is Strength, not CFG |
|
||||||
| `19` | Sampler starts from the masked canvas latent, not an empty Flux2 latent |
|
| `19` | Sampler starts from the masked canvas latent, not an empty Flux2 latent |
|
||||||
|
|
||||||
|
Generate only (`klein_v2_generate.json`):
|
||||||
|
|
||||||
|
| Node | Role |
|
||||||
|
|------|------|
|
||||||
|
| `14` | `EmptyFlux2LatentImage` at request width × height |
|
||||||
|
| `17` | `Flux2Scheduler` steps + the same size |
|
||||||
|
| `7` | SNOFS LoRA |
|
||||||
|
| `8` | Consistency LoRA — removed at runtime when both strengths are 0 |
|
||||||
|
| `9` / `10` | Prompt / negative from the API (no leftover widget text) |
|
||||||
|
|
||||||
|
There is no `LoadImage`. If the executed Generate graph has a required LoadImage, the job fails. v1 node 145 (muted T2I with a baked prompt) is not used.
|
||||||
|
|
||||||
If `image_b` is sent on Edit/Compose and the executed graph has fewer than two `LoadImage` nodes, the job fails. If Refine runs without a mask input or without denoise on the scheduler, the job fails.
|
If `image_b` is sent on Edit/Compose and the executed graph has fewer than two `LoadImage` nodes, the job fails. If Refine runs without a mask input or without denoise on the scheduler, the job fails.
|
||||||
|
|
||||||
## Default sliders
|
## Default sliders
|
||||||
@@ -85,7 +100,8 @@ If `image_b` is sent on Edit/Compose and the executed graph has fewer than two `
|
|||||||
| Steps | 24 (turbo 8) |
|
| Steps | 24 (turbo 8) |
|
||||||
| CFG | 4 (turbo 1) |
|
| CFG | 4 (turbo 1) |
|
||||||
| Scale to MP | 1.0 lanczos |
|
| Scale to MP | 1.0 lanczos |
|
||||||
| Strength (denoise) | 0.35 on Refine only. Hidden on Edit/Compose. Range 0.15–0.75 |
|
| Strength (denoise) | 0.35 on Refine only. Hidden on Edit/Compose/Generate. Range 0.15–0.75 |
|
||||||
|
| Size | Generate only. 1:1 1024×1024, 3:4 768×1024, 4:3 1024×768, 16:9 1280×768, 9:16 768×1280 |
|
||||||
|
|
||||||
### When to use each Refine strength
|
### When to use each Refine strength
|
||||||
|
|
||||||
@@ -103,5 +119,6 @@ Do not raise Strength to rewrite the whole frame. If the face or background move
|
|||||||
- **outfit** — keep SNOFS Model ~0.65 so cloth reads; do not raise it past ~0.85 or it starts rewriting the body from A. Consistency stays at 0.70 so the person in A does not become the person in B.
|
- **outfit** — keep SNOFS Model ~0.65 so cloth reads; do not raise it past ~0.85 or it starts rewriting the body from A. Consistency stays at 0.70 so the person in A does not become the person in B.
|
||||||
- **scene / edit** — start at the table defaults. Turbo is for drafts only.
|
- **scene / edit** — start at the table defaults. Turbo is for drafts only.
|
||||||
- **refine** — prompt only the masked change. Face vs hand/chest chips set Strength and LoRAs together.
|
- **refine** — prompt only the masked change. Face vs hand/chest chips set Strength and LoRAs together.
|
||||||
|
- **generate** — SFW scene = SNOFS 0 / 0. SNOF T2I = SNOFS 0.65 / 0.35. Consistency stays 0. Turbo is 8 steps / CFG 1.
|
||||||
|
|
||||||
Presets on this tab store sliders + mode + task (+ Strength when Refine). They do not load v1 LoRA stacks or a cached latent.
|
Presets on this tab store sliders + mode + task (+ Strength when Refine, + size when Generate). They do not load v1 LoRA stacks or a cached latent.
|
||||||
|
|||||||
+135
-24
@@ -65,7 +65,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<h2 class="font-display text-2xl font-bold">Input</h2>
|
<h2 class="font-display text-2xl font-bold">Input</h2>
|
||||||
<p class="text-sm text-zinc-400">{{ studioMode === 'editv2'
|
<p class="text-sm text-zinc-400">{{ studioMode === 'editv2'
|
||||||
? (v2Mode === 'refine'
|
? (v2Mode === 'generate'
|
||||||
|
? 'Generate: no reference image. Prompt only. Klein 9B Base text-to-image.'
|
||||||
|
: v2Mode === 'refine'
|
||||||
? 'Refine: paint a mask on Still A. Prompt only what should change in the painted area. Strength is denoise in that region.'
|
? 'Refine: paint a mask on Still A. Prompt only what should change in the painted area. Strength is denoise in that region.'
|
||||||
: v2Mode === 'compose'
|
: v2Mode === 'compose'
|
||||||
? 'Compose: still A is the person/body. Still B is the face or outfit. Two stills required — no silent one-image fallback.'
|
? 'Compose: still A is the person/body. Still B is the face or outfit. Two stills required — no silent one-image fallback.'
|
||||||
@@ -76,6 +78,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
v-if="!(studioMode === 'editv2' && v2Mode === 'generate')"
|
||||||
class="relative cursor-pointer rounded-2xl border border-dashed border-white/15 bg-zinc-950/50 p-4 transition hover:border-amber-300/50"
|
class="relative cursor-pointer rounded-2xl border border-dashed border-white/15 bg-zinc-950/50 p-4 transition hover:border-amber-300/50"
|
||||||
:class="{ 'border-amber-300/70 bg-amber-400/5': dragging }"
|
:class="{ 'border-amber-300/70 bg-amber-400/5': dragging }"
|
||||||
@dragover.prevent="dragging = true"
|
@dragover.prevent="dragging = true"
|
||||||
@@ -133,6 +136,14 @@
|
|||||||
>
|
>
|
||||||
Refine
|
Refine
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full border px-3 py-1 text-xs font-medium"
|
||||||
|
:class="v2Mode === 'generate' ? 'border-amber-300/70 bg-amber-400/10 text-amber-100' : 'border-white/10 text-zinc-400 hover:text-white'"
|
||||||
|
@click="setV2Mode('generate')"
|
||||||
|
>
|
||||||
|
Generate
|
||||||
|
</button>
|
||||||
<label v-if="v2Mode === 'compose'" class="ml-auto text-xs">
|
<label v-if="v2Mode === 'compose'" class="ml-auto text-xs">
|
||||||
<span class="mr-2 text-zinc-500">Task</span>
|
<span class="mr-2 text-zinc-500">Task</span>
|
||||||
<select
|
<select
|
||||||
@@ -192,7 +203,7 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div class="mb-2 flex flex-wrap items-center justify-between gap-2">
|
<div class="mb-2 flex flex-wrap items-center justify-between gap-2">
|
||||||
<label class="text-sm font-medium text-zinc-300">{{ studioMode === 'editv2' && v2Mode === 'refine' ? 'Refine prompt' : studioMode === 'edit' || studioMode === 'editv2' ? 'Edit prompt' : 'Motion & scene prompt' }}</label>
|
<label class="text-sm font-medium text-zinc-300">{{ studioMode === 'editv2' && v2Mode === 'generate' ? 'Generate prompt' : studioMode === 'editv2' && v2Mode === 'refine' ? 'Refine prompt' : studioMode === 'edit' || studioMode === 'editv2' ? 'Edit prompt' : 'Motion & scene prompt' }}</label>
|
||||||
<div class="flex flex-wrap items-center gap-3">
|
<div class="flex flex-wrap items-center gap-3">
|
||||||
<button
|
<button
|
||||||
v-if="identityPrompting"
|
v-if="identityPrompting"
|
||||||
@@ -276,6 +287,7 @@
|
|||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<p v-if="studioMode === 'editv2' && v2Mode === 'generate'" class="mt-3 text-xs text-zinc-500">No reference image. Prompt only.</p>
|
||||||
<div v-if="studioMode === 'editv2' && v2Mode === 'refine'" class="mt-3 space-y-2">
|
<div v-if="studioMode === 'editv2' && v2Mode === 'refine'" class="mt-3 space-y-2">
|
||||||
<p class="text-xs text-zinc-500">Prompt only what should change in the painted area.</p>
|
<p class="text-xs text-zinc-500">Prompt only what should change in the painted area.</p>
|
||||||
<div class="flex flex-wrap gap-2">
|
<div class="flex flex-wrap gap-2">
|
||||||
@@ -698,7 +710,40 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="studioMode === 'editv2'" class="space-y-3">
|
<div v-else-if="studioMode === 'editv2'" class="space-y-3">
|
||||||
<p class="text-xs text-zinc-500">Klein v2 · 9B Base · euler. Edit, Compose, and Refine are separate graphs. Shares the desktop GPU with video.</p>
|
<p class="text-xs text-zinc-500">Klein v2 · 9B Base · euler. Edit, Compose, Refine, and Generate are separate graphs. Shares the desktop GPU with video.</p>
|
||||||
|
<div v-if="v2Mode === 'generate'" class="space-y-2 rounded-2xl border border-white/10 bg-zinc-950/40 p-3">
|
||||||
|
<p class="text-xs text-zinc-400">Size · near 1 MP</p>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<button
|
||||||
|
v-for="(pair, aspect) in IMAGE_V2_GENERATE_ASPECTS"
|
||||||
|
:key="aspect"
|
||||||
|
type="button"
|
||||||
|
class="rounded-full border px-2.5 py-1 text-xs"
|
||||||
|
:class="v2Width === pair[0] && v2Height === pair[1] ? 'border-amber-300/70 text-amber-100' : 'border-white/10 text-zinc-400'"
|
||||||
|
@click="setGenerateSize(aspect)"
|
||||||
|
>
|
||||||
|
{{ aspect }} · {{ pair[0] }}×{{ pair[1] }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-wrap gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full border px-2.5 py-1 text-xs"
|
||||||
|
:class="v2SnofsModel === 0 && v2SnofsClip === 0 ? 'border-amber-300/70 text-amber-100' : 'border-white/10 text-zinc-400'"
|
||||||
|
@click="applyGenerateLook('sfw')"
|
||||||
|
>
|
||||||
|
SFW scene
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full border px-2.5 py-1 text-xs"
|
||||||
|
:class="v2SnofsModel === IMAGE_V2_GENERATE_SNOFS.snofsModel && v2SnofsClip === IMAGE_V2_GENERATE_SNOFS.snofsClip ? 'border-amber-300/70 text-amber-100' : 'border-white/10 text-zinc-400'"
|
||||||
|
@click="applyGenerateLook('snofs')"
|
||||||
|
>
|
||||||
|
SNOF T2I
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div v-if="v2Mode === 'refine'" class="space-y-2 rounded-2xl border border-white/10 bg-zinc-950/40 p-3">
|
<div v-if="v2Mode === 'refine'" class="space-y-2 rounded-2xl border border-white/10 bg-zinc-950/40 p-3">
|
||||||
<label class="block text-sm">
|
<label class="block text-sm">
|
||||||
<span class="mb-1 block text-zinc-300">Strength (denoise)</span>
|
<span class="mb-1 block text-zinc-300">Strength (denoise)</span>
|
||||||
@@ -750,11 +795,11 @@
|
|||||||
<span class="mb-1 block text-zinc-400">SNOFS CLIP</span>
|
<span class="mb-1 block text-zinc-400">SNOFS CLIP</span>
|
||||||
<input v-model.number="v2SnofsClip" type="number" min="0" max="2" step="0.05" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
<input v-model.number="v2SnofsClip" type="number" min="0" max="2" step="0.05" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
||||||
</label>
|
</label>
|
||||||
<label class="block text-sm">
|
<label v-if="v2Mode !== 'generate'" class="block text-sm">
|
||||||
<span class="mb-1 block text-zinc-400">Consistency Model</span>
|
<span class="mb-1 block text-zinc-400">Consistency Model</span>
|
||||||
<input v-model.number="v2ConsistencyModel" type="number" min="0" max="2" step="0.05" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
<input v-model.number="v2ConsistencyModel" type="number" min="0" max="2" step="0.05" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
||||||
</label>
|
</label>
|
||||||
<label class="block text-sm">
|
<label v-if="v2Mode !== 'generate'" class="block text-sm">
|
||||||
<span class="mb-1 block text-zinc-400">Consistency CLIP</span>
|
<span class="mb-1 block text-zinc-400">Consistency CLIP</span>
|
||||||
<input v-model.number="v2ConsistencyClip" type="number" min="0" max="2" step="0.05" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
<input v-model.number="v2ConsistencyClip" type="number" min="0" max="2" step="0.05" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
||||||
</label>
|
</label>
|
||||||
@@ -770,7 +815,7 @@
|
|||||||
<span class="mb-1 block text-zinc-400">Seed</span>
|
<span class="mb-1 block text-zinc-400">Seed</span>
|
||||||
<input v-model="seedInput" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm" placeholder="random">
|
<input v-model="seedInput" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm" placeholder="random">
|
||||||
</label>
|
</label>
|
||||||
<label class="block text-sm">
|
<label v-if="v2Mode !== 'generate'" class="block text-sm">
|
||||||
<span class="mb-1 block text-zinc-400">Scale to MP</span>
|
<span class="mb-1 block text-zinc-400">Scale to MP</span>
|
||||||
<input v-model.number="v2Megapixels" type="number" :min="IMAGE_SCALE_MP_MIN" :max="IMAGE_SCALE_MP_MAX" :step="IMAGE_SCALE_MP_STEP" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
<input v-model.number="v2Megapixels" type="number" :min="IMAGE_SCALE_MP_MIN" :max="IMAGE_SCALE_MP_MAX" :step="IMAGE_SCALE_MP_STEP" class="w-full rounded-xl border border-white/10 bg-zinc-950 px-3 py-2 text-sm outline-none ring-amber-300/40 focus:ring-2">
|
||||||
</label>
|
</label>
|
||||||
@@ -1327,6 +1372,13 @@
|
|||||||
>
|
>
|
||||||
Use as input still
|
Use as input still
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="inline-flex rounded-2xl border border-amber-300/40 px-4 py-2 text-sm text-amber-100 hover:border-amber-300/70"
|
||||||
|
@click="sendToEdit"
|
||||||
|
>
|
||||||
|
Send to Edit
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="inline-flex rounded-2xl border border-amber-300/40 px-4 py-2 text-sm text-amber-100 hover:border-amber-300/70"
|
class="inline-flex rounded-2xl border border-amber-300/40 px-4 py-2 text-sm text-amber-100 hover:border-amber-300/70"
|
||||||
@@ -1864,6 +1916,11 @@ import {
|
|||||||
IMAGE_V2_DENOISE_MAX,
|
IMAGE_V2_DENOISE_MAX,
|
||||||
IMAGE_V2_DENOISE_MIN,
|
IMAGE_V2_DENOISE_MIN,
|
||||||
IMAGE_V2_DENOISE_STEP,
|
IMAGE_V2_DENOISE_STEP,
|
||||||
|
IMAGE_V2_GENERATE_ASPECTS,
|
||||||
|
IMAGE_V2_GENERATE_HEIGHT,
|
||||||
|
IMAGE_V2_GENERATE_SNOFS,
|
||||||
|
IMAGE_V2_GENERATE_SFW,
|
||||||
|
IMAGE_V2_GENERATE_WIDTH,
|
||||||
IMAGE_V2_REFINE_FACE,
|
IMAGE_V2_REFINE_FACE,
|
||||||
IMAGE_V2_REFINE_FACE_PROMPT,
|
IMAGE_V2_REFINE_FACE_PROMPT,
|
||||||
IMAGE_V2_REFINE_HAND,
|
IMAGE_V2_REFINE_HAND,
|
||||||
@@ -1872,7 +1929,9 @@ import {
|
|||||||
IMAGE_V2_SNOFS_MODEL,
|
IMAGE_V2_SNOFS_MODEL,
|
||||||
IMAGE_V2_STEPS_DEFAULT,
|
IMAGE_V2_STEPS_DEFAULT,
|
||||||
clampImageV2Denoise,
|
clampImageV2Denoise,
|
||||||
|
clampImageV2Size,
|
||||||
clampImageV2Strength,
|
clampImageV2Strength,
|
||||||
|
type ImageV2GenerateAspect,
|
||||||
type ImageV2Mode,
|
type ImageV2Mode,
|
||||||
type ImageV2PresetSettings,
|
type ImageV2PresetSettings,
|
||||||
type ImageV2Task
|
type ImageV2Task
|
||||||
@@ -2153,6 +2212,8 @@ const v2Steps = ref(IMAGE_V2_STEPS_DEFAULT)
|
|||||||
const v2Cfg = ref(IMAGE_V2_CFG_DEFAULT)
|
const v2Cfg = ref(IMAGE_V2_CFG_DEFAULT)
|
||||||
const v2Megapixels = ref(1)
|
const v2Megapixels = ref(1)
|
||||||
const v2Turbo = ref(false)
|
const v2Turbo = ref(false)
|
||||||
|
const v2Width = ref(IMAGE_V2_GENERATE_WIDTH)
|
||||||
|
const v2Height = ref(IMAGE_V2_GENERATE_HEIGHT)
|
||||||
const v2Denoise = ref(IMAGE_V2_DENOISE_DEFAULT)
|
const v2Denoise = ref(IMAGE_V2_DENOISE_DEFAULT)
|
||||||
const refineMaskDirty = ref(false)
|
const refineMaskDirty = ref(false)
|
||||||
const refinePainter = ref<{ exportPng: () => Promise<Blob | null>; clear: () => void } | null>(null)
|
const refinePainter = ref<{ exportPng: () => Promise<Blob | null>; clear: () => void } | null>(null)
|
||||||
@@ -2532,14 +2593,15 @@ const stillBHint = computed(() => {
|
|||||||
return 'Still A is the edit image. Still B is style or background.'
|
return 'Still A is the edit image. Still B is style or background.'
|
||||||
})
|
})
|
||||||
const editV2Blocked = computed(() => {
|
const editV2Blocked = computed(() => {
|
||||||
if (!file.value || !prompt.value.trim() || !folderId.value) return true
|
if (!prompt.value.trim() || !folderId.value) return true
|
||||||
|
if (v2Mode.value !== 'generate' && !file.value) return true
|
||||||
if (v2Mode.value === 'compose' && !editRefFile.value) return true
|
if (v2Mode.value === 'compose' && !editRefFile.value) return true
|
||||||
if (v2Mode.value === 'refine' && !refineMaskDirty.value) return true
|
if (v2Mode.value === 'refine' && !refineMaskDirty.value) return true
|
||||||
if (!comfyOk.value && !imageComfyOk.value) return true
|
if (!comfyOk.value && !imageComfyOk.value) return true
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
const editV2BlockReason = computed(() => {
|
const editV2BlockReason = computed(() => {
|
||||||
if (!file.value) return 'Load still A first.'
|
if (v2Mode.value !== 'generate' && !file.value) return 'Load still A first.'
|
||||||
if (v2Mode.value === 'compose' && !editRefFile.value) return 'Compose requires still B. This will not fall back to one-image generation.'
|
if (v2Mode.value === 'compose' && !editRefFile.value) return 'Compose requires still B. This will not fall back to one-image generation.'
|
||||||
if (v2Mode.value === 'refine' && !refineMaskDirty.value) return 'Paint a mask on Still A first. Refine will not fall back to Edit.'
|
if (v2Mode.value === 'refine' && !refineMaskDirty.value) return 'Paint a mask on Still A first. Refine will not fall back to Edit.'
|
||||||
if (!prompt.value.trim()) return 'Write a prompt first.'
|
if (!prompt.value.trim()) return 'Write a prompt first.'
|
||||||
@@ -2550,7 +2612,7 @@ const editV2BlockReason = computed(() => {
|
|||||||
})
|
})
|
||||||
const editV2SubmitLabel = computed(() => {
|
const editV2SubmitLabel = computed(() => {
|
||||||
const occupied = videoBusy.value || editBusy.value || studioJobs.value.some(job => job.status === 'running')
|
const occupied = videoBusy.value || editBusy.value || studioJobs.value.some(job => job.status === 'running')
|
||||||
const label = v2Mode.value === 'refine' ? 'Refine image' : v2Mode.value === 'compose' ? 'Compose image' : 'Edit image'
|
const label = v2Mode.value === 'generate' ? 'Generate image' : v2Mode.value === 'refine' ? 'Refine image' : v2Mode.value === 'compose' ? 'Compose image' : 'Edit image'
|
||||||
return occupied ? `Queue ${label.toLowerCase()}` : label
|
return occupied ? `Queue ${label.toLowerCase()}` : label
|
||||||
})
|
})
|
||||||
const generateLabel = computed(() => {
|
const generateLabel = computed(() => {
|
||||||
@@ -2608,6 +2670,7 @@ const composedIdentityPrompt = computed(() => {
|
|||||||
})
|
})
|
||||||
const promptPlaceholder = computed(() => {
|
const promptPlaceholder = computed(() => {
|
||||||
if (studioMode.value === 'editv2') {
|
if (studioMode.value === 'editv2') {
|
||||||
|
if (v2Mode.value === 'generate') return 'A red cube on a white table, studio light.'
|
||||||
if (v2Mode.value === 'refine') return 'Prompt only what should change in the painted area.'
|
if (v2Mode.value === 'refine') return 'Prompt only what should change in the painted area.'
|
||||||
if (v2Mode.value === 'compose' && v2Task.value === 'outfit') return 'Keep everything the same except the clothes from still B.'
|
if (v2Mode.value === 'compose' && v2Task.value === 'outfit') return 'Keep everything the same except the clothes from still B.'
|
||||||
if (v2Mode.value === 'compose' && v2Task.value === 'face_lock') return 'Keep the body and scene from still A. Use the face from still B.'
|
if (v2Mode.value === 'compose' && v2Task.value === 'face_lock') return 'Keep the body and scene from still A. Use the face from still B.'
|
||||||
@@ -3347,17 +3410,19 @@ function currentPresetSnapshot() {
|
|||||||
loraStack: [],
|
loraStack: [],
|
||||||
settings: {
|
settings: {
|
||||||
mode: v2Mode.value,
|
mode: v2Mode.value,
|
||||||
task: v2Mode.value === 'compose' ? v2Task.value : v2Mode.value === 'refine' ? 'refine' : 'scene',
|
task: v2Mode.value === 'compose' ? v2Task.value : v2Mode.value === 'refine' ? 'refine' : v2Mode.value === 'generate' ? 't2i' : 'scene',
|
||||||
negative: v2Negative.value,
|
negative: v2Negative.value,
|
||||||
snofsModel: clampImageV2Strength(v2SnofsModel.value, IMAGE_V2_SNOFS_MODEL),
|
snofsModel: clampImageV2Strength(v2SnofsModel.value, IMAGE_V2_SNOFS_MODEL),
|
||||||
snofsClip: clampImageV2Strength(v2SnofsClip.value, IMAGE_V2_SNOFS_CLIP),
|
snofsClip: clampImageV2Strength(v2SnofsClip.value, IMAGE_V2_SNOFS_CLIP),
|
||||||
consistencyModel: clampImageV2Strength(v2ConsistencyModel.value, IMAGE_V2_CONSISTENCY_MODEL),
|
consistencyModel: v2Mode.value === 'generate' ? 0 : clampImageV2Strength(v2ConsistencyModel.value, IMAGE_V2_CONSISTENCY_MODEL),
|
||||||
consistencyClip: clampImageV2Strength(v2ConsistencyClip.value, IMAGE_V2_CONSISTENCY_CLIP),
|
consistencyClip: v2Mode.value === 'generate' ? 0 : clampImageV2Strength(v2ConsistencyClip.value, IMAGE_V2_CONSISTENCY_CLIP),
|
||||||
steps: clampImageSteps(v2Steps.value, IMAGE_V2_STEPS_DEFAULT),
|
steps: clampImageSteps(v2Steps.value, IMAGE_V2_STEPS_DEFAULT),
|
||||||
cfg: clampImageCfg(v2Cfg.value, IMAGE_V2_CFG_DEFAULT),
|
cfg: clampImageCfg(v2Cfg.value, IMAGE_V2_CFG_DEFAULT),
|
||||||
megapixels: clampImageScaleMegapixels(v2Megapixels.value, 1),
|
megapixels: v2Mode.value === 'generate' ? undefined : clampImageScaleMegapixels(v2Megapixels.value, 1),
|
||||||
turbo: v2Turbo.value === true,
|
turbo: v2Turbo.value === true,
|
||||||
strength: v2Mode.value === 'refine' ? clampImageV2Denoise(v2Denoise.value) : undefined
|
strength: v2Mode.value === 'refine' ? clampImageV2Denoise(v2Denoise.value) : undefined,
|
||||||
|
width: v2Mode.value === 'generate' ? v2Width.value : undefined,
|
||||||
|
height: v2Mode.value === 'generate' ? v2Height.value : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3396,18 +3461,23 @@ function applyGenerationPreset(preset: GenerationPreset) {
|
|||||||
const skipped = preset.loraStack.length - stack.length
|
const skipped = preset.loraStack.length - stack.length
|
||||||
if (preset.kind === 'imagev2') {
|
if (preset.kind === 'imagev2') {
|
||||||
const settings = preset.settings as ImageV2PresetSettings
|
const settings = preset.settings as ImageV2PresetSettings
|
||||||
v2Mode.value = settings.mode === 'compose' ? 'compose' : settings.mode === 'refine' ? 'refine' : 'edit'
|
v2Mode.value = settings.mode === 'compose' ? 'compose' : settings.mode === 'refine' ? 'refine' : settings.mode === 'generate' ? 'generate' : 'edit'
|
||||||
v2Task.value = v2Mode.value === 'compose' ? (settings.task || 'scene') : v2Mode.value === 'refine' ? 'refine' : 'scene'
|
v2Task.value = v2Mode.value === 'compose' ? (settings.task || 'scene') : v2Mode.value === 'refine' ? 'refine' : v2Mode.value === 'generate' ? 't2i' : 'scene'
|
||||||
if (typeof settings.negative === 'string') v2Negative.value = settings.negative
|
if (typeof settings.negative === 'string') v2Negative.value = settings.negative
|
||||||
v2SnofsModel.value = clampImageV2Strength(settings.snofsModel, IMAGE_V2_SNOFS_MODEL)
|
v2SnofsModel.value = clampImageV2Strength(settings.snofsModel, IMAGE_V2_SNOFS_MODEL)
|
||||||
v2SnofsClip.value = clampImageV2Strength(settings.snofsClip, IMAGE_V2_SNOFS_CLIP)
|
v2SnofsClip.value = clampImageV2Strength(settings.snofsClip, IMAGE_V2_SNOFS_CLIP)
|
||||||
v2ConsistencyModel.value = clampImageV2Strength(settings.consistencyModel, IMAGE_V2_CONSISTENCY_MODEL)
|
v2ConsistencyModel.value = v2Mode.value === 'generate' ? 0 : clampImageV2Strength(settings.consistencyModel, IMAGE_V2_CONSISTENCY_MODEL)
|
||||||
v2ConsistencyClip.value = clampImageV2Strength(settings.consistencyClip, IMAGE_V2_CONSISTENCY_CLIP)
|
v2ConsistencyClip.value = v2Mode.value === 'generate' ? 0 : clampImageV2Strength(settings.consistencyClip, IMAGE_V2_CONSISTENCY_CLIP)
|
||||||
v2Steps.value = clampImageSteps(settings.steps, IMAGE_V2_STEPS_DEFAULT)
|
v2Steps.value = clampImageSteps(settings.steps, IMAGE_V2_STEPS_DEFAULT)
|
||||||
v2Cfg.value = clampImageCfg(settings.cfg, IMAGE_V2_CFG_DEFAULT)
|
v2Cfg.value = clampImageCfg(settings.cfg, IMAGE_V2_CFG_DEFAULT)
|
||||||
v2Megapixels.value = clampImageScaleMegapixels(settings.megapixels, 1)
|
v2Megapixels.value = clampImageScaleMegapixels(settings.megapixels, 1)
|
||||||
v2Turbo.value = settings.turbo === true
|
v2Turbo.value = settings.turbo === true
|
||||||
if (v2Mode.value === 'refine') v2Denoise.value = clampImageV2Denoise(settings.strength)
|
if (v2Mode.value === 'refine') v2Denoise.value = clampImageV2Denoise(settings.strength)
|
||||||
|
if (v2Mode.value === 'generate') {
|
||||||
|
const size = clampImageV2Size(settings.width, settings.height)
|
||||||
|
v2Width.value = size.width
|
||||||
|
v2Height.value = size.height
|
||||||
|
}
|
||||||
void ensureRefineCanvas()
|
void ensureRefineCanvas()
|
||||||
imageV2PresetId.value = preset.id
|
imageV2PresetId.value = preset.id
|
||||||
imageV2PresetName.value = preset.name
|
imageV2PresetName.value = preset.name
|
||||||
@@ -5196,12 +5266,35 @@ async function editImage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setV2Mode(mode: ImageV2Mode) {
|
function setV2Mode(mode: ImageV2Mode) {
|
||||||
|
const previous = v2Mode.value
|
||||||
v2Mode.value = mode
|
v2Mode.value = mode
|
||||||
if (mode === 'edit') v2Task.value = 'scene'
|
if (mode === 'edit') v2Task.value = 'scene'
|
||||||
if (mode === 'refine') {
|
if (mode === 'refine') {
|
||||||
v2Task.value = 'refine'
|
v2Task.value = 'refine'
|
||||||
void ensureRefineCanvas()
|
void ensureRefineCanvas()
|
||||||
}
|
}
|
||||||
|
if (mode === 'generate') {
|
||||||
|
v2Task.value = 't2i'
|
||||||
|
v2ConsistencyModel.value = 0
|
||||||
|
v2ConsistencyClip.value = 0
|
||||||
|
} else if (previous === 'generate' && v2ConsistencyModel.value === 0 && v2ConsistencyClip.value === 0) {
|
||||||
|
v2ConsistencyModel.value = IMAGE_V2_CONSISTENCY_MODEL
|
||||||
|
v2ConsistencyClip.value = IMAGE_V2_CONSISTENCY_CLIP
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setGenerateSize(aspect: ImageV2GenerateAspect) {
|
||||||
|
const [width, height] = IMAGE_V2_GENERATE_ASPECTS[aspect]
|
||||||
|
v2Width.value = width
|
||||||
|
v2Height.value = height
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyGenerateLook(kind: 'sfw' | 'snofs') {
|
||||||
|
const look = kind === 'sfw' ? IMAGE_V2_GENERATE_SFW : IMAGE_V2_GENERATE_SNOFS
|
||||||
|
v2SnofsModel.value = look.snofsModel
|
||||||
|
v2SnofsClip.value = look.snofsClip
|
||||||
|
v2ConsistencyModel.value = 0
|
||||||
|
v2ConsistencyClip.value = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyRefinePreset(kind: 'face' | 'hand' | 'heavy') {
|
function applyRefinePreset(kind: 'face' | 'hand' | 'heavy') {
|
||||||
@@ -5238,6 +5331,19 @@ async function ensureRefineCanvas() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function sendToEdit() {
|
||||||
|
if (!editResultUrl.value) return
|
||||||
|
studioMode.value = 'editv2'
|
||||||
|
outputFocus.value = 'edit'
|
||||||
|
try {
|
||||||
|
await useEditAsInput()
|
||||||
|
setV2Mode('edit')
|
||||||
|
toast('Output is Still A. Write an edit prompt.')
|
||||||
|
} catch {
|
||||||
|
toast('Could not send that still to Edit')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function sendToRefine() {
|
async function sendToRefine() {
|
||||||
if (!editResultUrl.value) return
|
if (!editResultUrl.value) return
|
||||||
studioMode.value = 'editv2'
|
studioMode.value = 'editv2'
|
||||||
@@ -5268,8 +5374,8 @@ async function editImageV2() {
|
|||||||
try {
|
try {
|
||||||
const body = new FormData()
|
const body = new FormData()
|
||||||
body.append('mode', v2Mode.value)
|
body.append('mode', v2Mode.value)
|
||||||
body.append('task', v2Mode.value === 'refine' ? 'refine' : v2Mode.value === 'compose' ? v2Task.value : 'scene')
|
body.append('task', v2Mode.value === 'generate' ? 't2i' : v2Mode.value === 'refine' ? 'refine' : v2Mode.value === 'compose' ? v2Task.value : 'scene')
|
||||||
body.append('image_a', file.value as File)
|
if (v2Mode.value !== 'generate' && file.value) body.append('image_a', file.value)
|
||||||
if (v2Mode.value === 'compose' && editRefFile.value) body.append('image_b', editRefFile.value)
|
if (v2Mode.value === 'compose' && editRefFile.value) body.append('image_b', editRefFile.value)
|
||||||
if (v2Mode.value === 'refine') {
|
if (v2Mode.value === 'refine') {
|
||||||
const maskBlob = await refinePainter.value?.exportPng()
|
const maskBlob = await refinePainter.value?.exportPng()
|
||||||
@@ -5280,15 +5386,20 @@ async function editImageV2() {
|
|||||||
body.append('mask', new File([maskBlob], 'refine-mask.png', { type: 'image/png' }))
|
body.append('mask', new File([maskBlob], 'refine-mask.png', { type: 'image/png' }))
|
||||||
body.append('strength', String(clampImageV2Denoise(v2Denoise.value)))
|
body.append('strength', String(clampImageV2Denoise(v2Denoise.value)))
|
||||||
}
|
}
|
||||||
|
if (v2Mode.value === 'generate') {
|
||||||
|
const size = clampImageV2Size(v2Width.value, v2Height.value)
|
||||||
|
body.append('width', String(size.width))
|
||||||
|
body.append('height', String(size.height))
|
||||||
|
}
|
||||||
body.append('prompt', prompt.value.trim())
|
body.append('prompt', prompt.value.trim())
|
||||||
body.append('negative', v2Negative.value)
|
body.append('negative', v2Negative.value)
|
||||||
body.append('snofs_model', String(clampImageV2Strength(v2SnofsModel.value, IMAGE_V2_SNOFS_MODEL)))
|
body.append('snofs_model', String(clampImageV2Strength(v2SnofsModel.value, IMAGE_V2_SNOFS_MODEL)))
|
||||||
body.append('snofs_clip', String(clampImageV2Strength(v2SnofsClip.value, IMAGE_V2_SNOFS_CLIP)))
|
body.append('snofs_clip', String(clampImageV2Strength(v2SnofsClip.value, IMAGE_V2_SNOFS_CLIP)))
|
||||||
body.append('consistency_model', String(clampImageV2Strength(v2ConsistencyModel.value, IMAGE_V2_CONSISTENCY_MODEL)))
|
body.append('consistency_model', String(v2Mode.value === 'generate' ? 0 : clampImageV2Strength(v2ConsistencyModel.value, IMAGE_V2_CONSISTENCY_MODEL)))
|
||||||
body.append('consistency_clip', String(clampImageV2Strength(v2ConsistencyClip.value, IMAGE_V2_CONSISTENCY_CLIP)))
|
body.append('consistency_clip', String(v2Mode.value === 'generate' ? 0 : clampImageV2Strength(v2ConsistencyClip.value, IMAGE_V2_CONSISTENCY_CLIP)))
|
||||||
body.append('steps', String(clampImageSteps(v2Steps.value, IMAGE_V2_STEPS_DEFAULT)))
|
body.append('steps', String(clampImageSteps(v2Steps.value, IMAGE_V2_STEPS_DEFAULT)))
|
||||||
body.append('cfg', String(clampImageCfg(v2Cfg.value, IMAGE_V2_CFG_DEFAULT)))
|
body.append('cfg', String(clampImageCfg(v2Cfg.value, IMAGE_V2_CFG_DEFAULT)))
|
||||||
body.append('megapixels', String(clampImageScaleMegapixels(v2Megapixels.value, 1)))
|
if (v2Mode.value !== 'generate') body.append('megapixels', String(clampImageScaleMegapixels(v2Megapixels.value, 1)))
|
||||||
body.append('turbo', String(v2Turbo.value === true))
|
body.append('turbo', String(v2Turbo.value === true))
|
||||||
body.append('seed', seedInput.value || 'random')
|
body.append('seed', seedInput.value || 'random')
|
||||||
body.append('folderId', folderId.value)
|
body.append('folderId', folderId.value)
|
||||||
@@ -5328,7 +5439,7 @@ async function editImageV2() {
|
|||||||
editChainLabel.value = ''
|
editChainLabel.value = ''
|
||||||
editOverallProgress.value = 0
|
editOverallProgress.value = 0
|
||||||
editCompletedChainStep.value = 0
|
editCompletedChainStep.value = 0
|
||||||
editActiveChainPlan.value = [{ label: v2Mode.value === 'refine' ? 'Refine' : v2Mode.value === 'compose' ? 'Compose' : 'Edit', prompt: prompt.value.trim() }]
|
editActiveChainPlan.value = [{ label: v2Mode.value === 'generate' ? 'Generate' : v2Mode.value === 'refine' ? 'Refine' : v2Mode.value === 'compose' ? 'Compose' : 'Edit', prompt: prompt.value.trim() }]
|
||||||
startTimer('edit')
|
startTimer('edit')
|
||||||
editDownloadName.value = downloadName
|
editDownloadName.value = downloadName
|
||||||
editJobId.value = started.jobId
|
editJobId.value = started.jobId
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import {
|
|||||||
IMAGE_V2_TURBO_STEPS,
|
IMAGE_V2_TURBO_STEPS,
|
||||||
IMAGE_V2_DENOISE_DEFAULT,
|
IMAGE_V2_DENOISE_DEFAULT,
|
||||||
clampImageV2Denoise,
|
clampImageV2Denoise,
|
||||||
|
clampImageV2Size,
|
||||||
clampImageV2Strength,
|
clampImageV2Strength,
|
||||||
parseImageV2Mode,
|
parseImageV2Mode,
|
||||||
parseImageV2Task,
|
parseImageV2Task,
|
||||||
@@ -109,9 +110,12 @@ export default defineEventHandler(async (event) => {
|
|||||||
|
|
||||||
const mode = parseImageV2Mode(fields.mode)
|
const mode = parseImageV2Mode(fields.mode)
|
||||||
if (!mode) {
|
if (!mode) {
|
||||||
throw createError({ statusCode: 400, statusMessage: 'mode must be edit, compose, or refine' })
|
throw createError({ statusCode: 400, statusMessage: 'mode must be edit, compose, refine, or generate' })
|
||||||
}
|
}
|
||||||
const task = parseImageV2Task(fields.task, mode === 'refine' ? 'refine' : 'scene')
|
const task = parseImageV2Task(
|
||||||
|
fields.task,
|
||||||
|
mode === 'generate' ? 't2i' : mode === 'refine' ? 'refine' : 'scene'
|
||||||
|
)
|
||||||
const prompt = String(fields.prompt || '').trim()
|
const prompt = String(fields.prompt || '').trim()
|
||||||
if (!prompt) {
|
if (!prompt) {
|
||||||
throw createError({ statusCode: 400, statusMessage: 'A prompt is required' })
|
throw createError({ statusCode: 400, statusMessage: 'A prompt is required' })
|
||||||
@@ -131,11 +135,11 @@ export default defineEventHandler(async (event) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ownerKey = libraryOwnerKey(event)
|
const ownerKey = libraryOwnerKey(event)
|
||||||
const imageA = await resolveImageRef(ownerKey, fields.image_a, uploadedA)
|
const imageA = mode === 'generate' ? null : await resolveImageRef(ownerKey, fields.image_a, uploadedA)
|
||||||
const imageB = mode === 'refine' ? null : await resolveImageRef(ownerKey, fields.image_b, uploadedB)
|
const imageB = mode === 'refine' || mode === 'generate' ? null : await resolveImageRef(ownerKey, fields.image_b, uploadedB)
|
||||||
const mask = mode === 'refine' ? await resolveImageRef(ownerKey, fields.mask, uploadedMask) : null
|
const mask = mode === 'refine' ? await resolveImageRef(ownerKey, fields.mask, uploadedMask) : null
|
||||||
|
|
||||||
if (!imageA) {
|
if (mode !== 'generate' && !imageA) {
|
||||||
throw createError({ statusCode: 400, statusMessage: 'image_a is required' })
|
throw createError({ statusCode: 400, statusMessage: 'image_a is required' })
|
||||||
}
|
}
|
||||||
if (mode === 'refine' && !mask) {
|
if (mode === 'refine' && !mask) {
|
||||||
@@ -173,17 +177,25 @@ export default defineEventHandler(async (event) => {
|
|||||||
const turbo = parseBool(fields.turbo)
|
const turbo = parseBool(fields.turbo)
|
||||||
const steps = turbo ? IMAGE_V2_TURBO_STEPS : clampImageSteps(fields.steps, IMAGE_V2_STEPS_DEFAULT)
|
const steps = turbo ? IMAGE_V2_TURBO_STEPS : clampImageSteps(fields.steps, IMAGE_V2_STEPS_DEFAULT)
|
||||||
const cfg = turbo ? IMAGE_V2_TURBO_CFG : clampImageCfg(fields.cfg, IMAGE_V2_CFG_DEFAULT)
|
const cfg = turbo ? IMAGE_V2_TURBO_CFG : clampImageCfg(fields.cfg, IMAGE_V2_CFG_DEFAULT)
|
||||||
const megapixels = clampImageScaleMegapixels(fields.megapixels ?? fields.scaleMegapixels, 1)
|
const megapixels = mode === 'generate' ? 0 : clampImageScaleMegapixels(fields.megapixels ?? fields.scaleMegapixels, 1)
|
||||||
const seed = fields.seed && String(fields.seed) !== 'random'
|
const seed = fields.seed && String(fields.seed) !== 'random'
|
||||||
? Number(fields.seed)
|
? Number(fields.seed)
|
||||||
: Math.floor(Math.random() * 2_147_483_647)
|
: Math.floor(Math.random() * 2_147_483_647)
|
||||||
const size = imageDimensions(imageA.data)
|
const generateSize = clampImageV2Size(fields.width, fields.height, fields.aspect)
|
||||||
|
const size = mode === 'generate'
|
||||||
|
? { width: generateSize.width, height: generateSize.height }
|
||||||
|
: imageDimensions(imageA!.data)
|
||||||
const clipName = String(fields.name || '').trim().slice(0, 80)
|
const clipName = String(fields.name || '').trim().slice(0, 80)
|
||||||
const v2Mode = mode as ImageV2Mode
|
const v2Mode = mode as ImageV2Mode
|
||||||
const v2Task = (mode === 'refine' ? 'refine' : mode === 'edit' ? 'scene' : task) as ImageV2Task
|
const v2Task = (
|
||||||
|
mode === 'generate' ? 't2i' : mode === 'refine' ? 'refine' : mode === 'edit' ? 'scene' : task
|
||||||
|
) as ImageV2Task
|
||||||
const refineStrength = mode === 'refine' ? clampImageV2Denoise(fields.strength, IMAGE_V2_DENOISE_DEFAULT) : undefined
|
const refineStrength = mode === 'refine' ? clampImageV2Denoise(fields.strength, IMAGE_V2_DENOISE_DEFAULT) : undefined
|
||||||
|
const generateConsistencyModel = clampImageV2Strength(fields.consistency_model, mode === 'generate' ? 0 : IMAGE_V2_CONSISTENCY_MODEL)
|
||||||
|
const generateConsistencyClip = clampImageV2Strength(fields.consistency_clip, mode === 'generate' ? 0 : IMAGE_V2_CONSISTENCY_CLIP)
|
||||||
|
|
||||||
const still = await rememberInputStill({
|
const still = imageA
|
||||||
|
? await rememberInputStill({
|
||||||
ownerKey,
|
ownerKey,
|
||||||
folderId,
|
folderId,
|
||||||
filename: imageA.filename,
|
filename: imageA.filename,
|
||||||
@@ -192,6 +204,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
height: size?.height || 0,
|
height: size?.height || 0,
|
||||||
hideInput
|
hideInput
|
||||||
})
|
})
|
||||||
|
: null
|
||||||
const savedRef = imageB
|
const savedRef = imageB
|
||||||
? await rememberInputStill({
|
? await rememberInputStill({
|
||||||
ownerKey,
|
ownerKey,
|
||||||
@@ -219,7 +232,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
prompt,
|
prompt,
|
||||||
name: clipName,
|
name: clipName,
|
||||||
folderId,
|
folderId,
|
||||||
aspect: 'auto',
|
aspect: mode === 'generate' ? (generateSize.aspect || '1:1') : 'auto',
|
||||||
width: size?.width || 0,
|
width: size?.width || 0,
|
||||||
height: size?.height || 0,
|
height: size?.height || 0,
|
||||||
steps,
|
steps,
|
||||||
@@ -244,15 +257,15 @@ export default defineEventHandler(async (event) => {
|
|||||||
negative: String(fields.negative || '').trim(),
|
negative: String(fields.negative || '').trim(),
|
||||||
referenceStillId: savedRef?.id,
|
referenceStillId: savedRef?.id,
|
||||||
referenceStillFilename: savedRef?.filename,
|
referenceStillFilename: savedRef?.filename,
|
||||||
scaleToTotalPixels: true,
|
scaleToTotalPixels: mode !== 'generate',
|
||||||
scaleMegapixels: megapixels,
|
scaleMegapixels: megapixels,
|
||||||
imagePipeline: 'v2',
|
imagePipeline: 'v2',
|
||||||
v2Mode,
|
v2Mode,
|
||||||
v2Task,
|
v2Task,
|
||||||
snofsModel: clampImageV2Strength(fields.snofs_model, IMAGE_V2_SNOFS_MODEL),
|
snofsModel: clampImageV2Strength(fields.snofs_model, IMAGE_V2_SNOFS_MODEL),
|
||||||
snofsClip: clampImageV2Strength(fields.snofs_clip, IMAGE_V2_SNOFS_CLIP),
|
snofsClip: clampImageV2Strength(fields.snofs_clip, IMAGE_V2_SNOFS_CLIP),
|
||||||
consistencyModel: clampImageV2Strength(fields.consistency_model, IMAGE_V2_CONSISTENCY_MODEL),
|
consistencyModel: generateConsistencyModel,
|
||||||
consistencyClip: clampImageV2Strength(fields.consistency_clip, IMAGE_V2_CONSISTENCY_CLIP),
|
consistencyClip: generateConsistencyClip,
|
||||||
maskStillId: savedMask?.id,
|
maskStillId: savedMask?.id,
|
||||||
maskStillFilename: savedMask?.filename,
|
maskStillFilename: savedMask?.filename,
|
||||||
refineStrength
|
refineStrength
|
||||||
@@ -275,7 +288,11 @@ export default defineEventHandler(async (event) => {
|
|||||||
cfg,
|
cfg,
|
||||||
mode: v2Mode,
|
mode: v2Mode,
|
||||||
task: v2Task,
|
task: v2Task,
|
||||||
workflow: v2Mode === 'refine' ? 'klein_v2_refine.json' : v2Mode === 'compose' ? 'klein_v2_compose.json' : 'klein_v2_edit.json',
|
workflow: v2Mode === 'generate'
|
||||||
|
? 'klein_v2_generate.json'
|
||||||
|
: v2Mode === 'refine' ? 'klein_v2_refine.json' : v2Mode === 'compose' ? 'klein_v2_compose.json' : 'klein_v2_edit.json',
|
||||||
|
width: size?.width || 0,
|
||||||
|
height: size?.height || 0,
|
||||||
strength: refineStrength,
|
strength: refineStrength,
|
||||||
hideThumbnail,
|
hideThumbnail,
|
||||||
folderLocked
|
folderLocked
|
||||||
|
|||||||
@@ -0,0 +1,127 @@
|
|||||||
|
{
|
||||||
|
"4": {
|
||||||
|
"inputs": {
|
||||||
|
"unet_name": "flux-2-klein-base-9b-fp8.safetensors",
|
||||||
|
"weight_dtype": "default"
|
||||||
|
},
|
||||||
|
"class_type": "UNETLoader",
|
||||||
|
"_meta": { "title": "Load Flux.2 Klein 9B Base" }
|
||||||
|
},
|
||||||
|
"5": {
|
||||||
|
"inputs": {
|
||||||
|
"clip_name": "qwen_3_8b_fp8mixed.safetensors",
|
||||||
|
"type": "flux2",
|
||||||
|
"device": "default"
|
||||||
|
},
|
||||||
|
"class_type": "CLIPLoader",
|
||||||
|
"_meta": { "title": "Load Qwen 3 8B CLIP" }
|
||||||
|
},
|
||||||
|
"6": {
|
||||||
|
"inputs": { "vae_name": "full_encoder_small_decoder.safetensors" },
|
||||||
|
"class_type": "VAELoader",
|
||||||
|
"_meta": { "title": "Load Klein VAE" }
|
||||||
|
},
|
||||||
|
"7": {
|
||||||
|
"inputs": {
|
||||||
|
"lora_name": "klein_snofs_v1_4.safetensors",
|
||||||
|
"strength_model": 0.65,
|
||||||
|
"strength_clip": 0.35,
|
||||||
|
"model": ["4", 0],
|
||||||
|
"clip": ["5", 0]
|
||||||
|
},
|
||||||
|
"class_type": "LoraLoader",
|
||||||
|
"_meta": { "title": "SNOFS" }
|
||||||
|
},
|
||||||
|
"8": {
|
||||||
|
"inputs": {
|
||||||
|
"lora_name": "Flux2-Klein-9B-consistency-V2.safetensors",
|
||||||
|
"strength_model": 0,
|
||||||
|
"strength_clip": 0,
|
||||||
|
"model": ["7", 0],
|
||||||
|
"clip": ["7", 1]
|
||||||
|
},
|
||||||
|
"class_type": "LoraLoader",
|
||||||
|
"_meta": { "title": "Consistency" }
|
||||||
|
},
|
||||||
|
"9": {
|
||||||
|
"inputs": {
|
||||||
|
"text": "",
|
||||||
|
"clip": ["8", 1]
|
||||||
|
},
|
||||||
|
"class_type": "CLIPTextEncode",
|
||||||
|
"_meta": { "title": "Positive Prompt" }
|
||||||
|
},
|
||||||
|
"10": {
|
||||||
|
"inputs": {
|
||||||
|
"text": "",
|
||||||
|
"clip": ["8", 1]
|
||||||
|
},
|
||||||
|
"class_type": "CLIPTextEncode",
|
||||||
|
"_meta": { "title": "Negative Prompt" }
|
||||||
|
},
|
||||||
|
"14": {
|
||||||
|
"inputs": {
|
||||||
|
"width": 1024,
|
||||||
|
"height": 1024,
|
||||||
|
"batch_size": 1
|
||||||
|
},
|
||||||
|
"class_type": "EmptyFlux2LatentImage",
|
||||||
|
"_meta": { "title": "Empty Flux 2 Latent" }
|
||||||
|
},
|
||||||
|
"15": {
|
||||||
|
"inputs": { "noise_seed": 1 },
|
||||||
|
"class_type": "RandomNoise",
|
||||||
|
"_meta": { "title": "RandomNoise" }
|
||||||
|
},
|
||||||
|
"16": {
|
||||||
|
"inputs": { "sampler_name": "euler" },
|
||||||
|
"class_type": "KSamplerSelect",
|
||||||
|
"_meta": { "title": "KSamplerSelect" }
|
||||||
|
},
|
||||||
|
"17": {
|
||||||
|
"inputs": {
|
||||||
|
"steps": 24,
|
||||||
|
"width": 1024,
|
||||||
|
"height": 1024
|
||||||
|
},
|
||||||
|
"class_type": "Flux2Scheduler",
|
||||||
|
"_meta": { "title": "Flux2Scheduler" }
|
||||||
|
},
|
||||||
|
"18": {
|
||||||
|
"inputs": {
|
||||||
|
"cfg": 4,
|
||||||
|
"model": ["8", 0],
|
||||||
|
"positive": ["9", 0],
|
||||||
|
"negative": ["10", 0]
|
||||||
|
},
|
||||||
|
"class_type": "CFGGuider",
|
||||||
|
"_meta": { "title": "CFG Guider" }
|
||||||
|
},
|
||||||
|
"19": {
|
||||||
|
"inputs": {
|
||||||
|
"noise": ["15", 0],
|
||||||
|
"guider": ["18", 0],
|
||||||
|
"sampler": ["16", 0],
|
||||||
|
"sigmas": ["17", 0],
|
||||||
|
"latent_image": ["14", 0]
|
||||||
|
},
|
||||||
|
"class_type": "SamplerCustomAdvanced",
|
||||||
|
"_meta": { "title": "SamplerCustomAdvanced" }
|
||||||
|
},
|
||||||
|
"20": {
|
||||||
|
"inputs": {
|
||||||
|
"samples": ["19", 0],
|
||||||
|
"vae": ["6", 0]
|
||||||
|
},
|
||||||
|
"class_type": "VAEDecode",
|
||||||
|
"_meta": { "title": "VAE Decode" }
|
||||||
|
},
|
||||||
|
"21": {
|
||||||
|
"inputs": {
|
||||||
|
"filename_prefix": "aigen-v2-generate",
|
||||||
|
"images": ["20", 0]
|
||||||
|
},
|
||||||
|
"class_type": "SaveImage",
|
||||||
|
"_meta": { "title": "Save Image" }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import {
|
|||||||
IMAGE_V2_STEPS_DEFAULT,
|
IMAGE_V2_STEPS_DEFAULT,
|
||||||
IMAGE_V2_DENOISE_DEFAULT,
|
IMAGE_V2_DENOISE_DEFAULT,
|
||||||
clampImageV2Denoise,
|
clampImageV2Denoise,
|
||||||
|
clampImageV2Size,
|
||||||
clampImageV2Strength,
|
clampImageV2Strength,
|
||||||
parseImageV2Mode,
|
parseImageV2Mode,
|
||||||
parseImageV2Task,
|
parseImageV2Task,
|
||||||
@@ -116,17 +117,19 @@ function sanitizeImageV2Settings(raw: unknown): ImageV2PresetSettings {
|
|||||||
const turbo = rec.turbo === true
|
const turbo = rec.turbo === true
|
||||||
return {
|
return {
|
||||||
mode,
|
mode,
|
||||||
task: mode === 'compose' ? parseImageV2Task(rec.task, 'scene') : mode === 'refine' ? 'refine' : 'scene',
|
task: mode === 'compose' ? parseImageV2Task(rec.task, 'scene') : mode === 'refine' ? 'refine' : mode === 'generate' ? 't2i' : 'scene',
|
||||||
negative: String(rec.negative || '').slice(0, 2000),
|
negative: String(rec.negative || '').slice(0, 2000),
|
||||||
snofsModel: clampImageV2Strength(rec.snofsModel ?? rec.snofs_model, IMAGE_V2_SNOFS_MODEL),
|
snofsModel: clampImageV2Strength(rec.snofsModel ?? rec.snofs_model, IMAGE_V2_SNOFS_MODEL),
|
||||||
snofsClip: clampImageV2Strength(rec.snofsClip ?? rec.snofs_clip, IMAGE_V2_SNOFS_CLIP),
|
snofsClip: clampImageV2Strength(rec.snofsClip ?? rec.snofs_clip, IMAGE_V2_SNOFS_CLIP),
|
||||||
consistencyModel: clampImageV2Strength(rec.consistencyModel ?? rec.consistency_model, IMAGE_V2_CONSISTENCY_MODEL),
|
consistencyModel: clampImageV2Strength(rec.consistencyModel ?? rec.consistency_model, mode === 'generate' ? 0 : IMAGE_V2_CONSISTENCY_MODEL),
|
||||||
consistencyClip: clampImageV2Strength(rec.consistencyClip ?? rec.consistency_clip, IMAGE_V2_CONSISTENCY_CLIP),
|
consistencyClip: clampImageV2Strength(rec.consistencyClip ?? rec.consistency_clip, mode === 'generate' ? 0 : IMAGE_V2_CONSISTENCY_CLIP),
|
||||||
steps: turbo ? 8 : clampImageSteps(rec.steps, IMAGE_V2_STEPS_DEFAULT),
|
steps: turbo ? 8 : clampImageSteps(rec.steps, IMAGE_V2_STEPS_DEFAULT),
|
||||||
cfg: turbo ? 1 : clampImageCfg(rec.cfg, IMAGE_V2_CFG_DEFAULT),
|
cfg: turbo ? 1 : clampImageCfg(rec.cfg, IMAGE_V2_CFG_DEFAULT),
|
||||||
megapixels: clampImageScaleMegapixels(rec.megapixels ?? rec.scaleMegapixels, 1),
|
megapixels: mode === 'generate' ? undefined : clampImageScaleMegapixels(rec.megapixels ?? rec.scaleMegapixels, 1),
|
||||||
turbo,
|
turbo,
|
||||||
strength: mode === 'refine' ? clampImageV2Denoise(rec.strength, IMAGE_V2_DENOISE_DEFAULT) : undefined
|
strength: mode === 'refine' ? clampImageV2Denoise(rec.strength, IMAGE_V2_DENOISE_DEFAULT) : undefined,
|
||||||
|
width: mode === 'generate' ? clampImageV2Size(rec.width, rec.height, rec.aspect).width : undefined,
|
||||||
|
height: mode === 'generate' ? clampImageV2Size(rec.width, rec.height, rec.aspect).height : undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import type { EditImageFile } from '~/server/utils/imageChain'
|
|||||||
export type EditV2RunParams = {
|
export type EditV2RunParams = {
|
||||||
mode: ImageV2Mode
|
mode: ImageV2Mode
|
||||||
task: ImageV2Task
|
task: ImageV2Task
|
||||||
image: EditImageFile
|
image?: EditImageFile | null
|
||||||
reference: EditImageFile | null
|
reference: EditImageFile | null
|
||||||
mask?: EditImageFile | null
|
mask?: EditImageFile | null
|
||||||
prompt: string
|
prompt: string
|
||||||
@@ -27,6 +27,9 @@ export type EditV2RunParams = {
|
|||||||
consistencyClip: number
|
consistencyClip: number
|
||||||
megapixels: number
|
megapixels: number
|
||||||
strength?: number
|
strength?: number
|
||||||
|
width?: number
|
||||||
|
height?: number
|
||||||
|
turbo?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runEditV2(job: Job, params: EditV2RunParams) {
|
export async function runEditV2(job: Job, params: EditV2RunParams) {
|
||||||
@@ -41,6 +44,9 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
|||||||
if (params.mode === 'edit' && params.reference) {
|
if (params.mode === 'edit' && params.reference) {
|
||||||
throw new Error('Edit mode takes one image. Use Compose for two stills.')
|
throw new Error('Edit mode takes one image. Use Compose for two stills.')
|
||||||
}
|
}
|
||||||
|
if (params.mode !== 'generate' && !params.image) {
|
||||||
|
throw new Error('This v2 mode requires still A.')
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await ensureComfyReady((status) => {
|
await ensureComfyReady((status) => {
|
||||||
@@ -55,15 +61,18 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
|||||||
job.imageComfyHost = getComfyHost()
|
job.imageComfyHost = getComfyHost()
|
||||||
|
|
||||||
await withImageComfyHost(job.imageComfyHost, async () => {
|
await withImageComfyHost(job.imageComfyHost, async () => {
|
||||||
|
const generate = params.mode === 'generate'
|
||||||
emitChainJob(job, {
|
emitChainJob(job, {
|
||||||
type: 'status',
|
type: 'status',
|
||||||
message: params.mode === 'refine'
|
message: generate
|
||||||
|
? 'Queueing Klein v2 generate on Beast...'
|
||||||
|
: params.mode === 'refine'
|
||||||
? 'Uploading canvas and mask to Beast...'
|
? 'Uploading canvas and mask to Beast...'
|
||||||
: params.mode === 'compose' ? 'Uploading stills A and B to Beast...' : 'Uploading still A to Beast...',
|
: params.mode === 'compose' ? 'Uploading stills A and B to Beast...' : 'Uploading still A to Beast...',
|
||||||
progress: 8
|
progress: generate ? 12 : 8
|
||||||
})
|
})
|
||||||
const uploaded = await uploadImage(params.image, job.id)
|
const uploaded = generate || !params.image ? null : await uploadImage(params.image, job.id)
|
||||||
const uploadedRef = params.mode === 'refine'
|
const uploadedRef = generate || params.mode === 'refine'
|
||||||
? null
|
? null
|
||||||
: params.reference
|
: params.reference
|
||||||
? await uploadImage({
|
? await uploadImage({
|
||||||
@@ -71,7 +80,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
|||||||
filename: `ref_${params.reference.filename || 'image_b.png'}`
|
filename: `ref_${params.reference.filename || 'image_b.png'}`
|
||||||
}, job.id)
|
}, job.id)
|
||||||
: null
|
: null
|
||||||
const uploadedMask = params.mode === 'refine' && params.mask
|
const uploadedMask = !generate && params.mode === 'refine' && params.mask
|
||||||
? await uploadImage({
|
? await uploadImage({
|
||||||
...params.mask,
|
...params.mask,
|
||||||
filename: `mask_${params.mask.filename || 'refine-mask.png'}`
|
filename: `mask_${params.mask.filename || 'refine-mask.png'}`
|
||||||
@@ -79,6 +88,7 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
|||||||
: null
|
: null
|
||||||
if (job.status === 'cancelled') throw new Error('Job interrupted.')
|
if (job.status === 'cancelled') throw new Error('Job interrupted.')
|
||||||
|
|
||||||
|
if (!generate) {
|
||||||
emitChainJob(job, {
|
emitChainJob(job, {
|
||||||
type: 'status',
|
type: 'status',
|
||||||
message: params.mode === 'refine'
|
message: params.mode === 'refine'
|
||||||
@@ -88,14 +98,15 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
|||||||
: 'Queueing Klein v2 edit on Beast...',
|
: 'Queueing Klein v2 edit on Beast...',
|
||||||
progress: 12
|
progress: 12
|
||||||
})
|
})
|
||||||
|
}
|
||||||
await ensureComfyLoraNames('image')
|
await ensureComfyLoraNames('image')
|
||||||
await assertImageScaleToTotalPixelsNode()
|
if (!generate) await assertImageScaleToTotalPixelsNode()
|
||||||
const built = buildImageV2Workflow({
|
const built = buildImageV2Workflow({
|
||||||
mode: params.mode,
|
mode: params.mode,
|
||||||
task: params.task,
|
task: params.task,
|
||||||
prompt: params.prompt,
|
prompt: params.prompt,
|
||||||
negative: params.negative,
|
negative: params.negative,
|
||||||
imageAName: uploaded.name,
|
imageAName: uploaded?.name,
|
||||||
imageBName: uploadedRef?.name,
|
imageBName: uploadedRef?.name,
|
||||||
maskName: uploadedMask?.name,
|
maskName: uploadedMask?.name,
|
||||||
strength: params.strength,
|
strength: params.strength,
|
||||||
@@ -107,6 +118,9 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
|||||||
cfg: params.cfg,
|
cfg: params.cfg,
|
||||||
seed: params.seed,
|
seed: params.seed,
|
||||||
megapixels: params.megapixels,
|
megapixels: params.megapixels,
|
||||||
|
width: params.width,
|
||||||
|
height: params.height,
|
||||||
|
turbo: params.turbo === true,
|
||||||
filenamePrefix: `aigen_v2_${job.id.slice(0, 8)}`
|
filenamePrefix: `aigen_v2_${job.id.slice(0, 8)}`
|
||||||
})
|
})
|
||||||
const queued = await queuePrompt(built.graph, job.clientId)
|
const queued = await queuePrompt(built.graph, job.clientId)
|
||||||
@@ -154,8 +168,8 @@ export async function runEditV2(job: Job, params: EditV2RunParams) {
|
|||||||
job.stillId = still?.id
|
job.stillId = still?.id
|
||||||
await purgeComfyArtifacts({
|
await purgeComfyArtifacts({
|
||||||
video: { filename: output.filename, subfolder: output.subfolder, type: output.type },
|
video: { filename: output.filename, subfolder: output.subfolder, type: output.type },
|
||||||
imageName: uploaded.name,
|
imageName: uploaded?.name,
|
||||||
imageSubfolder: uploaded.subfolder,
|
imageSubfolder: uploaded?.subfolder,
|
||||||
extraImageNames: [uploadedRef?.name, uploadedMask?.name].filter((name): name is string => Boolean(name)),
|
extraImageNames: [uploadedRef?.name, uploadedMask?.name].filter((name): name is string => Boolean(name)),
|
||||||
promptId: job.promptId
|
promptId: job.promptId
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import editTemplate from '../assets/klein_v2_edit.json'
|
import editTemplate from '../assets/klein_v2_edit.json'
|
||||||
import composeTemplate from '../assets/klein_v2_compose.json'
|
import composeTemplate from '../assets/klein_v2_compose.json'
|
||||||
import refineTemplate from '../assets/klein_v2_refine.json'
|
import refineTemplate from '../assets/klein_v2_refine.json'
|
||||||
|
import generateTemplate from '../assets/klein_v2_generate.json'
|
||||||
import { IMAGE_SCALE_TO_TOTAL_PIXELS } from '~/server/utils/comfy'
|
import { IMAGE_SCALE_TO_TOTAL_PIXELS } from '~/server/utils/comfy'
|
||||||
import { cachedComfyLoraNames } from '~/server/utils/loras'
|
import { cachedComfyLoraNames } from '~/server/utils/loras'
|
||||||
import { resolveComfyLoraName, loraIdentityKey } from '~/utils/loras'
|
import { resolveComfyLoraName, loraIdentityKey } from '~/utils/loras'
|
||||||
@@ -13,7 +14,10 @@ import {
|
|||||||
IMAGE_V2_SNOFS_LORA,
|
IMAGE_V2_SNOFS_LORA,
|
||||||
IMAGE_V2_SNOFS_MODEL,
|
IMAGE_V2_SNOFS_MODEL,
|
||||||
IMAGE_V2_DENOISE_DEFAULT,
|
IMAGE_V2_DENOISE_DEFAULT,
|
||||||
|
IMAGE_V2_GENERATE_HEIGHT,
|
||||||
|
IMAGE_V2_GENERATE_WIDTH,
|
||||||
clampImageV2Denoise,
|
clampImageV2Denoise,
|
||||||
|
clampImageV2Size,
|
||||||
clampImageV2Strength,
|
clampImageV2Strength,
|
||||||
composeImageV2Prompt,
|
composeImageV2Prompt,
|
||||||
type ImageV2Mode,
|
type ImageV2Mode,
|
||||||
@@ -41,16 +45,20 @@ const CONSISTENCY = '8'
|
|||||||
export const IMAGE_V2_EDIT_WORKFLOW = 'klein_v2_edit.json'
|
export const IMAGE_V2_EDIT_WORKFLOW = 'klein_v2_edit.json'
|
||||||
export const IMAGE_V2_COMPOSE_WORKFLOW = 'klein_v2_compose.json'
|
export const IMAGE_V2_COMPOSE_WORKFLOW = 'klein_v2_compose.json'
|
||||||
export const IMAGE_V2_REFINE_WORKFLOW = 'klein_v2_refine.json'
|
export const IMAGE_V2_REFINE_WORKFLOW = 'klein_v2_refine.json'
|
||||||
|
export const IMAGE_V2_GENERATE_WORKFLOW = 'klein_v2_generate.json'
|
||||||
|
|
||||||
export interface ImageV2BuildParams {
|
export interface ImageV2BuildParams {
|
||||||
mode: ImageV2Mode
|
mode: ImageV2Mode
|
||||||
task: ImageV2Task
|
task: ImageV2Task
|
||||||
prompt: string
|
prompt: string
|
||||||
negative?: string
|
negative?: string
|
||||||
imageAName: string
|
imageAName?: string
|
||||||
imageBName?: string
|
imageBName?: string
|
||||||
maskName?: string
|
maskName?: string
|
||||||
strength?: number
|
strength?: number
|
||||||
|
width?: number
|
||||||
|
height?: number
|
||||||
|
turbo?: boolean
|
||||||
snofsModel?: number
|
snofsModel?: number
|
||||||
snofsClip?: number
|
snofsClip?: number
|
||||||
consistencyModel?: number
|
consistencyModel?: number
|
||||||
@@ -102,8 +110,30 @@ function graphHasMaskInput(graph: WorkflowGraph) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bypassLoraNode(graph: WorkflowGraph, id: string, modelFrom: string, clipFrom: string) {
|
||||||
|
delete graph[id]
|
||||||
|
for (const node of Object.values(graph)) {
|
||||||
|
for (const [key, value] of Object.entries(node.inputs)) {
|
||||||
|
if (!Array.isArray(value) || value[0] !== id) continue
|
||||||
|
node.inputs[key] = value[1] === 1 ? [clipFrom, 1] : [modelFrom, 0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function assertImageV2Graph(graph: WorkflowGraph, mode: ImageV2Mode, imageBName?: string) {
|
export function assertImageV2Graph(graph: WorkflowGraph, mode: ImageV2Mode, imageBName?: string) {
|
||||||
const loaders = loadImageNames(graph)
|
const loaders = loadImageNames(graph)
|
||||||
|
if (mode === 'generate') {
|
||||||
|
if (loaders.length) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: 500,
|
||||||
|
statusMessage: 'Generate graph has a required LoadImage. Refusing to run an edit fallback.'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const latent = Object.values(graph).find(node => node.class_type === 'EmptyFlux2LatentImage')
|
||||||
|
if (!latent) {
|
||||||
|
throw createError({ statusCode: 500, statusMessage: 'Generate graph is missing EmptyFlux2LatentImage.' })
|
||||||
|
}
|
||||||
|
}
|
||||||
if (mode === 'refine') {
|
if (mode === 'refine') {
|
||||||
const mask = graph[LOAD_MASK]
|
const mask = graph[LOAD_MASK]
|
||||||
if (!mask || mask.class_type !== 'LoadImage' || !String(mask.inputs.image || '').trim()) {
|
if (!mask || mask.class_type !== 'LoadImage' || !String(mask.inputs.image || '').trim()) {
|
||||||
@@ -140,7 +170,7 @@ export function assertImageV2Graph(graph: WorkflowGraph, mode: ImageV2Mode, imag
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mode !== 'refine' && imageBName && loaders.length < 2) {
|
if (mode !== 'refine' && mode !== 'generate' && imageBName && loaders.length < 2) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
statusMessage: 'image_b was sent but the executed graph has no second image input.'
|
statusMessage: 'image_b was sent but the executed graph has no second image input.'
|
||||||
@@ -161,43 +191,65 @@ export function assertImageV2Graph(graph: WorkflowGraph, mode: ImageV2Mode, imag
|
|||||||
export function buildImageV2Workflow(params: ImageV2BuildParams) {
|
export function buildImageV2Workflow(params: ImageV2BuildParams) {
|
||||||
const compose = params.mode === 'compose'
|
const compose = params.mode === 'compose'
|
||||||
const refine = params.mode === 'refine'
|
const refine = params.mode === 'refine'
|
||||||
|
const generate = params.mode === 'generate'
|
||||||
if (refine && !String(params.maskName || '').trim()) {
|
if (refine && !String(params.maskName || '').trim()) {
|
||||||
throw createError({ statusCode: 400, statusMessage: 'Refine requires a mask. Refusing to fall back to Edit.' })
|
throw createError({ statusCode: 400, statusMessage: 'Refine requires a mask. Refusing to fall back to Edit.' })
|
||||||
}
|
}
|
||||||
const graph = structuredClone(refine ? refineTemplate : compose ? composeTemplate : editTemplate) as WorkflowGraph
|
const graph = structuredClone(
|
||||||
|
generate ? generateTemplate : refine ? refineTemplate : compose ? composeTemplate : editTemplate
|
||||||
|
) as WorkflowGraph
|
||||||
const prompt = composeImageV2Prompt(params.mode, params.task, params.prompt)
|
const prompt = composeImageV2Prompt(params.mode, params.task, params.prompt)
|
||||||
const negative = String(params.negative || '')
|
const negative = String(params.negative || '')
|
||||||
const snofsModel = clampImageV2Strength(params.snofsModel, IMAGE_V2_SNOFS_MODEL)
|
const snofsModel = clampImageV2Strength(params.snofsModel, IMAGE_V2_SNOFS_MODEL)
|
||||||
const snofsClip = clampImageV2Strength(params.snofsClip, IMAGE_V2_SNOFS_CLIP)
|
const snofsClip = clampImageV2Strength(params.snofsClip, IMAGE_V2_SNOFS_CLIP)
|
||||||
const consistencyModel = clampImageV2Strength(params.consistencyModel, IMAGE_V2_CONSISTENCY_MODEL)
|
const consistencyModel = clampImageV2Strength(
|
||||||
const consistencyClip = clampImageV2Strength(params.consistencyClip, IMAGE_V2_CONSISTENCY_CLIP)
|
params.consistencyModel,
|
||||||
|
generate ? 0 : IMAGE_V2_CONSISTENCY_MODEL
|
||||||
|
)
|
||||||
|
const consistencyClip = clampImageV2Strength(
|
||||||
|
params.consistencyClip,
|
||||||
|
generate ? 0 : IMAGE_V2_CONSISTENCY_CLIP
|
||||||
|
)
|
||||||
const steps = clampImageSteps(params.steps, 24)
|
const steps = clampImageSteps(params.steps, 24)
|
||||||
const cfg = clampImageCfg(params.cfg, 4)
|
const cfg = clampImageCfg(params.cfg, 4)
|
||||||
const strength = refine ? clampImageV2Denoise(params.strength, IMAGE_V2_DENOISE_DEFAULT) : undefined
|
const strength = refine ? clampImageV2Denoise(params.strength, IMAGE_V2_DENOISE_DEFAULT) : undefined
|
||||||
const workflowFile = refine ? IMAGE_V2_REFINE_WORKFLOW : compose ? IMAGE_V2_COMPOSE_WORKFLOW : IMAGE_V2_EDIT_WORKFLOW
|
const size = generate ? clampImageV2Size(params.width, params.height) : null
|
||||||
|
const workflowFile = generate
|
||||||
|
? IMAGE_V2_GENERATE_WORKFLOW
|
||||||
|
: refine ? IMAGE_V2_REFINE_WORKFLOW : compose ? IMAGE_V2_COMPOSE_WORKFLOW : IMAGE_V2_EDIT_WORKFLOW
|
||||||
|
|
||||||
setInput(graph, LOAD_A, 'image', params.imageAName)
|
if (!generate) setInput(graph, LOAD_A, 'image', params.imageAName || '')
|
||||||
if (compose) setInput(graph, LOAD_B, 'image', params.imageBName || '')
|
if (compose) setInput(graph, LOAD_B, 'image', params.imageBName || '')
|
||||||
if (refine) {
|
if (refine) {
|
||||||
setInput(graph, LOAD_MASK, 'image', params.maskName || '')
|
setInput(graph, LOAD_MASK, 'image', params.maskName || '')
|
||||||
setInput(graph, SCHEDULER_DENOISE, 'denoise', strength)
|
setInput(graph, SCHEDULER_DENOISE, 'denoise', strength)
|
||||||
}
|
}
|
||||||
|
if (generate && size) {
|
||||||
|
setInput(graph, '14', 'width', size.width)
|
||||||
|
setInput(graph, '14', 'height', size.height)
|
||||||
|
setInput(graph, SCHEDULER, 'width', size.width)
|
||||||
|
setInput(graph, SCHEDULER, 'height', size.height)
|
||||||
|
}
|
||||||
setInput(graph, PROMPT, 'text', prompt)
|
setInput(graph, PROMPT, 'text', prompt)
|
||||||
setInput(graph, NEGATIVE, 'text', negative)
|
setInput(graph, NEGATIVE, 'text', negative)
|
||||||
setInput(graph, NOISE, 'noise_seed', params.seed)
|
setInput(graph, NOISE, 'noise_seed', params.seed)
|
||||||
setInput(graph, SCHEDULER, 'steps', steps)
|
setInput(graph, SCHEDULER, 'steps', steps)
|
||||||
setInput(graph, CFG, 'cfg', cfg)
|
setInput(graph, CFG, 'cfg', cfg)
|
||||||
setInput(graph, SAVE, 'filename_prefix', params.filenamePrefix || 'aigen-v2')
|
setInput(graph, SAVE, 'filename_prefix', params.filenamePrefix || (generate ? 'aigen-v2-generate' : 'aigen-v2'))
|
||||||
patchScaleMegapixels(graph, params.megapixels ?? 1)
|
if (!generate) patchScaleMegapixels(graph, params.megapixels ?? 1)
|
||||||
|
|
||||||
setInput(graph, SNOFS, 'lora_name', resolveRequiredLora(IMAGE_V2_SNOFS_LORA, 'SNOFS'))
|
setInput(graph, SNOFS, 'lora_name', resolveRequiredLora(IMAGE_V2_SNOFS_LORA, 'SNOFS'))
|
||||||
setInput(graph, SNOFS, 'strength_model', snofsModel)
|
setInput(graph, SNOFS, 'strength_model', snofsModel)
|
||||||
setInput(graph, SNOFS, 'strength_clip', snofsClip)
|
setInput(graph, SNOFS, 'strength_clip', snofsClip)
|
||||||
|
if (generate && consistencyModel <= 0 && consistencyClip <= 0) {
|
||||||
|
bypassLoraNode(graph, CONSISTENCY, SNOFS, SNOFS)
|
||||||
|
} else {
|
||||||
setInput(graph, CONSISTENCY, 'lora_name', resolveRequiredLora(IMAGE_V2_CONSISTENCY_LORA, 'Consistency'))
|
setInput(graph, CONSISTENCY, 'lora_name', resolveRequiredLora(IMAGE_V2_CONSISTENCY_LORA, 'Consistency'))
|
||||||
setInput(graph, CONSISTENCY, 'strength_model', consistencyModel)
|
setInput(graph, CONSISTENCY, 'strength_model', consistencyModel)
|
||||||
setInput(graph, CONSISTENCY, 'strength_clip', consistencyClip)
|
setInput(graph, CONSISTENCY, 'strength_clip', consistencyClip)
|
||||||
|
}
|
||||||
|
|
||||||
assertImageV2Graph(graph, params.mode, refine ? undefined : params.imageBName)
|
assertImageV2Graph(graph, params.mode, generate || refine ? undefined : params.imageBName)
|
||||||
|
|
||||||
const loaders = loadImageNames(graph)
|
const loaders = loadImageNames(graph)
|
||||||
console.log(JSON.stringify({
|
console.log(JSON.stringify({
|
||||||
@@ -205,18 +257,22 @@ export function buildImageV2Workflow(params: ImageV2BuildParams) {
|
|||||||
workflow: workflowFile,
|
workflow: workflowFile,
|
||||||
mode: params.mode,
|
mode: params.mode,
|
||||||
task: params.task,
|
task: params.task,
|
||||||
canvas: { id: LOAD_A, file: graph[LOAD_A]?.inputs.image },
|
canvas: generate ? undefined : { id: LOAD_A, file: graph[LOAD_A]?.inputs.image },
|
||||||
mask: refine ? { id: LOAD_MASK, file: graph[LOAD_MASK]?.inputs.image } : undefined,
|
mask: refine ? { id: LOAD_MASK, file: graph[LOAD_MASK]?.inputs.image } : undefined,
|
||||||
|
size: generate ? { width: size?.width ?? IMAGE_V2_GENERATE_WIDTH, height: size?.height ?? IMAGE_V2_GENERATE_HEIGHT } : undefined,
|
||||||
strength,
|
strength,
|
||||||
|
turbo: params.turbo === true,
|
||||||
loadImage: Object.fromEntries(loaders.map(item => [item.id, { title: item.title, file: item.image }])),
|
loadImage: Object.fromEntries(loaders.map(item => [item.id, { title: item.title, file: item.image }])),
|
||||||
loras: {
|
loras: {
|
||||||
snofs: { name: graph[SNOFS]?.inputs.lora_name, model: snofsModel, clip: snofsClip },
|
snofs: { name: graph[SNOFS]?.inputs.lora_name, model: snofsModel, clip: snofsClip },
|
||||||
consistency: { name: graph[CONSISTENCY]?.inputs.lora_name, model: consistencyModel, clip: consistencyClip }
|
consistency: graph[CONSISTENCY]
|
||||||
|
? { name: graph[CONSISTENCY]?.inputs.lora_name, model: consistencyModel, clip: consistencyClip }
|
||||||
|
: { loaded: false, model: 0, clip: 0 }
|
||||||
},
|
},
|
||||||
steps,
|
steps,
|
||||||
cfg,
|
cfg,
|
||||||
seed: params.seed,
|
seed: params.seed,
|
||||||
megapixels: clampImageScaleMegapixels(params.megapixels ?? 1)
|
megapixels: generate ? undefined : clampImageScaleMegapixels(params.megapixels ?? 1)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return { graph, workflowFile, loaders, prompt, strength }
|
return { graph, workflowFile, loaders, prompt, strength }
|
||||||
@@ -238,6 +294,7 @@ export const IMAGE_V2_NODE_LABELS: Record<string, string> = {
|
|||||||
'11': 'Encoding image A',
|
'11': 'Encoding image A',
|
||||||
'24': 'Encoding image B',
|
'24': 'Encoding image B',
|
||||||
'33': 'Applying mask',
|
'33': 'Applying mask',
|
||||||
|
'14': 'Building empty Klein latent',
|
||||||
'19': 'Sampling Klein v2',
|
'19': 'Sampling Klein v2',
|
||||||
'20': 'Decoding still',
|
'20': 'Decoding still',
|
||||||
'21': 'Saving still'
|
'21': 'Saving still'
|
||||||
|
|||||||
+22
-10
@@ -52,8 +52,8 @@ export interface StudioJobPayload {
|
|||||||
scaleToTotalPixels?: boolean
|
scaleToTotalPixels?: boolean
|
||||||
scaleMegapixels?: number
|
scaleMegapixels?: number
|
||||||
imagePipeline?: 'v1' | 'v2'
|
imagePipeline?: 'v1' | 'v2'
|
||||||
v2Mode?: 'edit' | 'compose' | 'refine'
|
v2Mode?: 'edit' | 'compose' | 'refine' | 'generate'
|
||||||
v2Task?: 'scene' | 'identity' | 'outfit' | 'face_lock' | 'refine'
|
v2Task?: 'scene' | 'identity' | 'outfit' | 'face_lock' | 'refine' | 't2i'
|
||||||
snofsModel?: number
|
snofsModel?: number
|
||||||
snofsClip?: number
|
snofsClip?: number
|
||||||
consistencyModel?: number
|
consistencyModel?: number
|
||||||
@@ -679,14 +679,17 @@ async function startStudioEditJob(item: StudioJob) {
|
|||||||
const { runEditV2 } = await import('~/server/utils/imageChainV2')
|
const { runEditV2 } = await import('~/server/utils/imageChainV2')
|
||||||
|
|
||||||
const payload = item.payload
|
const payload = item.payload
|
||||||
if (!payload.stillId || !existsSync(stillPath(item.ownerKey, payload.stillId))) {
|
const generate = payload.imagePipeline === 'v2' && payload.v2Mode === 'generate'
|
||||||
|
if (!generate && (!payload.stillId || !existsSync(stillPath(item.ownerKey, payload.stillId)))) {
|
||||||
throw new Error('The input still is missing from the library')
|
throw new Error('The input still is missing from the library')
|
||||||
}
|
}
|
||||||
const image = {
|
const image = payload.stillId && existsSync(stillPath(item.ownerKey, payload.stillId))
|
||||||
|
? {
|
||||||
filename: payload.stillFilename || 'still.png',
|
filename: payload.stillFilename || 'still.png',
|
||||||
data: readFileSync(stillPath(item.ownerKey, payload.stillId)),
|
data: readFileSync(stillPath(item.ownerKey, payload.stillId)),
|
||||||
type: 'image/png'
|
type: 'image/png'
|
||||||
}
|
}
|
||||||
|
: null
|
||||||
const refId = payload.referenceStillId
|
const refId = payload.referenceStillId
|
||||||
const reference = refId && existsSync(stillPath(item.ownerKey, refId))
|
const reference = refId && existsSync(stillPath(item.ownerKey, refId))
|
||||||
? {
|
? {
|
||||||
@@ -697,7 +700,13 @@ async function startStudioEditJob(item: StudioJob) {
|
|||||||
: null
|
: null
|
||||||
|
|
||||||
if (payload.imagePipeline === 'v2') {
|
if (payload.imagePipeline === 'v2') {
|
||||||
const mode = payload.v2Mode === 'compose' ? 'compose' : payload.v2Mode === 'refine' ? 'refine' : 'edit'
|
const mode = payload.v2Mode === 'compose'
|
||||||
|
? 'compose'
|
||||||
|
: payload.v2Mode === 'refine'
|
||||||
|
? 'refine'
|
||||||
|
: payload.v2Mode === 'generate'
|
||||||
|
? 'generate'
|
||||||
|
: 'edit'
|
||||||
const maskId = payload.maskStillId
|
const maskId = payload.maskStillId
|
||||||
const mask = mode === 'refine' && maskId && existsSync(stillPath(item.ownerKey, maskId))
|
const mask = mode === 'refine' && maskId && existsSync(stillPath(item.ownerKey, maskId))
|
||||||
? {
|
? {
|
||||||
@@ -745,8 +754,8 @@ async function startStudioEditJob(item: StudioJob) {
|
|||||||
void runEditV2(live, {
|
void runEditV2(live, {
|
||||||
mode,
|
mode,
|
||||||
task: payload.v2Task || 'scene',
|
task: payload.v2Task || 'scene',
|
||||||
image,
|
image: mode === 'generate' ? null : image,
|
||||||
reference: mode === 'refine' ? null : reference,
|
reference: mode === 'refine' || mode === 'generate' ? null : reference,
|
||||||
mask,
|
mask,
|
||||||
prompt: payload.prompt,
|
prompt: payload.prompt,
|
||||||
negative: payload.negative || '',
|
negative: payload.negative || '',
|
||||||
@@ -755,10 +764,13 @@ async function startStudioEditJob(item: StudioJob) {
|
|||||||
cfg: payload.cfg,
|
cfg: payload.cfg,
|
||||||
snofsModel: payload.snofsModel ?? 0.65,
|
snofsModel: payload.snofsModel ?? 0.65,
|
||||||
snofsClip: payload.snofsClip ?? 0.35,
|
snofsClip: payload.snofsClip ?? 0.35,
|
||||||
consistencyModel: payload.consistencyModel ?? 0.7,
|
consistencyModel: payload.consistencyModel ?? (mode === 'generate' ? 0 : 0.7),
|
||||||
consistencyClip: payload.consistencyClip ?? 0.7,
|
consistencyClip: payload.consistencyClip ?? (mode === 'generate' ? 0 : 0.7),
|
||||||
megapixels: payload.scaleMegapixels ?? 1,
|
megapixels: payload.scaleMegapixels ?? 1,
|
||||||
strength: payload.refineStrength
|
strength: payload.refineStrength,
|
||||||
|
width: payload.width,
|
||||||
|
height: payload.height,
|
||||||
|
turbo: payload.turbo === true
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
const message = error instanceof Error ? error.message : String(error)
|
const message = error instanceof Error ? error.message : String(error)
|
||||||
if (live && live.status !== 'error' && live.status !== 'cancelled' && live.status !== 'deferred') {
|
if (live && live.status !== 'error' && live.status !== 'cancelled' && live.status !== 'deferred') {
|
||||||
|
|||||||
+46
-5
@@ -1,5 +1,5 @@
|
|||||||
export const IMAGE_V2_MODES = ['edit', 'compose', 'refine'] as const
|
export const IMAGE_V2_MODES = ['edit', 'compose', 'refine', 'generate'] as const
|
||||||
export const IMAGE_V2_TASKS = ['scene', 'identity', 'outfit', 'face_lock', 'refine'] as const
|
export const IMAGE_V2_TASKS = ['scene', 'identity', 'outfit', 'face_lock', 'refine', 't2i'] as const
|
||||||
|
|
||||||
export type ImageV2Mode = (typeof IMAGE_V2_MODES)[number]
|
export type ImageV2Mode = (typeof IMAGE_V2_MODES)[number]
|
||||||
export type ImageV2Task = (typeof IMAGE_V2_TASKS)[number]
|
export type ImageV2Task = (typeof IMAGE_V2_TASKS)[number]
|
||||||
@@ -38,8 +38,21 @@ export const IMAGE_V2_REFINE_HAND = {
|
|||||||
}
|
}
|
||||||
export const IMAGE_V2_REFINE_HEAVY = { strength: 0.55 }
|
export const IMAGE_V2_REFINE_HEAVY = { strength: 0.55 }
|
||||||
export const IMAGE_V2_REFINE_FACE_PROMPT = 'same face as the canvas, same glasses, same cheeks and jaw. Change only the face in the masked area.'
|
export const IMAGE_V2_REFINE_FACE_PROMPT = 'same face as the canvas, same glasses, same cheeks and jaw. Change only the face in the masked area.'
|
||||||
|
export const IMAGE_V2_SIZE_SIDES = [768, 1024, 1280] as const
|
||||||
|
export const IMAGE_V2_GENERATE_WIDTH = 1024
|
||||||
|
export const IMAGE_V2_GENERATE_HEIGHT = 1024
|
||||||
|
export const IMAGE_V2_GENERATE_ASPECTS = {
|
||||||
|
'1:1': [1024, 1024],
|
||||||
|
'3:4': [768, 1024],
|
||||||
|
'4:3': [1024, 768],
|
||||||
|
'16:9': [1280, 768],
|
||||||
|
'9:16': [768, 1280]
|
||||||
|
} as const
|
||||||
|
export type ImageV2GenerateAspect = keyof typeof IMAGE_V2_GENERATE_ASPECTS
|
||||||
|
export const IMAGE_V2_GENERATE_SFW = { snofsModel: 0, snofsClip: 0 }
|
||||||
|
export const IMAGE_V2_GENERATE_SNOFS = { snofsModel: 0.65, snofsClip: 0.35 }
|
||||||
|
|
||||||
export const IMAGE_V2_ROLE_HEADERS: Record<Exclude<ImageV2Task, 'scene' | 'refine'>, string> = {
|
export const IMAGE_V2_ROLE_HEADERS: Record<Exclude<ImageV2Task, 'scene' | 'refine' | 't2i'>, string> = {
|
||||||
outfit: 'Person, face, body, pose, and background from image 1. Clothing only from image 2. Fit the outfit from image 2 to the body in image 1. Do not copy image 2’s face, body shape, or pose.',
|
outfit: 'Person, face, body, pose, and background from image 1. Clothing only from image 2. Fit the outfit from image 2 to the body in image 1. Do not copy image 2’s face, body shape, or pose.',
|
||||||
face_lock: 'Body, pose, and scene from image 1. Exact face from image 2.',
|
face_lock: 'Body, pose, and scene from image 1. Exact face from image 2.',
|
||||||
identity: 'Same person as image 1. Use image 2 only to reinforce the face. Follow the user’s pose/scene prompt.'
|
identity: 'Same person as image 1. Use image 2 only to reinforce the face. Follow the user’s pose/scene prompt.'
|
||||||
@@ -69,10 +82,36 @@ export function clampImageV2Denoise(raw: unknown, fallback = IMAGE_V2_DENOISE_DE
|
|||||||
return Math.min(IMAGE_V2_DENOISE_MAX, Math.max(IMAGE_V2_DENOISE_MIN, Math.round(snapped * 100) / 100))
|
return Math.min(IMAGE_V2_DENOISE_MAX, Math.max(IMAGE_V2_DENOISE_MIN, Math.round(snapped * 100) / 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function snapImageV2Side(raw: unknown, fallback = IMAGE_V2_GENERATE_WIDTH) {
|
||||||
|
const value = Number(raw)
|
||||||
|
if (!Number.isFinite(value)) return fallback
|
||||||
|
return IMAGE_V2_SIZE_SIDES.reduce((best, side) => (
|
||||||
|
Math.abs(side - value) < Math.abs(best - value) ? side : best
|
||||||
|
), IMAGE_V2_SIZE_SIDES[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseImageV2Aspect(raw: unknown): ImageV2GenerateAspect | null {
|
||||||
|
const value = String(raw || '').trim()
|
||||||
|
return value in IMAGE_V2_GENERATE_ASPECTS ? value as ImageV2GenerateAspect : null
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clampImageV2Size(width: unknown, height: unknown, aspect?: unknown) {
|
||||||
|
const preset = parseImageV2Aspect(aspect)
|
||||||
|
if (preset) {
|
||||||
|
const [w, h] = IMAGE_V2_GENERATE_ASPECTS[preset]
|
||||||
|
return { width: w, height: h, aspect: preset }
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
width: snapImageV2Side(width, IMAGE_V2_GENERATE_WIDTH),
|
||||||
|
height: snapImageV2Side(height, IMAGE_V2_GENERATE_HEIGHT),
|
||||||
|
aspect: null as ImageV2GenerateAspect | null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function composeImageV2Prompt(mode: ImageV2Mode, task: ImageV2Task, prompt: string) {
|
export function composeImageV2Prompt(mode: ImageV2Mode, task: ImageV2Task, prompt: string) {
|
||||||
const body = String(prompt || '').trim()
|
const body = String(prompt || '').trim()
|
||||||
if (mode === 'refine' || mode !== 'compose' || task === 'scene') return body
|
if (mode === 'generate' || mode === 'refine' || mode !== 'compose' || task === 'scene' || task === 't2i') return body
|
||||||
const header = IMAGE_V2_ROLE_HEADERS[task as Exclude<ImageV2Task, 'scene' | 'refine'>]
|
const header = IMAGE_V2_ROLE_HEADERS[task as Exclude<ImageV2Task, 'scene' | 'refine' | 't2i'>]
|
||||||
return header ? `${header}\n\n${body}` : body
|
return header ? `${header}\n\n${body}` : body
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,4 +128,6 @@ export type ImageV2PresetSettings = {
|
|||||||
megapixels?: number
|
megapixels?: number
|
||||||
turbo?: boolean
|
turbo?: boolean
|
||||||
strength?: number
|
strength?: number
|
||||||
|
width?: number
|
||||||
|
height?: number
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user