@weirdfingers/baseboards 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/index.js +54 -28
  2. package/dist/index.js.map +1 -1
  3. package/package.json +1 -1
  4. package/templates/README.md +2 -0
  5. package/templates/api/.env.example +3 -0
  6. package/templates/api/config/generators.yaml +58 -0
  7. package/templates/api/pyproject.toml +1 -1
  8. package/templates/api/src/boards/__init__.py +1 -1
  9. package/templates/api/src/boards/api/endpoints/storage.py +85 -4
  10. package/templates/api/src/boards/api/endpoints/uploads.py +1 -2
  11. package/templates/api/src/boards/database/connection.py +98 -58
  12. package/templates/api/src/boards/generators/implementations/fal/audio/__init__.py +4 -0
  13. package/templates/api/src/boards/generators/implementations/fal/audio/chatterbox_text_to_speech.py +176 -0
  14. package/templates/api/src/boards/generators/implementations/fal/audio/chatterbox_tts_turbo.py +195 -0
  15. package/templates/api/src/boards/generators/implementations/fal/image/__init__.py +14 -0
  16. package/templates/api/src/boards/generators/implementations/fal/image/bytedance_seedream_v45_edit.py +219 -0
  17. package/templates/api/src/boards/generators/implementations/fal/image/gemini_25_flash_image_edit.py +208 -0
  18. package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_15_edit.py +216 -0
  19. package/templates/api/src/boards/generators/implementations/fal/image/gpt_image_1_5.py +177 -0
  20. package/templates/api/src/boards/generators/implementations/fal/image/reve_edit.py +178 -0
  21. package/templates/api/src/boards/generators/implementations/fal/image/reve_text_to_image.py +155 -0
  22. package/templates/api/src/boards/generators/implementations/fal/image/seedream_v45_text_to_image.py +180 -0
  23. package/templates/api/src/boards/generators/implementations/fal/video/__init__.py +18 -0
  24. package/templates/api/src/boards/generators/implementations/fal/video/kling_video_ai_avatar_v2_pro.py +168 -0
  25. package/templates/api/src/boards/generators/implementations/fal/video/kling_video_ai_avatar_v2_standard.py +159 -0
  26. package/templates/api/src/boards/generators/implementations/fal/video/veed_fabric_1_0.py +180 -0
  27. package/templates/api/src/boards/generators/implementations/fal/video/veo31.py +190 -0
  28. package/templates/api/src/boards/generators/implementations/fal/video/veo31_fast.py +190 -0
  29. package/templates/api/src/boards/generators/implementations/fal/video/veo31_fast_image_to_video.py +191 -0
  30. package/templates/api/src/boards/generators/implementations/fal/video/veo31_first_last_frame_to_video.py +13 -6
  31. package/templates/api/src/boards/generators/implementations/fal/video/wan_25_preview_image_to_video.py +212 -0
  32. package/templates/api/src/boards/generators/implementations/fal/video/wan_25_preview_text_to_video.py +208 -0
  33. package/templates/api/src/boards/generators/implementations/kie/__init__.py +11 -0
  34. package/templates/api/src/boards/generators/implementations/kie/base.py +316 -0
  35. package/templates/api/src/boards/generators/implementations/kie/image/__init__.py +3 -0
  36. package/templates/api/src/boards/generators/implementations/kie/image/nano_banana_edit.py +190 -0
  37. package/templates/api/src/boards/generators/implementations/kie/utils.py +98 -0
  38. package/templates/api/src/boards/generators/implementations/kie/video/__init__.py +8 -0
  39. package/templates/api/src/boards/generators/implementations/kie/video/veo3.py +161 -0
  40. package/templates/api/src/boards/graphql/resolvers/upload.py +1 -1
  41. package/templates/web/package.json +4 -1
  42. package/templates/web/src/app/boards/[boardId]/page.tsx +156 -24
  43. package/templates/web/src/app/globals.css +3 -0
  44. package/templates/web/src/app/layout.tsx +15 -5
  45. package/templates/web/src/components/boards/ArtifactInputSlots.tsx +9 -9
  46. package/templates/web/src/components/boards/ArtifactPreview.tsx +34 -18
  47. package/templates/web/src/components/boards/GenerationGrid.tsx +101 -7
  48. package/templates/web/src/components/boards/GenerationInput.tsx +21 -21
  49. package/templates/web/src/components/boards/GeneratorSelector.tsx +232 -30
  50. package/templates/web/src/components/boards/UploadArtifact.tsx +385 -75
  51. package/templates/web/src/components/header.tsx +3 -1
  52. package/templates/web/src/components/theme-provider.tsx +10 -0
  53. package/templates/web/src/components/theme-toggle.tsx +75 -0
  54. package/templates/web/src/components/ui/alert-dialog.tsx +157 -0
  55. package/templates/web/src/components/ui/toast.tsx +128 -0
  56. package/templates/web/src/components/ui/toaster.tsx +35 -0
  57. package/templates/web/src/components/ui/use-toast.ts +186 -0
