Implementation:869413421 Ai moive studio ImageService generate images
| 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
- Repository: ai-moive-studio
- File: backend/src/services/image.py:L98-164
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']}")