From f521fe408730c7a5f48b51b402f907accb665873 Mon Sep 17 00:00:00 2001 From: zramsay Date: Fri, 20 Dec 2024 16:25:01 -0500 Subject: [PATCH] constants --- src/app/api/flux/route.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/api/flux/route.ts b/src/app/api/flux/route.ts index a7d737d..d4ab83b 100644 --- a/src/app/api/flux/route.ts +++ b/src/app/api/flux/route.ts @@ -10,6 +10,10 @@ fal.config({ credentials: process.env.FAL_AI_KEY }) +// Consistent image size for all generations +const IMAGE_WIDTH: number = 1024 +const IMAGE_HEIGHT: number = 1024 + export async function POST(req: NextRequest): Promise { try { const { prompt, modelId } = await req.json() @@ -27,6 +31,15 @@ export async function POST(req: NextRequest): Promise { const result = await fal.subscribe(modelId, { input: { prompt: prompt, + image_size: { + width: IMAGE_WIDTH, + height: IMAGE_HEIGHT + }, + // Additional parameters for consistent output + num_images: 1, + scheduler: "DDIM", + num_inference_steps: 50, + guidance_scale: 7.5 }, logs: true, onQueueUpdate: (update) => { @@ -38,11 +51,15 @@ export async function POST(req: NextRequest): Promise { console.log('Flux generation result:', result) - if (!result.data?.images?.[0]?.url) { + // Extract the image URL from the response + const imageUrl = result.data?.images?.[0]?.url + + if (!imageUrl) { + console.error('No image URL in response:', result) throw new Error('No image URL in response') } - return NextResponse.json({ imageUrl: result.data.images[0].url }) + return NextResponse.json({ imageUrl }) } catch (error) { console.error('Flux generation error:', error) return NextResponse.json(