Forge parameter fix
This commit is contained in:
+39
-8
@@ -81,16 +81,47 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ToolError(f"Failed to connect to Stable Diffusion server: {str(e)}")
|
raise ToolError(f"Failed to connect to Stable Diffusion server: {str(e)}")
|
||||||
|
|
||||||
# Build the label-to-index map
|
# Build the label-to-index map and a sparse payload
|
||||||
label_map = {}
|
label_map = {}
|
||||||
label_counts = {}
|
label_counts = {}
|
||||||
|
|
||||||
payload = [p["parameter_default"] for p in params_info]
|
# Find the maximum param index to determine payload size
|
||||||
|
max_param_idx = 0
|
||||||
|
for p in params_info:
|
||||||
|
name = p.get("parameter_name", "")
|
||||||
|
if name.startswith("param_"):
|
||||||
|
try:
|
||||||
|
idx = int(name.replace("param_", ""))
|
||||||
|
max_param_idx = max(max_param_idx, idx)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
for idx, p in enumerate(params_info):
|
# Initialize payload with Nones (size is max_idx + 1)
|
||||||
label = p["label"]
|
payload = [None] * (max_param_idx + 1)
|
||||||
|
|
||||||
|
for idx_in_list, p in enumerate(params_info):
|
||||||
|
name = p.get("parameter_name", "")
|
||||||
|
label = p.get("label")
|
||||||
|
default = p.get("parameter_default")
|
||||||
|
|
||||||
|
# Determine the absolute index in the payload
|
||||||
|
if name == "id_task":
|
||||||
|
abs_idx = 0
|
||||||
|
elif name.startswith("param_"):
|
||||||
|
try:
|
||||||
|
abs_idx = int(name.replace("param_", ""))
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
# Fallback for unexpected names, though unlikely
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Set the default value at the absolute index
|
||||||
|
payload[abs_idx] = default
|
||||||
|
|
||||||
|
# Handle label mapping for AI overrides
|
||||||
if not label or label.startswith("parameter_"):
|
if not label or label.startswith("parameter_"):
|
||||||
label = p["parameter_name"]
|
label = name
|
||||||
|
|
||||||
if label in label_counts:
|
if label in label_counts:
|
||||||
label_counts[label] += 1
|
label_counts[label] += 1
|
||||||
@@ -99,7 +130,7 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|||||||
label_counts[label] = 0
|
label_counts[label] = 0
|
||||||
mapped_label = label
|
mapped_label = label
|
||||||
|
|
||||||
label_map[mapped_label] = idx
|
label_map[mapped_label] = abs_idx
|
||||||
|
|
||||||
# 3. LOAD CONFIGS
|
# 3. LOAD CONFIGS
|
||||||
models_cfg = load_toml(config.MODEL_PRESETS_PATH)
|
models_cfg = load_toml(config.MODEL_PRESETS_PATH)
|
||||||
@@ -163,8 +194,8 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]:
|
|||||||
if "Seed" in label_map:
|
if "Seed" in label_map:
|
||||||
payload[label_map["Seed"]] = -1
|
payload[label_map["Seed"]] = -1
|
||||||
|
|
||||||
for _ in range(7):
|
# The "Magic Number" splice is no longer needed as gaps are
|
||||||
payload.insert(39, None)
|
# automatically filled by the sparse-to-dense mapping.
|
||||||
|
|
||||||
# 6. EXECUTE GENERATION
|
# 6. EXECUTE GENERATION
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user