@@ -0,0 +1,195 @@
1
+ """
2
+ fal.ai Chatterbox Text-to-Speech Turbo generator.
3
+
4
+ Generate expressive speech from text with paralinguistic controls like laughs,
5
+ sighs, coughs, and more. Supports voice cloning with custom audio samples.
6
+
7
+ Based on Fal AI's fal-ai/chatterbox/text-to-speech/turbo model.
8
+ See: https://fal.ai/models/fal-ai/chatterbox/text-to-speech/turbo
9
+ """
10
+
11
+ import os
12
+ from typing import Literal
13
+
14
+ from pydantic import BaseModel, Field
15
+
16
+ from ....artifacts import AudioArtifact
17
+ from ....base import BaseGenerator, GeneratorExecutionContext, GeneratorResult
18
+
19
+ # Voice presets available in Chatterbox
20
+ ChatterboxVoice = Literal[
21
+ "aaron",
22
+ "abigail",
23
+ "anaya",
24
+ "andy",
25
+ "archer",
26
+ "brian",
27
+ "chloe",
28
+ "dylan",
29
+ "emmanuel",
30
+ "ethan",
31
+ "evelyn",
32
+ "gavin",
33
+ "gordon",
34
+ "ivan",
35
+ "laura",
36
+ "lucy",
37
+ "madison",
38
+ "marisol",
39
+ "meera",
40
+ "walter",
41
+ ]
42
+
43
+
44
+ class ChatterboxTtsTurboInput(BaseModel):
45
+ """Input schema for Chatterbox TTS Turbo.
46
+
47
+ Artifact fields are automatically detected via type introspection
48
+ and resolved from generation IDs to artifact objects.
49
+ """
50
+
51
+ text: str = Field(
52
+ description=(
53
+ "The text to be converted to speech. Supports paralinguistic tags: "
54
+ "[clear throat], [sigh], [shush], [cough], [groan], [sniff], [gasp], "
55
+ "[chuckle], [laugh]"
56
+ ),
57
+ min_length=1,
58
+ )
59
+ voice: ChatterboxVoice = Field(
60
+ default="lucy",
61
+ description="Preset voice to use for synthesis",
62
+ )
63
+ audio_url: AudioArtifact | None = Field(
64
+ default=None,
65
+ description=(
66
+ "Optional audio file (5-10 seconds) for voice cloning. "
67
+ "If provided, this overrides the preset voice selection."
68
+ ),
69
+ )
70
+ temperature: float = Field(
71
+ default=0.8,
72
+ ge=0.05,
73
+ le=2.0,
74
+ description="Temperature for generation. Higher values create more varied speech patterns.",
75
+ )
76
+ seed: int | None = Field(
77
+ default=None,
78
+ description="Random seed for reproducible results. Set for consistent generations.",
79
+ )
80
+
81
+
82
+ class FalChatterboxTtsTurboGenerator(BaseGenerator):
83
+ """Chatterbox TTS Turbo text-to-speech generator using fal.ai."""
84
+
85
+ name = "fal-chatterbox-tts-turbo"
86
+ artifact_type = "audio"
87
+ description = (
88
+ "Fal: Chatterbox TTS Turbo - "
89
+ "Expressive text-to-speech with paralinguistic controls and voice cloning"
90
+ )
91
+
92
+ def get_input_schema(self) -> type[ChatterboxTtsTurboInput]:
93
+ return ChatterboxTtsTurboInput
94
+
95
+ async def generate(
96
+ self, inputs: ChatterboxTtsTurboInput, context: GeneratorExecutionContext
97
+ ) -> GeneratorResult:
98
+ """Generate audio using fal.ai Chatterbox TTS Turbo model."""
99
+ # Check for API key (fal-client uses FAL_KEY environment variable)
100
+ if not os.getenv("FAL_KEY"):
101
+ raise ValueError("API configuration invalid. Missing FAL_KEY environment variable")
102
+
103
+ # Import fal_client
104
+ try:
105
+ import fal_client
106
+ except ImportError as e:
107
+ raise ImportError(
108
+ "fal.ai SDK is required for FalChatterboxTtsTurboGenerator. "
109
+ "Install with: pip install weirdfingers-boards[generators-fal]"
110
+ ) from e
111
+
112
+ # Prepare arguments for fal.ai API
113
+ arguments: dict[str, str | float | int] = {
114
+ "text": inputs.text,
115
+ "voice": inputs.voice,
116
+ "temperature": inputs.temperature,
117
+ }
118
+
119
+ # Add seed if provided
120
+ if inputs.seed is not None:
121
+ arguments["seed"] = inputs.seed
122
+
123
+ # Handle voice cloning audio upload
124
+ if inputs.audio_url is not None:
125
+ from ..utils import upload_artifacts_to_fal
126
+
127
+ audio_urls = await upload_artifacts_to_fal([inputs.audio_url], context)
128
+ arguments["audio_url"] = audio_urls[0]
129
+
130
+ # Submit async job and get handler
131
+ handler = await fal_client.submit_async(
132
+ "fal-ai/chatterbox/text-to-speech/turbo",
133
+ arguments=arguments,
134
+ )
135
+
136
+ # Store the external job ID for tracking
137
+ await context.set_external_job_id(handler.request_id)
138
+
139
+ # Stream progress updates (sample every 3rd event to avoid spam)
140
+ from .....progress.models import ProgressUpdate
141
+
142
+ event_count = 0
143
+ async for event in handler.iter_events(with_logs=True):
144
+ event_count += 1
145
+
146
+ # Process every 3rd event to provide feedback without overwhelming
147
+ if event_count % 3 == 0:
148
+ # Extract logs if available
149
+ logs = getattr(event, "logs", None)
150
+ if logs:
151
+ # Join log entries into a single message
152
+ if isinstance(logs, list):
153
+ message = " | ".join(str(log) for log in logs if log)
154
+ else:
155
+ message = str(logs)
156
+
157
+ if message:
158
+ await context.publish_progress(
159
+ ProgressUpdate(
160
+ job_id=handler.request_id,
161
+ status="processing",
162
+ progress=50.0, # Approximate mid-point progress
163
+ phase="processing",
164
+ message=message,
165
+ )
166
+ )
167
+
168
+ # Get final result
169
+ result = await handler.get()
170
+
171
+ # Extract audio URL from result
172
+ # fal.ai returns: {"audio": {"url": "..."}}
173
+ audio_data = result.get("audio")
174
+ if audio_data is None:
175
+ raise ValueError("No audio data returned from fal.ai API")
176
+
177
+ audio_url = audio_data.get("url")
178
+ if not audio_url:
179
+ raise ValueError("Audio URL missing in fal.ai response")
180
+
181
+ # Store audio result
182
+ artifact = await context.store_audio_result(
183
+ storage_url=audio_url,
184
+ format="wav", # Chatterbox TTS returns WAV format
185
+ output_index=0,
186
+ )
187
+
188
+ return GeneratorResult(outputs=[artifact])
189
+
190
+ async def estimate_cost(self, inputs: ChatterboxTtsTurboInput) -> float:
191
+ """Estimate cost for Chatterbox TTS Turbo generation.
192
+
193
+ Chatterbox TTS Turbo pricing is approximately $0.03 per generation.
194
+ """
195
+ return 0.03
@@ -1,5 +1,6 @@
1
1
  """Fal.ai image generators."""
