bibibi12345 commited on
Commit
95030c6
·
1 Parent(s): b8b2a75

fixed retry bug. fixed highdream

Browse files
Files changed (3) hide show
  1. data/models.json +2 -3
  2. public/index.html +13 -4
  3. server.js +70 -78
data/models.json CHANGED
@@ -1,6 +1,5 @@
1
- [
2
- { "id": "JuggernautXL", "name": "JuggernautXL", "free": true },
3
- { "id": "hidream", "name": "hidream", "free": false },
4
  { "id": "FLUX.1-dev", "name": "FLUX.1-dev", "free": false },
5
  { "id": "FLUX.1-schnell", "name": "FLUX.1-schnell", "free": false },
6
  { "id": "chroma", "name": "chroma", "free": true },
 
1
+ [{ "id": "JuggernautXL", "name": "JuggernautXL", "free": true },
2
+ { "id": "qwen-image", "name": "qwen-image", "free": false },
 
3
  { "id": "FLUX.1-dev", "name": "FLUX.1-dev", "free": false },
4
  { "id": "FLUX.1-schnell", "name": "FLUX.1-schnell", "free": false },
5
  { "id": "chroma", "name": "chroma", "free": true },
public/index.html CHANGED
@@ -1052,7 +1052,7 @@
1052
  }
1053
 
1054
  function genRandomSeed() {
1055
- return Math.floor(Math.random() * 4294967295);
1056
  }
1057
 
1058
  async function fetchModels() {
@@ -1194,6 +1194,15 @@
1194
  return params;
1195
  }
1196
 
 
 
 
 
 
 
 
 
 
1197
  function createPlaceholderCard(i, params) {
1198
  const wrap = document.createElement('div');
1199
  wrap.className = 'card';
@@ -1203,7 +1212,7 @@
1203
  wrap.appendChild(ph);
1204
  const meta = document.createElement('div');
1205
  meta.className = 'meta';
1206
- meta.innerHTML = `${params.model} | ${params.width}x${params.height}`;
1207
  wrap.appendChild(meta);
1208
  qs('#gallery').prepend(wrap);
1209
  return wrap;
@@ -1248,7 +1257,7 @@
1248
  const metaContent = document.createElement('div');
1249
  metaContent.className = 'meta-content';
1250
  metaContent.innerHTML = `
1251
- <div style="margin-bottom: 4px;">尺寸: ${params.width}x${params.height}</div>
1252
  <div style="margin-bottom: 4px;">步数: ${params.num_inference_steps} | 引导: ${params.guidance_scale}</div>
1253
  <div style="margin-bottom: 8px; font-size: 12px; line-height: 1.3; word-break: break-all;">${params.prompt}</div>
1254
  `;
@@ -2033,7 +2042,7 @@ function isViewerOpen() {
2033
 
2034
  modalImg.src = imageUrl;
2035
  if (params) {
2036
- modalInfo.textContent = `${params.width}×${params.height} | ${params.model}`;
2037
  } else {
2038
  modalInfo.textContent = '';
2039
  }
 
1052
  }
1053
 
1054
  function genRandomSeed() {
1055
+ return Math.floor(Math.random() * 100000000);
1056
  }
1057
 
1058
  async function fetchModels() {
 
1194
  return params;
1195
  }
1196
 
1197
+ // Helper to get display size string (resolution for hidream, width x height for others)
1198
+ function getDisplaySize(params) {
1199
+ const isHidream = (params.model || '').toLowerCase() === 'hidream';
1200
+ if (isHidream && params.resolution) {
1201
+ return params.resolution;
1202
+ }
1203
+ return `${params.width}x${params.height}`;
1204
+ }
1205
+
1206
  function createPlaceholderCard(i, params) {
1207
  const wrap = document.createElement('div');
1208
  wrap.className = 'card';
 
1212
  wrap.appendChild(ph);
1213
  const meta = document.createElement('div');
1214
  meta.className = 'meta';
1215
+ meta.innerHTML = `${params.model} | ${getDisplaySize(params)}`;
1216
  wrap.appendChild(meta);
1217
  qs('#gallery').prepend(wrap);
1218
  return wrap;
 
1257
  const metaContent = document.createElement('div');
1258
  metaContent.className = 'meta-content';
1259
  metaContent.innerHTML = `
1260
+ <div style="margin-bottom: 4px;">尺寸: ${getDisplaySize(params)}</div>
1261
  <div style="margin-bottom: 4px;">步数: ${params.num_inference_steps} | 引导: ${params.guidance_scale}</div>
1262
  <div style="margin-bottom: 8px; font-size: 12px; line-height: 1.3; word-break: break-all;">${params.prompt}</div>
1263
  `;
 
2042
 
2043
  modalImg.src = imageUrl;
2044
  if (params) {
2045
+ modalInfo.textContent = `${getDisplaySize(params)} | ${params.model}`;
2046
  } else {
2047
  modalInfo.textContent = '';
2048
  }
server.js CHANGED
@@ -456,23 +456,16 @@ app.post('/api/generate', async (req, res) => {
456
  };
457
  const variantA = {
458
  model: targetModel,
459
- input_args: isHidream
460
- ? { ...inputExtras, ...commonArgs }
461
- : { ...inputExtras, ...commonArgs, width: flat.width, height: flat.height }
462
  };
463
 
464
- const variantB = isHidream
465
- ? {
466
- model: targetModel,
467
- input_args: { ...inputExtras, ...commonArgs }
468
- }
469
- : {
470
- model: targetModel,
471
- ...topLevelExtras,
472
- ...commonArgs,
473
- width: flat.width,
474
- height: flat.height
475
- };
476
 
477
  // Hidream-specific flat payload expected by chutes-hidream endpoint (no input_args)
478
  const variantHidreamFlat = isHidream ? {
@@ -621,70 +614,70 @@ app.post('/api/generate', async (req, res) => {
621
  }
622
 
623
  let result;
624
-
625
- // If the model prefers minimal payload, choose ordering per model.
626
- // For hunyuan-image-3: nested-minimal (input_args with size) FIRST to ensure size is honored.
627
- // For Z-Image-Turbo: use dedicated nested payload FIRST
628
- if (preferMinimal) {
629
- const isHunyuan =
630
- (typeof flat.model === 'string' && flat.model.toLowerCase() === 'hunyuan-image-3') ||
631
- /hunyuan-image-3/i.test(generateUrl) ||
632
- /hunyuan-image-3/i.test(String(targetModel || ''));
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);
646
- } catch (e0) {}
647
- if (!result) {
648
- try {
649
- result = await tryCall(variantCMinimal, 'nested-minimal', generateUrl);
650
- } catch (e1) {}
651
- }
652
  }
653
- }
654
-
655
- // Only try full payload if minimal didn't succeed
656
- if (!result) {
657
- let lastError = null;
658
-
 
 
 
 
659
  if (!result) {
660
- try { result = await tryCall(variantA, 'nested', generateUrl); }
661
- catch (e1) { lastError = e1; }
 
662
  }
663
-
 
 
 
 
664
  if (!result) {
665
- try { result = await tryCall(variantB, 'flat', generateUrl); }
666
- catch (e2) { lastError = e2; }
667
- }
668
-
669
- // qwen-image-edit official flat payload (no model)
670
- if (!result && isQwenEdit && variantQwenFlat) {
671
- try { result = await tryCall(variantQwenFlat, 'qwen-flat', generateUrl); }
672
- catch (eQ) { lastError = eQ; }
673
  }
 
674
 
675
- // hidream official flat payload (no model)
676
- if (!result && isHidream && variantHidreamFlat) {
677
- try { result = await tryCall(variantHidreamFlat, 'hidream-flat', generateUrl); }
678
- catch (eH) { lastError = eH; }
679
- }
680
 
681
- // Z-Image-Turbo nested payload - fallback if not tried in minimal mode
682
- if (!result && isZImageTurbo && variantZImageNested && !preferMinimal) {
683
- try { result = await tryCall(variantZImageNested, 'z-image-turbo-nested', generateUrl); }
684
- catch (eZ) { lastError = eZ; }
685
- }
686
 
687
- if (!result) {
 
688
  // Auto fallback to another model when capacity/infrastructure errors (disabled when NO_FALLBACK=true)
689
  const capacityCodes = ['UPSTREAM_CAPACITY_EXHAUSTED','UPSTREAM_NO_INSTANCES','UPSTREAM_INFRASTRUCTURE','UPSTREAM_BAD_GATEWAY'];
690
  if (AUTO_FALLBACK && !NO_FALLBACK && lastError && capacityCodes.includes(lastError.code || '')) {
@@ -739,14 +732,13 @@ app.post('/api/generate', async (req, res) => {
739
  }
740
  }
741
 
742
- const status = (lastError && lastError.status) || 502;
743
- return res.status(status).json({
744
- ok: false,
745
- error: (lastError && (lastError.hint || lastError.message)) || 'Upstream error',
746
- code: (lastError && lastError.code) || 'UPSTREAM_ERROR',
747
- upstream_model: targetModel
748
- });
749
- }
750
  }
751
 
752
  return res.json({
 
456
  };
457
  const variantA = {
458
  model: targetModel,
459
+ input_args: { ...inputExtras, ...commonArgs, width: flat.width, height: flat.height }
 
 
460
  };
461
 
462
+ const variantB = {
463
+ model: targetModel,
464
+ ...topLevelExtras,
465
+ ...commonArgs,
466
+ width: flat.width,
467
+ height: flat.height
468
+ };
 
 
 
 
 
469
 
470
  // Hidream-specific flat payload expected by chutes-hidream endpoint (no input_args)
471
  const variantHidreamFlat = isHidream ? {
 
614
  }
615
 
616
  let result;
617
+ let lastError = null;
618
+
619
+ const isHunyuan =
620
+ (typeof flat.model === 'string' && flat.model.toLowerCase() === 'hunyuan-image-3') ||
621
+ /hunyuan-image-3/i.test(generateUrl) ||
622
+ /hunyuan-image-3/i.test(String(targetModel || ''));
623
+
624
+ // Model-specific payloads FIRST - try the correct format before generic fallbacks
625
+ if (isHidream) {
626
+ // HiDream: uses resolution instead of width/height
627
+ try {
628
+ result = await tryCall(variantHidreamFlat, 'hidream-flat', generateUrl);
629
+ } catch (eH) { lastError = eH; }
630
+ } else if (isZImageTurbo) {
631
+ // Z-Image-Turbo: try minimal payload first (as shown in curl example)
632
+ try {
633
+ result = await tryCall(variantZImageMinimal, 'z-image-turbo-minimal', generateUrl);
634
+ } catch (e0) { lastError = e0; }
635
+ // Fallback to nested payload
636
+ if (!result && variantZImageNested) {
637
  try {
638
+ result = await tryCall(variantZImageNested, 'z-image-turbo-nested', generateUrl);
639
+ } catch (eZ) { lastError = eZ; }
 
 
 
 
 
640
  }
641
+ } else if (isQwenEdit) {
642
+ // Qwen-image-edit: try official flat payload first
643
+ try {
644
+ result = await tryCall(variantQwenFlat, 'qwen-flat', generateUrl);
645
+ } catch (eQ) { lastError = eQ; }
646
+ } else if (isHunyuan) {
647
+ // Hunyuan: uses size instead of width/height
648
+ try {
649
+ result = await tryCall(variantFlatMinimal, 'flat-minimal', generateUrl);
650
+ } catch (e0) { lastError = e0; }
651
  if (!result) {
652
+ try {
653
+ result = await tryCall(variantCMinimal, 'nested-minimal', generateUrl);
654
+ } catch (e1) { lastError = e1; }
655
  }
656
+ } else if (preferMinimal) {
657
+ // Other models with minimal preference
658
+ try {
659
+ result = await tryCall(variantFlatMinimal, 'flat-minimal', generateUrl);
660
+ } catch (e0) { lastError = e0; }
661
  if (!result) {
662
+ try {
663
+ result = await tryCall(variantCMinimal, 'nested-minimal', generateUrl);
664
+ } catch (e1) { lastError = e1; }
 
 
 
 
 
665
  }
666
+ }
667
 
668
+ // Generic fallback payloads - only try if model-specific didn't succeed
669
+ if (!result) {
670
+ try { result = await tryCall(variantA, 'nested', generateUrl); }
671
+ catch (e1) { lastError = e1; }
672
+ }
673
 
674
+ if (!result) {
675
+ try { result = await tryCall(variantB, 'flat', generateUrl); }
676
+ catch (e2) { lastError = e2; }
677
+ }
 
678
 
679
+ // Final fallback logic
680
+ if (!result) {
681
  // Auto fallback to another model when capacity/infrastructure errors (disabled when NO_FALLBACK=true)
682
  const capacityCodes = ['UPSTREAM_CAPACITY_EXHAUSTED','UPSTREAM_NO_INSTANCES','UPSTREAM_INFRASTRUCTURE','UPSTREAM_BAD_GATEWAY'];
683
  if (AUTO_FALLBACK && !NO_FALLBACK && lastError && capacityCodes.includes(lastError.code || '')) {
 
732
  }
733
  }
734
 
735
+ const status = (lastError && lastError.status) || 502;
736
+ return res.status(status).json({
737
+ ok: false,
738
+ error: (lastError && (lastError.hint || lastError.message)) || 'Upstream error',
739
+ code: (lastError && lastError.code) || 'UPSTREAM_ERROR',
740
+ upstream_model: targetModel
741
+ });
 
742
  }
743
 
744
  return res.json({