fix: simplify fal scale patch prompt
This commit is contained in:
parent
56d319af66
commit
38961de760
@ -3596,10 +3596,15 @@ function buildScaleAdjustPatchPrompt(
|
||||
patchReference: ScaleAdjustPatchReference,
|
||||
sourceSize: { width: number; height: number },
|
||||
cropReferences: ScaleAdjustCropReference[] = [],
|
||||
options: { includeSourceReference?: boolean; targetDraftPrimary?: boolean } = {}
|
||||
options: {
|
||||
falSafe?: boolean;
|
||||
includeSourceReference?: boolean;
|
||||
targetDraftPrimary?: boolean;
|
||||
} = {}
|
||||
) {
|
||||
const targetDraftPrimary = options.targetDraftPrimary === true;
|
||||
const includeSourceReference = options.includeSourceReference !== false;
|
||||
const falSafe = options.falSafe === true;
|
||||
const structureLockedDraft = patchReference.structureLockedDraft === true;
|
||||
const sourceInputIndex = targetDraftPrimary && includeSourceReference ? 2 : 1;
|
||||
const draftInputIndex = targetDraftPrimary ? 1 : 2;
|
||||
@ -3659,6 +3664,33 @@ function buildScaleAdjustPatchPrompt(
|
||||
return `Region ${region.index}: current search area inside input image ${sourceInputIndex} crop is x=${sourceInPatch.left}, y=${sourceInPatch.top}, w=${sourceInPatch.width}, h=${sourceInPatch.height}; final visual footprint inside input image ${draftInputIndex} / output crop is x=${targetInPatch.left}, y=${targetInPatch.top}, w=${targetInPatch.width}, h=${targetInPatch.height}; requested scale width=${widthFactor.toFixed(2)}, height=${heightFactor.toFixed(2)}. User request: ${region.prompt || action}. Main action: ${action}. Treat the main selected subject inside the search area as the target; it may be a person, model, child, body part, furniture, product, or other object. The final subject must be much closer to the final footprint than to the current search area.${cropNote}`;
|
||||
})
|
||||
.join("\n");
|
||||
const falSafeRegionLines = regions
|
||||
.map((region) => {
|
||||
const targetRect = getScaleAdjustTargetRect(region, scalePercent);
|
||||
const targetPixelRect =
|
||||
region.targetPixelRect ||
|
||||
rectToPixels(targetRect, sourceSize.width, sourceSize.height);
|
||||
const sourceInPatch = toPatchRelativePixelBox(
|
||||
region.pixelRect,
|
||||
patchReference.workspacePixelRect
|
||||
);
|
||||
const targetInPatch = toPatchRelativePixelBox(
|
||||
targetPixelRect,
|
||||
patchReference.workspacePixelRect
|
||||
);
|
||||
const widthFactor =
|
||||
region.rect.width > 0 ? targetRect.width / region.rect.width : 1;
|
||||
const heightFactor =
|
||||
region.rect.height > 0 ? targetRect.height / region.rect.height : 1;
|
||||
const action =
|
||||
widthFactor < 0.92 || heightFactor < 0.92
|
||||
? "make the same selected subject smaller"
|
||||
: widthFactor > 1.08 || heightFactor > 1.08
|
||||
? "make the same selected subject larger"
|
||||
: "move the same selected subject to the final footprint";
|
||||
return `Region ${region.index}: original search area x=${sourceInPatch.left}, y=${sourceInPatch.top}, w=${sourceInPatch.width}, h=${sourceInPatch.height}; final target footprint x=${targetInPatch.left}, y=${targetInPatch.top}, w=${targetInPatch.width}, h=${targetInPatch.height}; scale width=${widthFactor.toFixed(2)}, height=${heightFactor.toFixed(2)}. ${region.prompt || action}`;
|
||||
})
|
||||
.join("\n");
|
||||
const chineseHardConstraint = (() => {
|
||||
if (!targetDraftPrimary) {
|
||||
return "中文硬约束:只输出输入图1同一裁切范围的干净局部照片;输入图2是目标大小/位置草稿,必须按它的目标尺寸和目标位置输出,不是要保留旧尺寸。目标家具必须相对原图产生明显比例变化,非目标背景和裁切边缘要稳定自然。";
|
||||
@ -3673,6 +3705,27 @@ function buildScaleAdjustPatchPrompt(
|
||||
: "中文硬约束:输入图1是唯一视觉参考和目标大小/位置草稿,必须按它的目标尺寸和目标位置输出。不要找回旧尺寸目标主体。草稿里的淡色擦除层/雾块只是提示旧位置需要补背景,不是画面内容,最终不能出现矩形雾块、白块、残影或拼接感。";
|
||||
})();
|
||||
|
||||
if (falSafe) {
|
||||
return [
|
||||
"Clean local image edit for a cropped workspace.",
|
||||
`Return one clean realistic crop with the same framing and aspect as input image 1. This crop maps to full-photo pixels left=${patchReference.workspacePixelRect.left}, top=${patchReference.workspacePixelRect.top}, width=${patchReference.workspacePixelRect.width}, height=${patchReference.workspacePixelRect.height}.`,
|
||||
"Input image 1 is the rough target draft. The selected subject is already placed at the requested final size and position; keep that final footprint.",
|
||||
includeSourceReference
|
||||
? "Input image 2 is the original clean crop for background texture, lighting, perspective, and non-target objects only. Do not restore the selected subject to its old size."
|
||||
: "",
|
||||
"Use AI editing only to clean and blend the draft: remove halos, mask holes, rough edges, ghost fragments, haze blocks, dirty spots, and bad contact shadows.",
|
||||
"Keep the same selected subject identity, product structure, material, perspective, and natural proportions. Do not replace, stretch, duplicate, or redesign it.",
|
||||
"Rebuild newly visible floor, rug, wall, sofa edge, shadow, or background naturally where the old larger footprint was removed.",
|
||||
"Do not output a full-room image. Do not zoom, crop, pan, or resize the whole canvas. Do not draw boxes, lines, labels, arrows, UI marks, overlays, text, seams, or rectangular patch edges.",
|
||||
"中文硬约束:输入图1已经把目标主体放到最终大小和位置;只清理融合局部裁切,不要恢复旧尺寸,不要整图缩放,不要输出标注框、矩形雾块、贴片边、残影或全房间图。",
|
||||
"",
|
||||
"Region instructions:",
|
||||
falSafeRegionLines,
|
||||
"",
|
||||
"Success check: the selected subject must stay much closer to the final target footprint than to the original search area, and the crop must look like one natural photograph.",
|
||||
].filter(Boolean).join("\n");
|
||||
}
|
||||
|
||||
return [
|
||||
"Local selected-subject scale edit inside a cropped workspace.",
|
||||
`Return exactly one clean realistic crop with the same framing and aspect as input image 1. The crop represents full-photo pixels left=${patchReference.workspacePixelRect.left}, top=${patchReference.workspacePixelRect.top}, width=${patchReference.workspacePixelRect.width}, height=${patchReference.workspacePixelRect.height}.`,
|
||||
@ -4017,6 +4070,9 @@ export async function POST(request: NextRequest) {
|
||||
const useScaleAdjustPatchTargetDraftPrimary = Boolean(scaleAdjustPatchReference);
|
||||
const includeScaleAdjustPatchSourceReference =
|
||||
Boolean(scaleAdjustPatchReference);
|
||||
const useFalScaleAdjustPatchPrompt =
|
||||
Boolean(scaleAdjustPatchReference) &&
|
||||
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image";
|
||||
const prompt = isScaleAdjustOperation
|
||||
? scaleAdjustPatchReference
|
||||
? buildScaleAdjustPatchPrompt(
|
||||
@ -4026,6 +4082,7 @@ export async function POST(request: NextRequest) {
|
||||
{ width: sourceWidth, height: sourceHeight },
|
||||
scaleAdjustCropReferences,
|
||||
{
|
||||
falSafe: useFalScaleAdjustPatchPrompt,
|
||||
includeSourceReference: includeScaleAdjustPatchSourceReference,
|
||||
targetDraftPrimary: useScaleAdjustPatchTargetDraftPrimary,
|
||||
}
|
||||
@ -4066,6 +4123,8 @@ export async function POST(request: NextRequest) {
|
||||
"artificial graphic overlay, visible coordinate aid, visible line, visible label, UI element, annotation text, full image redesign, full-frame zoom, crop, pan, pasted crop, hard patch edge, color mismatch, changed sofa, changed lamp, changed wall, changed rug, duplicate subject, duplicate person, duplicate furniture, changed face, deformed person, extra limbs, stretched subject, stretched furniture, distorted furniture";
|
||||
const scaleAdjustPatchNegativePrompt =
|
||||
"full room image, changed crop border, artificial graphic overlay, visible coordinate aid, visible line, visible label, UI element, annotation text, guide mark, pasted crop, hard patch edge, rectangular haze, white haze block, pale wipe block, color mismatch, gray draft patch, beige wash patch, flat painted area, jagged mask hole, black speckled stain, dark blotch, duplicate subject, duplicate person, duplicate furniture, unchanged target subject, unchanged target person, unchanged target furniture, old-size target subject, changed target identity, changed face, deformed person, broken anatomy, extra limbs, extra fingers, changed locked product, redrawn product interior, different furniture, broken woven panel, dirty woven panel, wheel inside woven panel, stretched subject, stretched furniture, distorted furniture";
|
||||
const scaleAdjustFalPatchNegativePrompt =
|
||||
"full room image, boxes, labels, UI marks, arrows, text, overlays, seams, rectangular patch edge, haze block, ghost copy, old-size subject, unchanged subject, duplicate subject, stretched subject, distorted product, changed product structure";
|
||||
const manualRegionReferenceImageUrls = regions.flatMap((region) =>
|
||||
region.referenceImages.map((reference) => reference.url)
|
||||
);
|
||||
@ -4242,6 +4301,7 @@ export async function POST(request: NextRequest) {
|
||||
useScaleAdjustCoordinateGuide &&
|
||||
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image",
|
||||
falScaleAdjustSafePromptApplied: useFalScaleAdjustCoordinatePrompt,
|
||||
falScaleAdjustPatchSafePromptApplied: useFalScaleAdjustPatchPrompt,
|
||||
scaleAdjustProviderFallbackPolicy: isScaleAdjustOperation
|
||||
? "disabled-one-shot-single-model"
|
||||
: undefined,
|
||||
@ -4300,7 +4360,9 @@ export async function POST(request: NextRequest) {
|
||||
negativePrompt:
|
||||
isScaleAdjustOperation
|
||||
? scaleAdjustPatchReference
|
||||
? scaleAdjustPatchNegativePrompt
|
||||
? useFalScaleAdjustPatchPrompt
|
||||
? scaleAdjustFalPatchNegativePrompt
|
||||
: scaleAdjustPatchNegativePrompt
|
||||
: useProviderTextOnlyCoordinatePrompt
|
||||
? scaleAdjustTextOnlyNegativePrompt
|
||||
: useScaleAdjustCoordinatePrompt
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user