Improve docstrings for services and processors (#2087)
This commit is contained in:
@@ -4,6 +4,12 @@
|
||||
# SPDX-License-Identifier: BSD 2-Clause License
|
||||
#
|
||||
|
||||
"""Fal's image generation service implementation.
|
||||
|
||||
This module provides integration with Fal's image generation API
|
||||
for creating images from text prompts using various AI models.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import io
|
||||
import os
|
||||
@@ -26,7 +32,25 @@ except ModuleNotFoundError as e:
|
||||
|
||||
|
||||
class FalImageGenService(ImageGenService):
|
||||
"""Fal's image generation service.
|
||||
|
||||
Provides text-to-image generation using Fal.ai's API with configurable
|
||||
parameters for image quality, safety, and format options.
|
||||
"""
|
||||
|
||||
class InputParams(BaseModel):
|
||||
"""Input parameters for Fal.ai image generation.
|
||||
|
||||
Parameters:
|
||||
seed: Random seed for reproducible generation. If None, uses random seed.
|
||||
num_inference_steps: Number of inference steps for generation. Defaults to 8.
|
||||
num_images: Number of images to generate. Defaults to 1.
|
||||
image_size: Image dimensions as string preset or dict with width/height. Defaults to "square_hd".
|
||||
expand_prompt: Whether to automatically expand/enhance the prompt. Defaults to False.
|
||||
enable_safety_checker: Whether to enable content safety filtering. Defaults to True.
|
||||
format: Output image format. Defaults to "png".
|
||||
"""
|
||||
|
||||
seed: Optional[int] = None
|
||||
num_inference_steps: int = 8
|
||||
num_images: int = 1
|
||||
@@ -44,6 +68,15 @@ class FalImageGenService(ImageGenService):
|
||||
key: Optional[str] = None,
|
||||
**kwargs,
|
||||
):
|
||||
"""Initialize the FalImageGenService.
|
||||
|
||||
Args:
|
||||
params: Input parameters for image generation configuration.
|
||||
aiohttp_session: HTTP client session for downloading generated images.
|
||||
model: The Fal.ai model to use for generation. Defaults to "fal-ai/fast-sdxl".
|
||||
key: Optional API key for Fal.ai. If provided, sets FAL_KEY environment variable.
|
||||
**kwargs: Additional arguments passed to parent ImageGenService.
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
self.set_model_name(model)
|
||||
self._params = params
|
||||
@@ -52,6 +85,16 @@ class FalImageGenService(ImageGenService):
|
||||
os.environ["FAL_KEY"] = key
|
||||
|
||||
async def run_image_gen(self, prompt: str) -> AsyncGenerator[Frame, None]:
|
||||
"""Generate an image from a text prompt.
|
||||
|
||||
Args:
|
||||
prompt: The text prompt to generate an image from.
|
||||
|
||||
Yields:
|
||||
URLImageRawFrame: Frame containing the generated image data and metadata.
|
||||
ErrorFrame: If image generation fails.
|
||||
"""
|
||||
|
||||
def load_image_bytes(encoded_image: bytes):
|
||||
buffer = io.BytesIO(encoded_image)
|
||||
image = Image.open(buffer)
|
||||
|
||||
Reference in New Issue
Block a user