|
|
import type { GradioClient } from '$lib/types'; |
|
|
|
|
|
export interface EnhancedCaptionResult { |
|
|
caption: string; |
|
|
} |
|
|
|
|
|
export class EnhancedCaptionService { |
|
|
|
|
|
|
|
|
|
|
|
static async generateEnhancedCaption( |
|
|
client: GradioClient, |
|
|
image: Blob | File |
|
|
): Promise<EnhancedCaptionResult> { |
|
|
try { |
|
|
const result = await client.predict("/stream_chat", [ |
|
|
image, |
|
|
"Descriptive", |
|
|
"medium-length", |
|
|
[], |
|
|
"", |
|
|
"Describe this image in detail, identifying any recognizable objects, brands, logos, or specific models. Be specific about product names and types." |
|
|
]); |
|
|
|
|
|
const caption = result.data[1] as string; |
|
|
|
|
|
return { |
|
|
caption |
|
|
}; |
|
|
} catch (error) { |
|
|
console.error('Caption generation failed:', error); |
|
|
throw error; |
|
|
} |
|
|
} |
|
|
} |