fix: use text coordinate guide for alibaba scale adjust
This commit is contained in:
parent
56240d4a6d
commit
11e6aca724
@ -1867,6 +1867,61 @@ function buildScaleAdjustCoordinateSystemPrompt() {
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
function buildScaleAdjustTextOnlyPrompt(
|
||||
regions: NormalizedLocalEditRegion[],
|
||||
scalePercent: ScaleAdjustPercent | null | undefined,
|
||||
cropReferences: ScaleAdjustCropReference[] = [],
|
||||
sourceSize: { width: number; height: number }
|
||||
) {
|
||||
const cropLines = cropReferences
|
||||
.map(
|
||||
(reference, index) =>
|
||||
`Input image ${index + 2}: clean crop reference for Region ${reference.regionIndex}; use it only to identify the furniture subject and its natural aspect ratio, never paste the crop into the output.`
|
||||
)
|
||||
.join("\n");
|
||||
const regionLines = regions
|
||||
.map((region) => {
|
||||
const cropIndex = cropReferences.findIndex(
|
||||
(reference) => reference.regionIndex === region.index
|
||||
);
|
||||
const targetRect = getScaleAdjustTargetRect(region, scalePercent);
|
||||
const targetPixelRect =
|
||||
region.targetPixelRect ||
|
||||
rectToPixels(targetRect, sourceSize.width, sourceSize.height);
|
||||
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 sourceRight = region.pixelRect.left + region.pixelRect.width;
|
||||
const sourceBottom = region.pixelRect.top + region.pixelRect.height;
|
||||
const targetRight = targetPixelRect.left + targetPixelRect.width;
|
||||
const targetBottom = targetPixelRect.top + targetPixelRect.height;
|
||||
const cropNote =
|
||||
cropIndex >= 0
|
||||
? ` Input image ${cropIndex + 2} is the clean crop reference for this furniture identity and silhouette.`
|
||||
: "";
|
||||
return `Region ${region.index}: source search box left=${region.pixelRect.left}, top=${region.pixelRect.top}, right=${sourceRight}, bottom=${sourceBottom}, width=${region.pixelRect.width}, height=${region.pixelRect.height}; target final footprint left=${targetPixelRect.left}, top=${targetPixelRect.top}, right=${targetRight}, bottom=${targetBottom}, width=${targetPixelRect.width}, height=${targetPixelRect.height}; target scale width=${widthFactor.toFixed(2)}, height=${heightFactor.toFixed(2)}. User request: ${region.prompt || "scale the furniture to the target footprint"}.${cropNote}`;
|
||||
})
|
||||
.join("\n");
|
||||
|
||||
return [
|
||||
"Local furniture scale edit. Input image 1 is the locked source photo and the only final canvas base.",
|
||||
`Return one clean realistic photo with exactly the same camera frame and pixel size as input image 1: ${sourceSize.width} x ${sourceSize.height} px.`,
|
||||
cropLines ? cropLines : "",
|
||||
"Do not output any guide marks, boxes, labels, arrows, blue lines, cyan lines, overlays, UI marks, text annotations, patch edges, full-frame zoom, crop, pan, or redesigned room.",
|
||||
"Only edit the main movable furniture subject inside each source search box. Keep all other furniture, sofa, lamps, wall, windows, rug, floor, decor, text, lighting, and camera frame stable.",
|
||||
"Use the numeric pixel coordinates below as the only geometry guide. Do not need a visible guide image.",
|
||||
"When target footprint is smaller than source, make the same furniture visibly smaller and naturally rebuild the newly visible floor, rug, wall, shadow, or background around it. Do not leave the old full-size footprint.",
|
||||
"Keep the furniture identity, materials, perspective, objects on top, contact shadows, and natural aspect ratio. Do not stretch, squash, duplicate, or paste a rectangular crop.",
|
||||
"中文硬约束:输入图1是锁定底图,只能调整源框里的主要家具主体;目标框是最终家具可见占位。禁止整图重绘、整图缩放、输出标注框、输出蓝线或把裁切图贴回。",
|
||||
"",
|
||||
"Region instructions:",
|
||||
regionLines,
|
||||
"",
|
||||
"Success check before returning: the selected furniture must be clearly closer to the target footprint than to the original source footprint, while the rest of the photo remains visually unchanged and clean.",
|
||||
].filter(Boolean).join("\n");
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const session = await auth();
|
||||
@ -2030,20 +2085,21 @@ export async function POST(request: NextRequest) {
|
||||
const scaleAdjustModelFamily = getScaleAdjustModelFamily(
|
||||
resolvedScaleAdjustModelEntry
|
||||
);
|
||||
const useProviderMarkedPhotoCoordinatePrompt =
|
||||
const useProviderTextOnlyCoordinatePrompt =
|
||||
isScaleAdjustOperation &&
|
||||
resolvedScaleAdjustModelEntry?.provider?.type === "alibaba-image";
|
||||
const useScaleAdjustCoordinatePrompt =
|
||||
useScaleAdjustCoordinateGuide || useProviderMarkedPhotoCoordinatePrompt;
|
||||
const useScaleAdjustCoordinatePrompt = useScaleAdjustCoordinateGuide;
|
||||
const useFalScaleAdjustCoordinatePrompt =
|
||||
useScaleAdjustCoordinatePrompt &&
|
||||
resolvedScaleAdjustModelEntry?.provider?.type === "fal-image";
|
||||
const useScaleAdjustVisualLayoutGuide =
|
||||
useScaleAdjustCoordinatePrompt &&
|
||||
!useFalScaleAdjustCoordinatePrompt &&
|
||||
!useProviderMarkedPhotoCoordinatePrompt;
|
||||
!useProviderTextOnlyCoordinatePrompt;
|
||||
const useScaleAdjustMarkedPhotoGuide =
|
||||
useScaleAdjustCoordinatePrompt && !useScaleAdjustVisualLayoutGuide;
|
||||
const sendScaleAdjustAnnotatedReferenceToModel =
|
||||
isScaleAdjustOperation && !useProviderTextOnlyCoordinatePrompt;
|
||||
const annotatedBuffer = isScaleAdjustOperation
|
||||
? useScaleAdjustCoordinatePrompt
|
||||
? useScaleAdjustVisualLayoutGuide
|
||||
@ -2122,6 +2178,7 @@ export async function POST(request: NextRequest) {
|
||||
isScaleAdjustOperation &&
|
||||
(useScaleAdjustVisualLayoutGuide ||
|
||||
!useScaleAdjustCoordinatePrompt ||
|
||||
useProviderTextOnlyCoordinatePrompt ||
|
||||
(useScaleAdjustMarkedPhotoGuide && !useFalScaleAdjustCoordinatePrompt));
|
||||
const scaleAdjustCropReferences: ScaleAdjustCropReference[] =
|
||||
shouldCreateScaleAdjustCropReferences
|
||||
@ -2133,7 +2190,14 @@ export async function POST(request: NextRequest) {
|
||||
})
|
||||
: [];
|
||||
const prompt = isScaleAdjustOperation
|
||||
? useScaleAdjustCoordinatePrompt
|
||||
? useProviderTextOnlyCoordinatePrompt
|
||||
? buildScaleAdjustTextOnlyPrompt(
|
||||
regions,
|
||||
scalePercent,
|
||||
scaleAdjustCropReferences,
|
||||
{ width: sourceWidth, height: sourceHeight }
|
||||
)
|
||||
: useScaleAdjustCoordinatePrompt
|
||||
? buildScaleAdjustCoordinatePrompt(
|
||||
regions,
|
||||
scalePercent,
|
||||
@ -2167,7 +2231,9 @@ export async function POST(request: NextRequest) {
|
||||
const referenceImages = isScaleAdjustOperation
|
||||
? [
|
||||
sourceImageUrl,
|
||||
annotatedUpload.url,
|
||||
...(sendScaleAdjustAnnotatedReferenceToModel
|
||||
? [annotatedUpload.url]
|
||||
: []),
|
||||
...scaleAdjustCropReferenceImageUrls,
|
||||
...manualRegionReferenceImageUrls,
|
||||
]
|
||||
@ -2209,9 +2275,11 @@ export async function POST(request: NextRequest) {
|
||||
operation === SCALE_ADJUST_OPERATION ? "canvas-scale-adjust" : "canvas-local-edit",
|
||||
debugMeta: {
|
||||
annotatedReferenceUrl: annotatedUpload.url,
|
||||
annotatedReferenceSentToModel: isScaleAdjustOperation,
|
||||
annotatedReferenceSentToModel: sendScaleAdjustAnnotatedReferenceToModel,
|
||||
annotatedReferenceType: isScaleAdjustOperation
|
||||
? useScaleAdjustCoordinatePrompt
|
||||
? useProviderTextOnlyCoordinatePrompt
|
||||
? "scale-adjust-text-coordinate-only-debug-map"
|
||||
: useScaleAdjustCoordinatePrompt
|
||||
? useScaleAdjustVisualLayoutGuide
|
||||
? "scale-adjust-visual-layout-guide"
|
||||
: useScaleAdjustMarkedPhotoGuide
|
||||
@ -2238,7 +2306,10 @@ export async function POST(request: NextRequest) {
|
||||
resolvedScaleAdjustModelEntry?.provider?.type || null,
|
||||
scaleAdjustModelFamily: scaleAdjustModelFamily || null,
|
||||
scaleAdjustCoordinateGuideApplied: useScaleAdjustCoordinateGuide,
|
||||
scaleAdjustCoordinatePromptApplied: useScaleAdjustCoordinatePrompt,
|
||||
scaleAdjustCoordinatePromptApplied:
|
||||
useScaleAdjustCoordinatePrompt || useProviderTextOnlyCoordinatePrompt,
|
||||
scaleAdjustTextOnlyCoordinatePromptApplied:
|
||||
useProviderTextOnlyCoordinatePrompt,
|
||||
scaleAdjustNeutralCoordinateMapApplied:
|
||||
isScaleAdjustOperation &&
|
||||
useScaleAdjustCoordinatePrompt &&
|
||||
@ -2248,6 +2319,7 @@ export async function POST(request: NextRequest) {
|
||||
scaleAdjustFalMarkedPhotoGuideApplied: useFalScaleAdjustCoordinatePrompt,
|
||||
scaleAdjustVisualLayoutGuideApplied:
|
||||
isScaleAdjustOperation &&
|
||||
!useProviderTextOnlyCoordinatePrompt &&
|
||||
(!useScaleAdjustCoordinatePrompt || useScaleAdjustVisualLayoutGuide),
|
||||
falScaleAdjustCoordinateGuideApplied:
|
||||
useScaleAdjustCoordinateGuide &&
|
||||
@ -2279,8 +2351,8 @@ export async function POST(request: NextRequest) {
|
||||
? "fal-safe-marked-photo-box-guide-no-old-crop-v44-one-shot"
|
||||
: useScaleAdjustVisualLayoutGuide
|
||||
? "same-name-focused-layout-crop-guide-v54-one-shot"
|
||||
: useProviderMarkedPhotoCoordinatePrompt
|
||||
? "provider-marked-photo-crop-guide-v60-one-shot"
|
||||
: useProviderTextOnlyCoordinatePrompt
|
||||
? "provider-text-coordinate-crop-v61-one-shot"
|
||||
: useScaleAdjustMarkedPhotoGuide
|
||||
? "same-name-marked-photo-box-guide-no-old-crop-v45-one-shot"
|
||||
: "locked-plate-semantic-target-map-no-old-crop-v15"
|
||||
@ -2306,7 +2378,7 @@ export async function POST(request: NextRequest) {
|
||||
model: resolvedModel || undefined,
|
||||
negativePrompt:
|
||||
isScaleAdjustOperation
|
||||
? useScaleAdjustCoordinatePrompt
|
||||
? useScaleAdjustCoordinatePrompt || useProviderTextOnlyCoordinatePrompt
|
||||
? scaleAdjustCoordinateNegativePrompt
|
||||
: "彩色框、蓝色边框、绿色边框、红色边框、橙色边框、矩形框、箭头、连线、角点、编号圆点、提示词气泡、标注文字、UI 控件、半透明色块、蓝色色块、色条、灰底坐标图、目标占位叠图、淡化痕迹、选区边框、白边、画幅压扁、画面拉伸、整张图缩放、全图放大、全图裁切、全图平移、文字位置变化、文字内容变化、文字模糊、Logo位置变化、主体拉伸、主体压扁、主体变窄、主体变高但变窄、横向挤压、纵向拉伸、透视变形、矩形贴片、硬边、拼接线、补丁感、局部裁切、色差边缘、背景断裂、背景错位、窗框错位、文字错位、地毯纹理错位、非主体背景重绘、主体未缩放、整块框选区域缩放"
|
||||
: "彩色框、蓝色边框、绿色边框、红色边框、橙色边框、矩形框、编号圆点、提示词气泡、标注文字、UI 控件、半透明色块、选区边框、白边、画幅压扁、画面拉伸、主体截断、动物截断、缺头、缺尾巴、缺四肢、贴边裁切、矩形贴片、硬边、拼接线、补丁感、色差边缘、背景错位、地面纹理断裂、椅脚错位",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user