fix: use marked photo guide for scale adjust models

This commit is contained in:
134 2026-07-02 18:04:51 +08:00
parent ee403bff11
commit a8c5c14656

View File

@ -1371,7 +1371,7 @@ function buildScaleAdjustZoomedCoordinateSvg(params: {
`); `);
} }
function buildScaleAdjustFalPhotoGuideSvg(params: { function buildScaleAdjustMarkedPhotoGuideSvg(params: {
width: number; width: number;
height: number; height: number;
regions: NormalizedLocalEditRegion[]; regions: NormalizedLocalEditRegion[];
@ -1407,7 +1407,7 @@ function buildScaleAdjustFalPhotoGuideSvg(params: {
`); `);
} }
async function buildScaleAdjustFalPhotoGuideBuffer(params: { async function buildScaleAdjustMarkedPhotoGuideBuffer(params: {
sourceBuffer: Buffer; sourceBuffer: Buffer;
width: number; width: number;
height: number; height: number;
@ -1421,7 +1421,7 @@ async function buildScaleAdjustFalPhotoGuideBuffer(params: {
.modulate({ brightness: 1.04, saturation: 0.45 }) .modulate({ brightness: 1.04, saturation: 0.45 })
.composite([ .composite([
{ {
input: buildScaleAdjustFalPhotoGuideSvg({ input: buildScaleAdjustMarkedPhotoGuideSvg({
height, height,
regions, regions,
scalePercent, scalePercent,
@ -1572,7 +1572,7 @@ function buildScaleAdjustCoordinatePrompt(
scalePercent: ScaleAdjustPercent | null | undefined, scalePercent: ScaleAdjustPercent | null | undefined,
sourceSize: { width: number; height: number }, sourceSize: { width: number; height: number },
cropReferences: ScaleAdjustCropReference[] = [], cropReferences: ScaleAdjustCropReference[] = [],
options: { falSafe?: boolean } = {} options: { falSafe?: boolean; markedPhotoGuide?: boolean } = {}
) { ) {
const regionLines = regions const regionLines = regions
.map((region) => { .map((region) => {
@ -1653,13 +1653,17 @@ function buildScaleAdjustCoordinatePrompt(
].join("\n"); ].join("\n");
} }
const coordinateGuideLine = options.markedPhotoGuide
? "输入图片2是一张原图浅化后的完整画面位置参考图,不是输出底图。青色虚线框表示当前主体搜索框(对应下方 OLD),蓝色实线框表示目标最终占位(对应下方 TARGET)。请用输入图片2理解主体在真实室内画面中的位置关系,但最终图不能出现任何框线、色块、标注或参考图的浅化效果。"
: "Input image 2 is a zoomed neutral coordinate instruction map, not a photo and not output content. It enlarges the OLD and TARGET boxes so their relative scale is easy to read; use the numeric pixel coordinates below for the exact absolute position in input image 1. The OLD box/label locates the current furniture; the TARGET box/label gives the required final footprint, center, and scale factor. If the map says OLD OUTSIDE -> BG, rebuild the old full-size furniture area outside TARGET as natural background in the final photo. Read the boxes, labels, arrows, and scale text only as instructions; never output any map graphics.";
return [ return [
"Local furniture scale edit. Use input image 1 as the clean original photo and the locked camera frame.", "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.", "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.",
"中文硬约束:只调整 OLD 框中的主要家具主体。TARGET 框是最终占位;如果是缩小,OLD 框里超出 TARGET 的旧家具占位必须改为自然背景;如果是放大,同一件家具必须明显变大。禁止整图缩放、整图裁切、整图重绘。", "中文硬约束:只调整 OLD 框中的主要家具主体。TARGET 框是最终占位;如果是缩小,OLD 框里超出 TARGET 的旧家具占位必须改为自然背景;如果是放大,同一件家具必须明显变大。禁止整图缩放、整图裁切、整图重绘。",
"一次成功硬约束:不要保守返回原尺寸。目标家具的可见轮廓必须明显从 OLD 原始占位变到 TARGET 占位;不接受看起来和原图几乎相同的结果。", "一次成功硬约束:不要保守返回原尺寸。目标家具的可见轮廓必须明显从 OLD 原始占位变到 TARGET 占位;不接受看起来和原图几乎相同的结果。",
`Return one seamless realistic photo with the same frame and pixel size as input image 1: ${sourceSize.width} x ${sourceSize.height} px.`, `Return one seamless realistic photo with the same frame and pixel size as input image 1: ${sourceSize.width} x ${sourceSize.height} px.`,
"Input image 2 is a zoomed neutral coordinate instruction map, not a photo and not output content. It enlarges the OLD and TARGET boxes so their relative scale is easy to read; use the numeric pixel coordinates below for the exact absolute position in input image 1. The OLD box/label locates the current furniture; the TARGET box/label gives the required final footprint, center, and scale factor. If the map says OLD OUTSIDE -> BG, rebuild the old full-size furniture area outside TARGET as natural background in the final photo. Read the boxes, labels, arrows, and scale text only as instructions; never output any map graphics.", coordinateGuideLine,
cropLines ? `${cropLines}` : "", cropLines ? `${cropLines}` : "",
"", "",
"Task:", "Task:",
@ -1861,10 +1865,11 @@ export async function POST(request: NextRequest) {
const useFalScaleAdjustCoordinatePrompt = const useFalScaleAdjustCoordinatePrompt =
useScaleAdjustCoordinateGuide && useScaleAdjustCoordinateGuide &&
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image"; resolvedScaleAdjustModelEntry?.provider?.type === "fal-image";
const useScaleAdjustMarkedPhotoGuide = useScaleAdjustCoordinateGuide;
const annotatedBuffer = isScaleAdjustOperation const annotatedBuffer = isScaleAdjustOperation
? useScaleAdjustCoordinateGuide ? useScaleAdjustCoordinateGuide
? useFalScaleAdjustCoordinatePrompt ? useScaleAdjustMarkedPhotoGuide
? await buildScaleAdjustFalPhotoGuideBuffer({ ? await buildScaleAdjustMarkedPhotoGuideBuffer({
height: sourceHeight, height: sourceHeight,
regions, regions,
scalePercent, scalePercent,
@ -1920,7 +1925,10 @@ export async function POST(request: NextRequest) {
height: sourceHeight, height: sourceHeight,
}, },
scaleAdjustCropReferences, scaleAdjustCropReferences,
{ falSafe: useFalScaleAdjustCoordinatePrompt } {
falSafe: useFalScaleAdjustCoordinatePrompt,
markedPhotoGuide: useScaleAdjustMarkedPhotoGuide,
}
) )
: buildScaleAdjustPrompt( : buildScaleAdjustPrompt(
regions, regions,
@ -1987,8 +1995,8 @@ export async function POST(request: NextRequest) {
annotatedReferenceSentToModel: isScaleAdjustOperation, annotatedReferenceSentToModel: isScaleAdjustOperation,
annotatedReferenceType: isScaleAdjustOperation annotatedReferenceType: isScaleAdjustOperation
? useScaleAdjustCoordinateGuide ? useScaleAdjustCoordinateGuide
? useFalScaleAdjustCoordinatePrompt ? useScaleAdjustMarkedPhotoGuide
? "scale-adjust-fal-marked-photo-guide" ? "scale-adjust-marked-photo-guide"
: "scale-adjust-neutral-coordinate-map" : "scale-adjust-neutral-coordinate-map"
: "scale-adjust-full-frame-semantic-edit-map" : "scale-adjust-full-frame-semantic-edit-map"
: "source-overlay", : "source-overlay",
@ -2008,7 +2016,8 @@ export async function POST(request: NextRequest) {
scaleAdjustNeutralCoordinateMapApplied: scaleAdjustNeutralCoordinateMapApplied:
isScaleAdjustOperation && isScaleAdjustOperation &&
useScaleAdjustCoordinateGuide && useScaleAdjustCoordinateGuide &&
!useFalScaleAdjustCoordinatePrompt, !useScaleAdjustMarkedPhotoGuide,
scaleAdjustMarkedPhotoGuideApplied: useScaleAdjustMarkedPhotoGuide,
scaleAdjustFalMarkedPhotoGuideApplied: useFalScaleAdjustCoordinatePrompt, scaleAdjustFalMarkedPhotoGuideApplied: useFalScaleAdjustCoordinatePrompt,
scaleAdjustVisualLayoutGuideApplied: scaleAdjustVisualLayoutGuideApplied:
isScaleAdjustOperation && !useScaleAdjustCoordinateGuide, isScaleAdjustOperation && !useScaleAdjustCoordinateGuide,
@ -2041,7 +2050,7 @@ export async function POST(request: NextRequest) {
? useScaleAdjustCoordinateGuide ? useScaleAdjustCoordinateGuide
? useFalScaleAdjustCoordinatePrompt ? useFalScaleAdjustCoordinatePrompt
? "fal-safe-marked-photo-box-guide-no-old-crop-v44-one-shot" ? "fal-safe-marked-photo-box-guide-no-old-crop-v44-one-shot"
: "same-name-zoomed-coordinate-map-no-old-crop-v42-one-shot" : "same-name-marked-photo-box-guide-no-old-crop-v45-one-shot"
: "locked-plate-semantic-target-map-no-old-crop-v15" : "locked-plate-semantic-target-map-no-old-crop-v15"
: undefined, : undefined,
scaleAdjustPostCompositeApplied: false, scaleAdjustPostCompositeApplied: false,