init
This commit is contained in:
75
reelforge/services/image.py
Normal file
75
reelforge/services/image.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""
|
||||
Image Generation Service
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from reelforge.services.base import BaseService
|
||||
|
||||
|
||||
class ImageService(BaseService):
|
||||
"""
|
||||
Image generation service
|
||||
|
||||
Provides unified access to various image generation providers (ComfyKit, etc.)
|
||||
Returns path or URL to generated image.
|
||||
|
||||
Usage:
|
||||
# Direct call with workflow path
|
||||
image_path = await reelforge.image(
|
||||
workflow="workflows/book_cover.json",
|
||||
title="Atomic Habits",
|
||||
author="James Clear"
|
||||
)
|
||||
# Returns: "http://comfyui.local/view?filename=..."
|
||||
|
||||
# Or use workflow ID (if using RunningHub)
|
||||
image_path = await reelforge.image(
|
||||
workflow="12345",
|
||||
prompt="a beautiful landscape"
|
||||
)
|
||||
|
||||
# Check active image generator
|
||||
print(f"Using: {reelforge.image.active}")
|
||||
"""
|
||||
|
||||
def __init__(self, router):
|
||||
super().__init__(router, "image")
|
||||
|
||||
async def __call__(
|
||||
self,
|
||||
workflow: str,
|
||||
**params
|
||||
) -> str:
|
||||
"""
|
||||
Generate image using workflow
|
||||
|
||||
Args:
|
||||
workflow: Workflow path, ID, or URL
|
||||
**params: Workflow parameters (e.g., prompt, title, author, etc.)
|
||||
|
||||
Returns:
|
||||
Image URL or path (str)
|
||||
|
||||
Example:
|
||||
# Generate book cover
|
||||
image_url = await reelforge.image(
|
||||
workflow="workflows/book_cover.json",
|
||||
title="Atomic Habits",
|
||||
author="James Clear",
|
||||
genre="Self-Help"
|
||||
)
|
||||
|
||||
# Generate from text prompt
|
||||
image_url = await reelforge.image(
|
||||
workflow="workflows/text2img.json",
|
||||
prompt="a cute cat playing with yarn",
|
||||
width=1024,
|
||||
height=768
|
||||
)
|
||||
"""
|
||||
call_params = {"workflow": workflow}
|
||||
call_params.update(params)
|
||||
|
||||
return await self._config_manager.call(self._capability_type, **call_params)
|
||||
|
||||
Reference in New Issue
Block a user