2
2
 
3
+ from .bytedance_seedream_v45_edit import FalBytedanceSeedreamV45EditGenerator
3
4
  from .clarity_upscaler import FalClarityUpscalerGenerator
4
5
  from .crystal_upscaler import FalCrystalUpscalerGenerator
5
6
  from .fal_ideogram_character import FalIdeogramCharacterGenerator
@@ -10,8 +11,11 @@ from .flux_2_pro_edit import FalFlux2ProEditGenerator
10
11
  from .flux_pro_kontext import FalFluxProKontextGenerator
11
12
  from .flux_pro_ultra import FalFluxProUltraGenerator
12
13
  from .gemini_25_flash_image import FalGemini25FlashImageGenerator
14
+ from .gemini_25_flash_image_edit import FalGemini25FlashImageEditGenerator
15
+ from .gpt_image_1_5 import FalGptImage15Generator
13
16
  from .gpt_image_1_edit_image import FalGptImage1EditImageGenerator
14
17
  from .gpt_image_1_mini import FalGptImage1MiniGenerator
18
+ from .gpt_image_15_edit import FalGptImage15EditGenerator
15
19
  from .ideogram_character_edit import FalIdeogramCharacterEditGenerator
16
20
  from .ideogram_v2 import FalIdeogramV2Generator
