Spaces:
Sleeping
Sleeping
Commit
·
decc758
1
Parent(s):
1847d87
fixed zimage guidance scale bug
Browse files- public/index.html +6 -1
- server.js +17 -19
public/index.html
CHANGED
|
@@ -1168,13 +1168,18 @@
|
|
| 1168 |
negative_prompt: (qs(`#negative_prompt${prefix}`).value || '').trim(),
|
| 1169 |
width: Number(qs(`#width${prefix}`).value) || 1024,
|
| 1170 |
height: Number(qs(`#height${prefix}`).value) || 1024,
|
| 1171 |
-
guidance_scale: Number(qs(`#guidance_scale${prefix}`).value)
|
| 1172 |
num_inference_steps: Number(qs(`#num_inference_steps${prefix}`).value) || 20,
|
| 1173 |
true_cfg_scale: Number(qs(`#true_cfg_scale${prefix}`)?.value) || 4,
|
| 1174 |
image_b64s: state.imageB64s ? state.imageB64s.slice(0, 3) : [],
|
| 1175 |
seed: state.seedRandom ? null : 0,
|
| 1176 |
resolution: (qs(`#resolution${prefix}`) && qs(`#resolution${prefix}`).value) || ''
|
| 1177 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1178 |
|
| 1179 |
// 添加 Z-Image-Turbo 特定参数(从 UI 控件读取)
|
| 1180 |
const shiftEl = qs(`#shift${prefix}`);
|
|
|
|
| 1168 |
negative_prompt: (qs(`#negative_prompt${prefix}`).value || '').trim(),
|
| 1169 |
width: Number(qs(`#width${prefix}`).value) || 1024,
|
| 1170 |
height: Number(qs(`#height${prefix}`).value) || 1024,
|
| 1171 |
+
guidance_scale: Number(qs(`#guidance_scale${prefix}`).value),
|
| 1172 |
num_inference_steps: Number(qs(`#num_inference_steps${prefix}`).value) || 20,
|
| 1173 |
true_cfg_scale: Number(qs(`#true_cfg_scale${prefix}`)?.value) || 4,
|
| 1174 |
image_b64s: state.imageB64s ? state.imageB64s.slice(0, 3) : [],
|
| 1175 |
seed: state.seedRandom ? null : 0,
|
| 1176 |
resolution: (qs(`#resolution${prefix}`) && qs(`#resolution${prefix}`).value) || ''
|
| 1177 |
};
|
| 1178 |
+
|
| 1179 |
+
// Handle guidance_scale default value properly - only use default if value is NaN (empty input)
|
| 1180 |
+
if (Number.isNaN(params.guidance_scale)) {
|
| 1181 |
+
params.guidance_scale = 6;
|
| 1182 |
+
}
|
| 1183 |
|
| 1184 |
// 添加 Z-Image-Turbo 特定参数(从 UI 控件读取)
|
| 1185 |
const shiftEl = qs(`#shift${prefix}`);
|
server.js
CHANGED
|
@@ -312,7 +312,11 @@ app.post('/api/generate', async (req, res) => {
|
|
| 312 |
negative_prompt: (body.negative_prompt ?? (body.input_args ? body.input_args.negative_prompt : undefined) ?? '').toString(),
|
| 313 |
width: clamp(parseInt(body.width ?? (body.input_args ? body.input_args.width : 1024), 10) || 1024, 128, 2048),
|
| 314 |
height: clamp(parseInt(body.height ?? (body.input_args ? body.input_args.height : 1024), 10) || 1024, 128, 2048),
|
| 315 |
-
guidance_scale: clamp(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 316 |
num_inference_steps: clamp(parseInt(body.num_inference_steps ?? (body.input_args ? body.input_args.num_inference_steps : 25), 10) || 25, 1, 100),
|
| 317 |
// Seed: support top-level or input_args.seed; if missing/null -> null (omit from payload)
|
| 318 |
seed: (() => {
|
|
@@ -495,7 +499,14 @@ app.post('/api/generate', async (req, res) => {
|
|
| 495 |
|
| 496 |
// Z-Image-Turbo minimal payload (top-level prompt only, as shown in curl example)
|
| 497 |
const variantZImageMinimal = isZImageTurbo ? {
|
| 498 |
-
prompt: flat.prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
} : null;
|
| 500 |
|
| 501 |
// Minimal payload (some models reject extended fields). Include size/steps/seed for hunyuan-image-3 compatibility
|
|
@@ -622,26 +633,13 @@ app.post('/api/generate', async (req, res) => {
|
|
| 622 |
|
| 623 |
if (isZImageTurbo) {
|
| 624 |
// Z-Image-Turbo: try minimal payload first (as shown in curl example)
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
} catch (e0) {}
|
| 629 |
-
}
|
| 630 |
-
// If minimal fails, try full nested payload
|
| 631 |
-
if (!result && variantZImageNested) {
|
| 632 |
-
try {
|
| 633 |
-
result = await tryCall(variantZImageNested, 'z-image-turbo-nested', generateUrl);
|
| 634 |
-
} catch (e1) {}
|
| 635 |
-
}
|
| 636 |
} else if (isHunyuan) {
|
| 637 |
try {
|
| 638 |
-
result = await tryCall(
|
| 639 |
} catch (e0) {}
|
| 640 |
-
if (!result) {
|
| 641 |
-
try {
|
| 642 |
-
result = await tryCall(variantFlatMinimal, 'flat-minimal', generateUrl);
|
| 643 |
-
} catch (e1) {}
|
| 644 |
-
}
|
| 645 |
} else {
|
| 646 |
try {
|
| 647 |
result = await tryCall(variantFlatMinimal, 'flat-minimal', generateUrl);
|
|
|
|
| 312 |
negative_prompt: (body.negative_prompt ?? (body.input_args ? body.input_args.negative_prompt : undefined) ?? '').toString(),
|
| 313 |
width: clamp(parseInt(body.width ?? (body.input_args ? body.input_args.width : 1024), 10) || 1024, 128, 2048),
|
| 314 |
height: clamp(parseInt(body.height ?? (body.input_args ? body.input_args.height : 1024), 10) || 1024, 128, 2048),
|
| 315 |
+
guidance_scale: clamp((() => {
|
| 316 |
+
const raw = body.guidance_scale ?? (body.input_args ? body.input_args.guidance_scale : undefined);
|
| 317 |
+
const parsed = parseFloat(raw);
|
| 318 |
+
return Number.isNaN(parsed) ? 7.5 : parsed;
|
| 319 |
+
})(), 0, 20),
|
| 320 |
num_inference_steps: clamp(parseInt(body.num_inference_steps ?? (body.input_args ? body.input_args.num_inference_steps : 25), 10) || 25, 1, 100),
|
| 321 |
// Seed: support top-level or input_args.seed; if missing/null -> null (omit from payload)
|
| 322 |
seed: (() => {
|
|
|
|
| 499 |
|
| 500 |
// Z-Image-Turbo minimal payload (top-level prompt only, as shown in curl example)
|
| 501 |
const variantZImageMinimal = isZImageTurbo ? {
|
| 502 |
+
prompt: flat.prompt,
|
| 503 |
+
height: flat.height,
|
| 504 |
+
width: flat.width,
|
| 505 |
+
num_inference_steps: flat.num_inference_steps,
|
| 506 |
+
guidance_scale: flat.guidance_scale,
|
| 507 |
+
shift: (inputExtras && inputExtras.shift !== undefined) ? Number(inputExtras.shift) : 3.0,
|
| 508 |
+
max_sequence_length: (inputExtras && inputExtras.max_sequence_length !== undefined) ? Number(inputExtras.max_sequence_length) : 512,
|
| 509 |
+
...(flat.seed !== null ? { seed: flat.seed } : {})
|
| 510 |
} : null;
|
| 511 |
|
| 512 |
// Minimal payload (some models reject extended fields). Include size/steps/seed for hunyuan-image-3 compatibility
|
|
|
|
| 633 |
|
| 634 |
if (isZImageTurbo) {
|
| 635 |
// Z-Image-Turbo: try minimal payload first (as shown in curl example)
|
| 636 |
+
try {
|
| 637 |
+
result = await tryCall(variantZImageMinimal, 'z-image-turbo-minimal', generateUrl);
|
| 638 |
+
} catch (e0) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 639 |
} else if (isHunyuan) {
|
| 640 |
try {
|
| 641 |
+
result = await tryCall(variantFlatMinimal, 'flat-minimal', generateUrl);
|
| 642 |
} catch (e0) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 643 |
} else {
|
| 644 |
try {
|
| 645 |
result = await tryCall(variantFlatMinimal, 'flat-minimal', generateUrl);
|