Spaces:
Sleeping
Sleeping
| import { z } from 'zod'; | |
| export type UploadedImage = { | |
| originalName: string; | |
| mimeType: string; | |
| size: number; | |
| buffer?: Buffer; | |
| }; | |
| export type GenerationVariant = { | |
| id: string; | |
| label: string; | |
| status: 'queued' | 'completed'; | |
| prompt: string; | |
| providerPromptId?: string; | |
| imageUrl?: string; | |
| imageBase64?: string; | |
| }; | |
| export type GenerationImage = { | |
| id: string; | |
| originalName: string; | |
| variants: GenerationVariant[]; | |
| }; | |
| export type GenerationProvider = 'mock' | 'kaggle'; | |
| export type GenerationResponse = { | |
| jobId: string; | |
| provider: GenerationProvider; | |
| preset: string; | |
| ratio: string; | |
| images: GenerationImage[]; | |
| metrics?: GenerationMetrics; | |
| }; | |
| export type GenerationMetrics = { | |
| durationSeconds?: number; | |
| inferenceSeconds?: number; | |
| modelLoadSeconds?: number; | |
| setupSeconds?: number; | |
| height?: number; | |
| width?: number; | |
| steps?: number; | |
| smallDecoder?: boolean; | |
| cudaAvailable?: boolean; | |
| gpuName?: string; | |
| hfHome?: string; | |
| mode?: GenerationMode; | |
| modelId?: string; | |
| }; | |
| export type GenerationMode = 'product' | 'menu'; | |
| export const generationRequestSchema = z.object({ | |
| prompt: z.string().trim().min(1), | |
| preset: z.enum(['studio', 'food', 'retail', 'premium']), | |
| ratio: z.enum(['16:9', '9:16', '1:1']), | |
| mode: z.enum(['product', 'menu']).default('product'), | |
| }); | |
| export function buildGenerationResponse(input: z.infer<typeof generationRequestSchema>, images: UploadedImage[], provider: GenerationProvider = 'mock'): GenerationResponse { | |
| const responseImages = input.mode === 'menu' ? images.slice(0, 1) : images; | |
| return { | |
| jobId: crypto.randomUUID(), | |
| provider, | |
| preset: input.preset, | |
| ratio: input.ratio, | |
| images: responseImages.map((image) => ({ | |
| id: crypto.randomUUID(), | |
| originalName: image.originalName, | |
| variants: buildVariants(input.prompt), | |
| })), | |
| }; | |
| } | |
| function buildVariants(prompt: string): GenerationVariant[] { | |
| return [ | |
| { | |
| id: crypto.randomUUID(), | |
| label: 'Clean studio', | |
| status: 'queued', | |
| prompt: `${prompt}. Clean studio background, realistic product shadow.`, | |
| }, | |
| { | |
| id: crypto.randomUUID(), | |
| label: 'Warme food sfeer', | |
| status: 'queued', | |
| prompt: `${prompt}. Warm hospitality setting, photorealistic lighting.`, | |
| }, | |
| { | |
| id: crypto.randomUUID(), | |
| label: 'Premium donker', | |
| status: 'queued', | |
| prompt: `${prompt}. Dark premium campaign scene, controlled highlights.`, | |
| }, | |
| ]; | |
| } | |