Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:869413421 Ai moive studio ImageService generate images

From Leeroopedia
Knowledge Sources
Domains Vision, Generative_AI
Last Updated 2026-10-23 12:00 GMT

Overview

Service that batch-generates illustration images for sentences using a multi-provider gateway, with concurrent processing and retry with backoff.

Description

ImageService.generate_images loads sentences by ID, creates a GatewayProvider from the user's API key with high concurrency (20), and concurrently processes each sentence by calling GatewayProvider.generate_image with the sentence's image_prompt. Generated images are extracted from the response and uploaded to MinIO storage, and each sentence's image_url is updated.

The per-sentence worker (process_sentence) uses retry_with_backoff for transient failures and updates the sentence status to GENERATED_IMAGE.

Usage

Import when generating illustration images for narrative sentences. Called by the content generation Celery task after prompt generation.

Code Reference

Source Location

Signature

class ImageService(BaseService):
    async def generate_images(
        self,
        api_key_id: str,
        sentence_ids: List[str],
        model: str = None
    ) -> dict:
        """
        Args:
            api_key_id: API key UUID
            sentence_ids: sentence UUIDs to generate images for
            model: image model name (e.g., 'gemini-3-pro-image-preview')

        Returns:
            Dict with total, success, failed
        """

Import

from src.services.image import ImageService

I/O Contract

Inputs

Name Type Required Description
api_key_id str Yes API key UUID
sentence_ids List[str] Yes Sentence UUIDs to process
model str No Image model name

Outputs

Name Type Description
return value dict {total, success, failed}
DB side effects — Updates Sentence.image_url with MinIO key; sets status to GENERATED_IMAGE

Usage Examples

Batch Image Generation

from src.services.image import ImageService

service = ImageService(db_session)
result = await service.generate_images(
    api_key_id="key-uuid",
    sentence_ids=["sent-1", "sent-2", "sent-3"],
    model="gemini-3-pro-image-preview",
)
print(f"Images generated: {result['success']}/{result['total']}")

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment