fix: use fal-safe scale adjust prompt
This commit is contained in:
parent
f5a318beef
commit
291597a69f
@ -1507,7 +1507,8 @@ function buildScaleAdjustCoordinatePrompt(
|
||||
regions: NormalizedLocalEditRegion[],
|
||||
scalePercent: ScaleAdjustPercent | null | undefined,
|
||||
sourceSize: { width: number; height: number },
|
||||
cropReferences: ScaleAdjustCropReference[] = []
|
||||
cropReferences: ScaleAdjustCropReference[] = [],
|
||||
options: { falSafe?: boolean } = {}
|
||||
) {
|
||||
const regionLines = regions
|
||||
.map((region) => {
|
||||
@ -1542,8 +1543,25 @@ function buildScaleAdjustCoordinatePrompt(
|
||||
|
||||
const cropNote =
|
||||
cropIndex >= 0
|
||||
? ` Input image ${cropIndex + 3} is a clean crop reference for this same furniture identity and silhouette; use it only to recognize the subject, never paste it, and do not preserve its old size.`
|
||||
? options.falSafe
|
||||
? ` Input image ${cropIndex + 3} is an extra identity and silhouette reference.`
|
||||
: ` Input image ${cropIndex + 3} is a clean crop reference for this same furniture identity and silhouette; use it only to recognize the subject, never paste it, and do not preserve its old size.`
|
||||
: "";
|
||||
if (options.falSafe) {
|
||||
const actionPhrase =
|
||||
isShrink
|
||||
? "resize the furniture proportionally smaller and place it inside the final footprint"
|
||||
: isEnlarge
|
||||
? "resize the same furniture proportionally larger toward the final footprint"
|
||||
: "place the same furniture subject on the final footprint";
|
||||
const blendPhrase =
|
||||
isShrink
|
||||
? "Blend the newly visible floor, rug, wall, window area, shadow, and background around it naturally."
|
||||
: isEnlarge
|
||||
? "Blend edges, contact shadows, and occlusion with the surrounding room naturally."
|
||||
: "Keep the surrounding room stable.";
|
||||
return `Region ${region.index}: current furniture box in source photo left=${region.pixelRect.left}, top=${region.pixelRect.top}, right=${sourceRight}, bottom=${sourceBottom}, width=${region.pixelRect.width}, height=${region.pixelRect.height}; requested final footprint left=${targetPixelRect.left}, top=${targetPixelRect.top}, right=${targetRight}, bottom=${targetBottom}, width=${targetPixelRect.width}, height=${targetPixelRect.height}; scale factor width=${widthFactor.toFixed(2)}, height=${heightFactor.toFixed(2)}. Edit direction: ${actionPhrase}. ${blendPhrase}${cropNote}`;
|
||||
}
|
||||
return `Region ${region.index}: OLD search box in input 1 left=${region.pixelRect.left}, top=${region.pixelRect.top}, right=${sourceRight}, bottom=${sourceBottom}, width=${region.pixelRect.width}, height=${region.pixelRect.height}; TARGET final visual footprint left=${targetPixelRect.left}, top=${targetPixelRect.top}, right=${targetRight}, bottom=${targetBottom}, width=${targetPixelRect.width}, height=${targetPixelRect.height}; target scale is ${widthFactor.toFixed(2)}x width and ${heightFactor.toFixed(2)}x height. Main action: ${scaleDirection}. The final furniture silhouette must clearly leave the OLD footprint edges and align much closer to TARGET than OLD; returning an almost unchanged furniture footprint is not acceptable. ${footprintRule}${cropNote}`;
|
||||
})
|
||||
.join("\n");
|
||||
@ -1554,6 +1572,23 @@ function buildScaleAdjustCoordinatePrompt(
|
||||
)
|
||||
.join("\n");
|
||||
|
||||
if (options.falSafe) {
|
||||
return [
|
||||
"Interior furniture photo edit.",
|
||||
`Return one realistic photo with the same camera frame and pixel size as input image 1: ${sourceSize.width} x ${sourceSize.height} px.`,
|
||||
"Input image 1 is the source photo. Input image 2 is a coordinate guide only and should not appear in the final photo.",
|
||||
"The guide labels OLD as the current furniture box and TARGET as the requested final footprint.",
|
||||
"Resize only the furniture subject indicated by each current box. Keep the camera, room layout, walls, windows, floor, rug, sofa, lamp, text, and background stable.",
|
||||
"Preserve the furniture identity, material, perspective, objects on top, and natural aspect ratio.",
|
||||
"For a smaller final footprint, show the furniture smaller and blend newly visible floor, rug, wall, window area, shadow, and background around it naturally. For a larger final footprint, scale the same furniture proportionally with natural edges and contact shadows.",
|
||||
"Return a clean photo without guide marks, labels, boxes, arrows, overlays, patch edges, color mismatch, or full-frame zoom.",
|
||||
cropLines ? `${cropLines}` : "",
|
||||
"",
|
||||
"Region instructions:",
|
||||
regionLines,
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
return [
|
||||
"Local furniture scale edit. Use input image 1 as the clean original photo and the locked camera frame.",
|
||||
"One-shot cost constraint: produce the requested edit in this generation without relying on later retries or alternate candidates; an unchanged result is not acceptable.",
|
||||
@ -1759,6 +1794,9 @@ export async function POST(request: NextRequest) {
|
||||
const scaleAdjustModelFamily = getScaleAdjustModelFamily(
|
||||
resolvedScaleAdjustModelEntry
|
||||
);
|
||||
const useFalScaleAdjustCoordinatePrompt =
|
||||
useScaleAdjustCoordinateGuide &&
|
||||
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image";
|
||||
const annotatedBuffer = isScaleAdjustOperation
|
||||
? useScaleAdjustCoordinateGuide
|
||||
? await sharp(
|
||||
@ -1809,7 +1847,8 @@ export async function POST(request: NextRequest) {
|
||||
width: sourceWidth,
|
||||
height: sourceHeight,
|
||||
},
|
||||
scaleAdjustCropReferences
|
||||
scaleAdjustCropReferences,
|
||||
{ falSafe: useFalScaleAdjustCoordinatePrompt }
|
||||
)
|
||||
: buildScaleAdjustPrompt(
|
||||
regions,
|
||||
@ -1818,8 +1857,9 @@ export async function POST(request: NextRequest) {
|
||||
{ width: sourceWidth, height: sourceHeight }
|
||||
)
|
||||
: buildLocalEditPrompt(regions);
|
||||
const scaleAdjustCoordinateNegativePrompt =
|
||||
"visible annotation, guide overlay, translucent overlay, target placement overlay, faded wash, placeholder shadow, text label, arrows, boxes, rectangle border, UI marks, pasted patch, rough layout patch, hard crop edge, seam, hard rectangular edge, color mismatch, different-resolution area, whole image zoom, whole image crop, whole image pan, whole image redesign, unchanged target furniture, old-size target furniture, stretched furniture, squashed furniture, duplicate furniture, second copy, extra legs, extra rails, side panels, shelves, cabinets, lattice panels";
|
||||
const scaleAdjustCoordinateNegativePrompt = useFalScaleAdjustCoordinatePrompt
|
||||
? "guide marks, labels, boxes, arrows, overlays, patch edges, color mismatch, full-frame zoom, duplicate furniture, stretched furniture, distorted furniture"
|
||||
: "visible annotation, guide overlay, translucent overlay, target placement overlay, faded wash, placeholder shadow, text label, arrows, boxes, rectangle border, UI marks, pasted patch, rough layout patch, hard crop edge, seam, hard rectangular edge, color mismatch, different-resolution area, whole image zoom, whole image crop, whole image pan, whole image redesign, unchanged target furniture, old-size target furniture, stretched furniture, squashed furniture, duplicate furniture, second copy, extra legs, extra rails, side panels, shelves, cabinets, lattice panels";
|
||||
const manualRegionReferenceImageUrls = regions.flatMap((region) =>
|
||||
region.referenceImages.map((reference) => reference.url)
|
||||
);
|
||||
@ -1898,6 +1938,7 @@ export async function POST(request: NextRequest) {
|
||||
falScaleAdjustCoordinateGuideApplied:
|
||||
useScaleAdjustCoordinateGuide &&
|
||||
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image",
|
||||
falScaleAdjustSafePromptApplied: useFalScaleAdjustCoordinatePrompt,
|
||||
scaleAdjustProviderFallbackPolicy: isScaleAdjustOperation
|
||||
? "disabled-one-shot-single-model"
|
||||
: undefined,
|
||||
@ -1921,7 +1962,9 @@ export async function POST(request: NextRequest) {
|
||||
.length,
|
||||
scaleAdjustPromptStrategy: isScaleAdjustOperation
|
||||
? useScaleAdjustCoordinateGuide
|
||||
? "same-name-zoomed-coordinate-map-no-old-crop-v41-one-shot"
|
||||
? useFalScaleAdjustCoordinatePrompt
|
||||
? "fal-safe-zoomed-coordinate-map-no-old-crop-v42-one-shot"
|
||||
: "same-name-zoomed-coordinate-map-no-old-crop-v42-one-shot"
|
||||
: "locked-plate-semantic-target-map-no-old-crop-v15"
|
||||
: undefined,
|
||||
scaleAdjustPostCompositeApplied: false,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user