17
21
  from .imagen4_preview import FalImagen4PreviewGenerator
@@ -22,8 +26,12 @@ from .nano_banana_pro import FalNanoBananaProGenerator
22
26
  from .nano_banana_pro_edit import FalNanoBananaProEditGenerator
23
27
  from .qwen_image import FalQwenImageGenerator
24
28
  from .qwen_image_edit import FalQwenImageEditGenerator
29
+ from .reve_edit import FalReveEditGenerator
30
+ from .reve_text_to_image import FalReveTextToImageGenerator
31
+ from .seedream_v45_text_to_image import FalSeedreamV45TextToImageGenerator
25
32
 
26
33
  __all__ = [
34
+ "FalBytedanceSeedreamV45EditGenerator",
27
35
  "FalClarityUpscalerGenerator",
28
36
  "FalCrystalUpscalerGenerator",
29
37
  "FalFlux2Generator",
@@ -32,7 +40,10 @@ __all__ = [
32
40
  "FalFlux2ProEditGenerator",
33
41
  "FalFluxProKontextGenerator",
34
42
  "FalFluxProUltraGenerator",
43
+ "FalGemini25FlashImageEditGenerator",
35
44
  "FalGemini25FlashImageGenerator",
45
+ "FalGptImage15EditGenerator",
46
+ "FalGptImage15Generator",
36
47
  "FalGptImage1EditImageGenerator",
37
48
  "FalGptImage1MiniGenerator",
38
49
  "FalIdeogramCharacterGenerator",
@@ -46,4 +57,7 @@ __all__ = [
46
57
  "FalNanoBananaProEditGenerator",
47
58
  "FalQwenImageEditGenerator",
48
59
  "FalQwenImageGenerator",
60
+ "FalReveEditGenerator",
61
+ "FalReveTextToImageGenerator",
62
+ "FalSeedreamV45TextToImageGenerator",
49
63
  ]
@@ -0,0 +1,219 @@
1
+ """
2
+ fal.ai ByteDance Seedream v4.5 Edit image editing generator.
3
+
4
+ Edit images using fal.ai's ByteDance Seedream v4.5 Edit model.
5
+ A new-generation image creation model that integrates image generation
6
+ and image editing capabilities into a single, unified architecture.
7
+ Supports editing up to 10 input images with a text prompt.
8
+
9
+ See: https://fal.ai/models/fal-ai/bytedance/seedream/v4.5/edit
10
+ """
11
+
12
+ import os
13
+ from typing import Literal
14
+
15
+ from pydantic import BaseModel, Field
16
+
17
+ from ....artifacts import ImageArtifact
18
+ from ....base import BaseGenerator, GeneratorExecutionContext, GeneratorResult
19
+
20
+ # Valid image size presets
21
+ ImageSizePreset = Literal[
22
+ "square_hd",
23
+ "square",
24
+ "portrait_4_3",
25
+ "portrait_16_9",
26
+ "landscape_4_3",
27
+ "landscape_16_9",
28
+ "auto_2K",
29
+ "auto_4K",
30
+ ]
31
+
32
+
33
+ class BytedanceSeedreamV45EditInput(BaseModel):
34
+ """Input schema for ByteDance Seedream v4.5 Edit.
35
+
36
+ Artifact fields (like image_sources) are automatically detected via type
37
+ introspection and resolved from generation IDs to ImageArtifact objects.
38
+ """
39
+
40
+ prompt: str = Field(description="The text prompt used to edit the image")
41
+ image_sources: list[ImageArtifact] = Field(
42
+ description="List of input images for editing (up to 10 images)",
43
+ min_length=1,
44
+ max_length=10,
45
+ )
46
+ num_images: int = Field(
47
+ default=1,
48
+ ge=1,
49
+ le=6,
50
+ description="Number of images to generate",
51
+ )
52
+ image_size: ImageSizePreset | None = Field(
53
+ default=None,
54
+ description=(
55
+ "The size of the generated image. Options: square_hd, square, "
56
+ "portrait_4_3, portrait_16_9, landscape_4_3, landscape_16_9, "
57
+ "auto_2K, auto_4K. Default is 2048x2048"
58
+ ),
59
+ )
60
+ seed: int | None = Field(
61
+ default=None,
62
+ description="Random seed to control the stochasticity of image generation",
63
+ )
64
+ sync_mode: bool = Field(
65
+ default=False,
66
+ description=(
67
+ "If True, the media will be returned as a data URI and the output "
68
+ "data won't be available in the request history"
69
+ ),
70
+ )
71
+ enable_safety_checker: bool = Field(
72
+ default=True,
73
+ description="Enables safety filtering on generated images",
74
+ )
75
+
76
+
77
+ class FalBytedanceSeedreamV45EditGenerator(BaseGenerator):
78
+ """ByteDance Seedream v4.5 Edit image editing generator using fal.ai."""
79
+
80
+ name = "fal-bytedance-seedream-v45-edit"
81
+ artifact_type = "image"
82
+ description = "Fal: ByteDance Seedream v4.5 Edit - Unified image generation and editing"
83
+
84
+ def get_input_schema(self) -> type[BytedanceSeedreamV45EditInput]:
85
+ return BytedanceSeedreamV45EditInput
86
+
87
+ async def generate(
88
+ self, inputs: BytedanceSeedreamV45EditInput, context: GeneratorExecutionContext
89
+ ) -> GeneratorResult:
90
+ """Edit images using fal.ai ByteDance Seedream v4.5 Edit model."""
91
+ # Check for API key (fal-client uses FAL_KEY environment variable)
92
+ if not os.getenv("FAL_KEY"):
93
+ raise ValueError("API configuration invalid. Missing FAL_KEY environment variable")
94
+
95
+ # Import fal_client
96
+ try:
97
+ import fal_client
98
+ except ImportError as e:
99
+ raise ImportError(
100
+ "fal.ai SDK is required for FalBytedanceSeedreamV45EditGenerator. "
101
+ "Install with: pip install weirdfingers-boards[generators-fal]"
102
+ ) from e
103
+
104
+ # Upload image artifacts to Fal's public storage
105
+ # Fal API requires publicly accessible URLs, but our storage_url might be:
106
+ # - Localhost URLs (not publicly accessible)
107
+ # - Private S3 buckets (not publicly accessible)
108
+ # So we upload to Fal's temporary storage first
109
+ from ..utils import upload_artifacts_to_fal
110
+
111
+ image_urls = await upload_artifacts_to_fal(inputs.image_sources, context)
112
+
113
+ # Prepare arguments for fal.ai API
114
+ arguments: dict = {
115
+ "prompt": inputs.prompt,
116
+ "image_urls": image_urls,
117
+ "num_images": inputs.num_images,
118
+ "sync_mode": inputs.sync_mode,
119
+ "enable_safety_checker": inputs.enable_safety_checker,
120
+ }
121
+
122
+ # Add optional parameters
123
+ if inputs.image_size is not None:
124
+ arguments["image_size"] = inputs.image_size
125
+
126
+ if inputs.seed is not None:
127
+ arguments["seed"] = inputs.seed
128
+
129
+ # Submit async job and get handler
130
+ handler = await fal_client.submit_async(
131
+ "fal-ai/bytedance/seedream/v4.5/edit",
132
+ arguments=arguments,
133
+ )
134
+
135
+ # Store the external job ID for tracking
136
+ await context.set_external_job_id(handler.request_id)
137
+
138
+ # Stream progress updates (sample every 3rd event to avoid spam)
139
+ from .....progress.models import ProgressUpdate
140
+
141
+ event_count = 0
142
+ async for event in handler.iter_events(with_logs=True):
143
+ event_count += 1
144
+
145
+ # Process every 3rd event to provide feedback without overwhelming
146
+ if event_count % 3 == 0:
147
+ # Extract logs if available
148
+ logs = getattr(event, "logs", None)
149
+ if logs:
150
+ # Join log entries into a single message
151
+ if isinstance(logs, list):
152
+ message = " | ".join(str(log) for log in logs if log)
153
+ else:
154
+ message = str(logs)
155
+
156
+ if message:
157
+ await context.publish_progress(
158
+ ProgressUpdate(
159
+ job_id=handler.request_id,
160
+ status="processing",
161
+ progress=50.0, # Approximate mid-point progress
162
+ phase="processing",
163
+ message=message,
164
+ )
165
+ )
166
+
167
+ # Get final result
168
+ result = await handler.get()
169
+
170
+ # Extract image URLs from result
171
+ # fal.ai returns: {
172
+ # "images": [{"url": "...", "width": ..., "height": ..., ...}, ...]
173
+ # }
174
+ images = result.get("images", [])
175
+
176
+ if not images:
177
+ raise ValueError("No images returned from fal.ai API")
178
+
179
+ # Store each image using output_index
180
+ artifacts = []
181
+ for idx, image_data in enumerate(images):
182
+ image_url = image_data.get("url")
183
+ # Extract dimensions if available, otherwise use sensible defaults
184
+ width = image_data.get("width", 2048)
185
+ height = image_data.get("height", 2048)
186
+
187
+ if not image_url:
188
+ raise ValueError(f"Image {idx} missing URL in fal.ai response")
189
+
190
+ # Determine format from content_type or default to png
191
+ content_type = image_data.get("content_type", "image/png")
192
+ if "jpeg" in content_type or "jpg" in content_type:
193
+ format_type = "jpeg"
194
+ elif "webp" in content_type:
195
+ format_type = "webp"
196
+ else:
197
+ format_type = "png"
198
+
199
+ # Store with appropriate output_index
200
+ artifact = await context.store_image_result(
201
+ storage_url=image_url,
202
+ format=format_type,
203
+ width=width,
204
+ height=height,
205
+ output_index=idx,
206
+ )
207
+ artifacts.append(artifact)
208
+
209
+ return GeneratorResult(outputs=artifacts)
210
+
211
+ async def estimate_cost(self, inputs: BytedanceSeedreamV45EditInput) -> float:
212
+ """Estimate cost for ByteDance Seedream v4.5 Edit generation.
213
+
214
+ Pricing not disclosed in documentation, using conservative estimate
215
+ based on similar high-quality image editing models.
216
+ """
217
+ # Conservative estimate per image
218
+ per_image_cost = 0.05
219
+ return per_image_cost * inputs.num_images
@@ -0,0 +1,208 @@
1
+ """
2
+ Google Gemini 2.5 Flash Image edit image-to-image generator.
3
+
4
+ Google's state-of-the-art image generation and editing model available through fal.ai.
5
+ Performs image-to-image transformations and edits based on text prompts.
6
+ Supports multiple aspect ratios and output formats with batch generation up to 4 images.
7
+
8
+ Based on Fal AI's fal-ai/gemini-25-flash-image/edit model.
9
+ See: https://fal.ai/models/fal-ai/gemini-25-flash-image/edit
10
+ """
11
+
12
+ import os
13
+ from typing import Literal
14
+
15
+ from pydantic import BaseModel, Field
16
+
17
+ from ....artifacts import ImageArtifact
18
+ from ....base import BaseGenerator, GeneratorExecutionContext, GeneratorResult
19
+
20
+
21
+ class Gemini25FlashImageEditInput(BaseModel):
22
+ """Input schema for Gemini 2.5 Flash Image edit generation.
23
+
24
+ Artifact fields (like image_sources) are automatically detected via type
25
+ introspection and resolved from generation IDs to ImageArtifact objects.
26
+ """
27
+
28
+ prompt: str = Field(
29
+ description="The editing instruction for image transformation",
30
+ min_length=3,
31
+ max_length=5000,
32
+ )
33
+ image_sources: list[ImageArtifact] = Field(
34
+ description="List of input images for editing (from previous generations)",
35
+ min_length=1,
36
+ )
37
+ num_images: int = Field(
38
+ default=1,
39
+ ge=1,
40
+ le=4,
41
+ description="Number of images to generate (max 4)",
42
+ )
43
+ aspect_ratio: (
44
+ Literal[
45
+ "auto",
46
+ "21:9",
47
+ "16:9",
48
+ "3:2",
49
+ "4:3",
50
+ "5:4",
51
+ "1:1",
52
+ "4:5",
53
+ "3:4",
54
+ "2:3",
55
+ "9:16",
56
+ ]
57
+ | None
58
+ ) = Field(
59
+ default="auto",
60
+ description="Image aspect ratio. Default 'auto' uses input image's aspect ratio.",
61
+ )
62
+ output_format: Literal["jpeg", "png", "webp"] = Field(
63
+ default="png",
64
+ description="Output image format",
65
+ )
66
+ sync_mode: bool = Field(
67
+ default=False,
68
+ description="Return media as data URI without request history storage",
69
+ )
70
+ limit_generations: bool = Field(
71
+ default=False,
72
+ description="Restrict to single generation per round (experimental)",
73
+ )
74
+
75
+
76
+ class FalGemini25FlashImageEditGenerator(BaseGenerator):
77
+ """Google Gemini 2.5 Flash Image edit generator using fal.ai."""
78
+
79
+ name = "fal-gemini-25-flash-image-edit"
80
+ artifact_type = "image"
81
+ description = "Fal: Gemini 2.5 Flash Image Edit - AI-powered image editing with Gemini"
82
+
83
+ def get_input_schema(self) -> type[Gemini25FlashImageEditInput]:
84
+ return Gemini25FlashImageEditInput
85
+
86
+ async def generate(
87
+ self, inputs: Gemini25FlashImageEditInput, context: GeneratorExecutionContext
88
+ ) -> GeneratorResult:
89
+ """Edit images using Google Gemini 2.5 Flash Image via fal.ai."""
90
+ # Check for API key (fal-client uses FAL_KEY environment variable)
91
+ if not os.getenv("FAL_KEY"):
92
+ raise ValueError("API configuration invalid. Missing FAL_KEY environment variable")
93
+
94
+ # Import fal_client
95
+ try:
96
+ import fal_client
97
+ except ImportError as e:
98
+ raise ImportError(
99
+ "fal.ai SDK is required for FalGemini25FlashImageEditGenerator. "
100
+ "Install with: pip install weirdfingers-boards[generators-fal]"
101
+ ) from e
102
+
103
+ # Upload image artifacts to Fal's public storage
104
+ # Fal API requires publicly accessible URLs, but our storage_url might be:
105
+ # - Localhost URLs (not publicly accessible)
106
+ # - Private S3 buckets (not publicly accessible)
107
+ # So we upload to Fal's temporary storage first
108
+ from ..utils import upload_artifacts_to_fal
109
+
110
+ image_urls = await upload_artifacts_to_fal(inputs.image_sources, context)
111
+
112
+ # Prepare arguments for fal.ai API
113
+ arguments = {
114
+ "prompt": inputs.prompt,
115
+ "image_urls": image_urls,
116
+ "num_images": inputs.num_images,
117
+ "output_format": inputs.output_format,
118
+ "sync_mode": inputs.sync_mode,
119
+ "limit_generations": inputs.limit_generations,
120
+ }
121
+
122
+ # Add aspect_ratio if provided
123
+ if inputs.aspect_ratio is not None:
124
+ arguments["aspect_ratio"] = inputs.aspect_ratio
125
+
126
+ # Submit async job and get handler
127
+ handler = await fal_client.submit_async(
128
+ "fal-ai/gemini-25-flash-image/edit",
129
+ arguments=arguments,
130
+ )
131
+
132
+ # Store the external job ID for tracking
133
+ await context.set_external_job_id(handler.request_id)
134
+
135
+ # Stream progress updates (sample every 3rd event to avoid spam)
136
+ from .....progress.models import ProgressUpdate
137
+
138
+ event_count = 0
139
+ async for event in handler.iter_events(with_logs=True):
140
+ event_count += 1
141
+
142
+ # Process every 3rd event to provide feedback without overwhelming
143
+ if event_count % 3 == 0:
144
+ # Extract logs if available
145
+ logs = getattr(event, "logs", None)
146
+ if logs:
147
+ # Join log entries into a single message
148
+ if isinstance(logs, list):
149
+ message = " | ".join(str(log) for log in logs if log)
150
+ else:
151
+ message = str(logs)
152
+
153
+ if message:
154
+ await context.publish_progress(
155
+ ProgressUpdate(
156
+ job_id=handler.request_id,
157
+ status="processing",
158
+ progress=50.0, # Approximate mid-point progress
159
+ phase="processing",
160
+ message=message,
161
+ )
162
+ )
163
+
164
+ # Get final result
165
+ result = await handler.get()
166
+
167
+ # Extract image URLs and description from result
168
+ # fal.ai returns: {
169
+ # "images": [{"url": "...", "width": ..., "height": ..., ...}, ...],
170
+ # "description": "Text description from Gemini"
171
+ # }
172
+ images = result.get("images", [])
173
+
174
+ if not images:
175
+ raise ValueError("No images returned from fal.ai API")
176
+
177
+ # Store each image using output_index
178
+ artifacts = []
179
+ for idx, image_data in enumerate(images):
180
+ image_url = image_data.get("url")
181
+ # Use 'or' to handle explicit None values from API
182
+ width = image_data.get("width") or 1024
183
+ height = image_data.get("height") or 1024
184
+
185
+ if not image_url:
186
+ raise ValueError(f"Image {idx} missing URL in fal.ai response")
187
+
188
+ # Store with appropriate output_index
189
+ artifact = await context.store_image_result(
190
+ storage_url=image_url,
191
+ format=inputs.output_format,
192
+ width=width,
193
+ height=height,
194
+ output_index=idx,
195
+ )
196
+ artifacts.append(artifact)
197
+
198
+ return GeneratorResult(outputs=artifacts)
199
+
200
+ async def estimate_cost(self, inputs: Gemini25FlashImageEditInput) -> float:
201
+ """Estimate cost for Gemini 2.5 Flash Image edit generation.
202
+
203
+ Note: Pricing information not available in fal.ai documentation.
204
+ Using placeholder estimate similar to other Gemini-based models.
205
+ """
206
+ # Placeholder cost estimate per image (similar to nano-banana which also uses Gemini)
207
+ per_image_cost = 0.039
208
+ return per_image_cost * inputs.num_images