appkit-imagecreator 0.12.0__tar.gz
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.
- appkit_imagecreator-0.12.0/.gitignore +114 -0
- appkit_imagecreator-0.12.0/PKG-INFO +398 -0
- appkit_imagecreator-0.12.0/README.md +372 -0
- appkit_imagecreator-0.12.0/docs/imagecreator.jpeg +0 -0
- appkit_imagecreator-0.12.0/pyproject.toml +50 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/__init__.py +12 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/generator_registry.py +130 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/generators/__init__.py +11 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/generators/black_forest_labs.py +320 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/generators/google.py +172 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/generators/nano_banana.py +91 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/generators/openai.py +257 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/image_api.py +43 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/models.py +283 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/backend/repository.py +200 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/components/count.py +54 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/components/history.py +181 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/components/image_props.py +59 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/components/images.py +502 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/components/prompt.py +221 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/components/styles.py +93 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/configuration.py +86 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/pages.py +76 -0
- appkit_imagecreator-0.12.0/src/appkit_imagecreator/state.py +900 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
__pypackages__/
|
|
3
|
+
.cache
|
|
4
|
+
.coverage
|
|
5
|
+
.coverage.*
|
|
6
|
+
.dmypy.json
|
|
7
|
+
.DS_Store
|
|
8
|
+
.eggs/
|
|
9
|
+
.env
|
|
10
|
+
.env.backup
|
|
11
|
+
.env.docker
|
|
12
|
+
.hypothesis/
|
|
13
|
+
.idea/
|
|
14
|
+
.installed.cfg
|
|
15
|
+
.ipynb_checkpoints
|
|
16
|
+
.mypy_cache/
|
|
17
|
+
.nox/
|
|
18
|
+
.pdm.toml
|
|
19
|
+
.pybuilder/
|
|
20
|
+
.pyre/
|
|
21
|
+
.pytest_cache/
|
|
22
|
+
.Python
|
|
23
|
+
.python_packages
|
|
24
|
+
.pytype/
|
|
25
|
+
.ropeproject
|
|
26
|
+
.scrapy
|
|
27
|
+
.spyderproject
|
|
28
|
+
.spyproject
|
|
29
|
+
.states
|
|
30
|
+
.tox/
|
|
31
|
+
.venv
|
|
32
|
+
.venv.mac
|
|
33
|
+
.web
|
|
34
|
+
.webassets-cache
|
|
35
|
+
*.bak
|
|
36
|
+
*.cover
|
|
37
|
+
*.db
|
|
38
|
+
*.egg
|
|
39
|
+
*.egg-info/
|
|
40
|
+
*.kv-env.*
|
|
41
|
+
*.log
|
|
42
|
+
*.manifest
|
|
43
|
+
*.mo
|
|
44
|
+
*.pot
|
|
45
|
+
*.py,cover
|
|
46
|
+
*.py[cod]
|
|
47
|
+
*.sage.py
|
|
48
|
+
*.so
|
|
49
|
+
*.spec
|
|
50
|
+
*.terraform.lock.hcl
|
|
51
|
+
*.tfplan
|
|
52
|
+
*.tfstate
|
|
53
|
+
*.tfstate.*.backup
|
|
54
|
+
*.tfstate.backup
|
|
55
|
+
*.tfvars
|
|
56
|
+
**/.terraform/*
|
|
57
|
+
*$py.class
|
|
58
|
+
/site
|
|
59
|
+
/vectorstore/
|
|
60
|
+
aila-storage/
|
|
61
|
+
assets/external/
|
|
62
|
+
build/
|
|
63
|
+
celerybeat-schedule
|
|
64
|
+
celerybeat.pid
|
|
65
|
+
configuration/config.abaz009.yaml
|
|
66
|
+
configuration/config.bubb001.yaml
|
|
67
|
+
configuration/config.stie104.yaml
|
|
68
|
+
configuration/config.voro047.yaml
|
|
69
|
+
connector examples/sharepoint.json
|
|
70
|
+
cover/
|
|
71
|
+
coverage.xml
|
|
72
|
+
cython_debug/
|
|
73
|
+
db.sqlite3
|
|
74
|
+
db.sqlite3-journal
|
|
75
|
+
develop-eggs/
|
|
76
|
+
dist/
|
|
77
|
+
dmypy.json
|
|
78
|
+
docs/_build/
|
|
79
|
+
Documents/
|
|
80
|
+
downloads/
|
|
81
|
+
eggs/
|
|
82
|
+
env.bak/
|
|
83
|
+
env/
|
|
84
|
+
ENV/
|
|
85
|
+
htmlcov/
|
|
86
|
+
instance/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
knowledge/migrate.py
|
|
89
|
+
lib/
|
|
90
|
+
lib64/
|
|
91
|
+
local_settings.py
|
|
92
|
+
local.settings.json
|
|
93
|
+
MANIFEST
|
|
94
|
+
nosetests.xml
|
|
95
|
+
out
|
|
96
|
+
parts/
|
|
97
|
+
pip-delete-this-directory.txt
|
|
98
|
+
pip-log.txt
|
|
99
|
+
Pipfile
|
|
100
|
+
profile_default/
|
|
101
|
+
sdist/
|
|
102
|
+
share/python-wheels/
|
|
103
|
+
sketchpad/
|
|
104
|
+
sketchpad/
|
|
105
|
+
stores/
|
|
106
|
+
target/
|
|
107
|
+
tests/mcp_test.py
|
|
108
|
+
tmp.txt
|
|
109
|
+
uploaded_files/
|
|
110
|
+
uploads/
|
|
111
|
+
var/
|
|
112
|
+
venv.bak/
|
|
113
|
+
venv/
|
|
114
|
+
wheels/
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: appkit-imagecreator
|
|
3
|
+
Version: 0.12.0
|
|
4
|
+
Summary: Add your description here
|
|
5
|
+
Project-URL: Homepage, https://github.com/jenreh/appkit
|
|
6
|
+
Project-URL: Documentation, https://github.com/jenreh/appkit/tree/main/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/jenreh/appkit
|
|
8
|
+
Project-URL: Issues, https://github.com/jenreh/appkit/issues
|
|
9
|
+
Author: Jens Rehpöhler
|
|
10
|
+
Keywords: components,mantine,reflex,ui,web
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Classifier: Topic :: Software Development :: User Interfaces
|
|
17
|
+
Requires-Python: >=3.13
|
|
18
|
+
Requires-Dist: appkit-commons
|
|
19
|
+
Requires-Dist: fastapi>=0.115.0
|
|
20
|
+
Requires-Dist: google-genai>=1.26.0
|
|
21
|
+
Requires-Dist: httpx>=0.28.1
|
|
22
|
+
Requires-Dist: openai>=2.3.0
|
|
23
|
+
Requires-Dist: pillow>=12.1.0
|
|
24
|
+
Requires-Dist: reflex>=0.8.22
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# appkit-imagecreator
|
|
28
|
+
|
|
29
|
+
[](https://www.python.org/downloads/)
|
|
30
|
+
[](https://opensource.org/licenses/MIT)
|
|
31
|
+
|
|
32
|
+
**Multi-provider AI image generation component for Reflex applications.**
|
|
33
|
+
|
|
34
|
+
appkit-imagecreator provides a unified interface for generating images using multiple AI providers including Google Gemini (Imagen), OpenAI (DALL-E/GPT-Image), and Black Forest Labs (FLUX). It includes a complete Reflex UI for image generation workflows with prompt enhancement, parameter controls, and image management features.
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## ✨ Features
|
|
41
|
+
|
|
42
|
+
- **Multi-Provider Support** - Google Gemini Imagen, OpenAI GPT-Image-1/DALL-E, Black Forest Labs FLUX
|
|
43
|
+
- **Unified API** - Consistent interface across all image generation providers
|
|
44
|
+
- **Prompt Enhancement** - AI-powered prompt improvement using GPT models
|
|
45
|
+
- **Interactive UI** - Complete image generation interface with canvas, sidebar controls, and image gallery
|
|
46
|
+
- **Parameter Control** - Configurable image dimensions, steps, negative prompts, and seeds
|
|
47
|
+
- **Image Management** - Download, copy, and organize generated images
|
|
48
|
+
- **Error Handling** - Robust error handling and user feedback
|
|
49
|
+
- **Streaming Support** - Real-time generation progress and results
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 🚀 Installation
|
|
54
|
+
|
|
55
|
+
### As Part of AppKit Workspace
|
|
56
|
+
|
|
57
|
+
If you're using the full AppKit workspace:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
git clone https://github.com/jenreh/appkit.git
|
|
61
|
+
cd appkit
|
|
62
|
+
uv sync
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Standalone Installation
|
|
66
|
+
|
|
67
|
+
Install from PyPI:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install appkit-imagecreator
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or with uv:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
uv add appkit-imagecreator
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Dependencies
|
|
80
|
+
|
|
81
|
+
- `google-genai>=1.26.0` (Google Gemini API)
|
|
82
|
+
- `httpx>=0.28.1` (HTTP client)
|
|
83
|
+
- `appkit-commons` (shared utilities)
|
|
84
|
+
- `openai>=2.3.0` (OpenAI API)
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 🏁 Quick Start
|
|
89
|
+
|
|
90
|
+
### Basic Configuration
|
|
91
|
+
|
|
92
|
+
Configure API keys for your preferred providers:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from appkit_imagecreator.configuration import ImageGeneratorConfig
|
|
96
|
+
|
|
97
|
+
config = ImageGeneratorConfig(
|
|
98
|
+
google_api_key="secret:google_api_key",
|
|
99
|
+
openai_api_key="secret:openai_api_key",
|
|
100
|
+
blackforestlabs_api_key="secret:blackforestlabs_api_key",
|
|
101
|
+
tmp_dir="./generated_images" # Optional: custom temp directory
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Using the Image Generator
|
|
106
|
+
|
|
107
|
+
Generate images using the registry:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from appkit_imagecreator.backend.generator_registry import generator_registry
|
|
111
|
+
from appkit_imagecreator.backend.models import GenerationInput
|
|
112
|
+
|
|
113
|
+
# Get a generator
|
|
114
|
+
generator = generator_registry.get("gpt-image-1")
|
|
115
|
+
|
|
116
|
+
# Create generation input
|
|
117
|
+
input_data = GenerationInput(
|
|
118
|
+
prompt="A beautiful sunset over mountains",
|
|
119
|
+
width=1024,
|
|
120
|
+
height=1024,
|
|
121
|
+
negative_prompt="blurry, low quality",
|
|
122
|
+
steps=4,
|
|
123
|
+
enhance_prompt=True
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Generate image
|
|
127
|
+
response = await generator.generate(input_data)
|
|
128
|
+
if response.state == "succeeded":
|
|
129
|
+
print(f"Generated images: {response.images}")
|
|
130
|
+
else:
|
|
131
|
+
print(f"Error: {response.error}")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Using the UI Component
|
|
135
|
+
|
|
136
|
+
Add the image generator page to your Reflex app:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
import reflex as rx
|
|
140
|
+
from appkit_imagecreator.pages import image_generator_page
|
|
141
|
+
|
|
142
|
+
app = rx.App()
|
|
143
|
+
app.add_page(image_generator_page, title="Image Generator", route="/images")
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
---
|
|
147
|
+
|
|
148
|
+
## 📖 Usage
|
|
149
|
+
|
|
150
|
+
### Generator Registry
|
|
151
|
+
|
|
152
|
+
The registry manages all available image generators:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from appkit_imagecreator.backend.generator_registry import generator_registry
|
|
156
|
+
|
|
157
|
+
# List all generators
|
|
158
|
+
generators = generator_registry.list_generators()
|
|
159
|
+
print(generators)
|
|
160
|
+
# [{"id": "gpt-image-1", "label": "OpenAI GPT-Image-1"}, ...]
|
|
161
|
+
|
|
162
|
+
# Get a specific generator
|
|
163
|
+
generator = generator_registry.get("imagen-3")
|
|
164
|
+
|
|
165
|
+
# Get default generator
|
|
166
|
+
default_gen = generator_registry.get_default_generator()
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Generation Input
|
|
170
|
+
|
|
171
|
+
Configure image generation parameters:
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from appkit_imagecreator.backend.models import GenerationInput
|
|
175
|
+
|
|
176
|
+
input_data = GenerationInput(
|
|
177
|
+
prompt="A cyberpunk city at night with neon lights",
|
|
178
|
+
width=1024, # Image width
|
|
179
|
+
height=1024, # Image height
|
|
180
|
+
negative_prompt="blurry, distorted, ugly", # What to avoid
|
|
181
|
+
steps=4, # Generation steps (higher = better quality)
|
|
182
|
+
n=1, # Number of images to generate
|
|
183
|
+
seed=42, # Random seed for reproducible results
|
|
184
|
+
enhance_prompt=True # Use AI to improve the prompt
|
|
185
|
+
)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Custom Generators
|
|
189
|
+
|
|
190
|
+
Implement your own image generator:
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
from appkit_imagecreator.backend.models import ImageGenerator, GenerationInput, ImageGeneratorResponse, ImageResponseState
|
|
194
|
+
|
|
195
|
+
class CustomGenerator(ImageGenerator):
|
|
196
|
+
def __init__(self, api_key: str, backend_server: str):
|
|
197
|
+
super().__init__(
|
|
198
|
+
id="custom-gen",
|
|
199
|
+
label="Custom Generator",
|
|
200
|
+
model="custom-model",
|
|
201
|
+
api_key=api_key,
|
|
202
|
+
backend_server=backend_server
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
async def _perform_generation(self, input_data: GenerationInput) -> ImageGeneratorResponse:
|
|
206
|
+
# Your generation logic here
|
|
207
|
+
# Save image to temp and return URL
|
|
208
|
+
image_url = await self._save_image_to_tmp_and_get_url(
|
|
209
|
+
image_bytes, "custom", "png"
|
|
210
|
+
)
|
|
211
|
+
return ImageGeneratorResponse(
|
|
212
|
+
state=ImageResponseState.SUCCEEDED,
|
|
213
|
+
images=[image_url]
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
# Register your generator
|
|
217
|
+
generator_registry.register(CustomGenerator(api_key, backend_server))
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### UI Components
|
|
221
|
+
|
|
222
|
+
#### Main Page
|
|
223
|
+
|
|
224
|
+
The complete image generator interface:
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
from appkit_imagecreator.pages import image_generator_page
|
|
228
|
+
|
|
229
|
+
# Add to your app
|
|
230
|
+
app.add_page(image_generator_page, route="/image-generator")
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
#### Individual Components
|
|
234
|
+
|
|
235
|
+
Use specific UI components:
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
from appkit_imagecreator.components.canvas import image_ui
|
|
239
|
+
from appkit_imagecreator.components.sidebar import sidebar
|
|
240
|
+
|
|
241
|
+
def custom_layout():
|
|
242
|
+
return rx.flex(
|
|
243
|
+
sidebar(), # Generation controls
|
|
244
|
+
image_ui(), # Image display canvas
|
|
245
|
+
flex_direction="row"
|
|
246
|
+
)
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## 🔧 Configuration
|
|
252
|
+
|
|
253
|
+
### ImageGeneratorConfig
|
|
254
|
+
|
|
255
|
+
Configure API keys and settings:
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
from appkit_imagecreator.configuration import ImageGeneratorConfig
|
|
259
|
+
|
|
260
|
+
config = ImageGeneratorConfig(
|
|
261
|
+
google_api_key="secret:google_gemini_key",
|
|
262
|
+
openai_api_key="secret:openai_key",
|
|
263
|
+
blackforestlabs_api_key="secret:bfl_key",
|
|
264
|
+
openai_base_url="https://api.openai.com/v1", # Optional custom endpoint
|
|
265
|
+
tmp_dir="./tmp/images" # Temp directory for generated images
|
|
266
|
+
)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Provider-Specific Setup
|
|
270
|
+
|
|
271
|
+
#### Google Gemini
|
|
272
|
+
|
|
273
|
+
Requires `google_api_key` for Imagen models:
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
# Uses Imagen 3.0 by default
|
|
277
|
+
generator = generator_registry.get("imagen-3")
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
#### OpenAI
|
|
281
|
+
|
|
282
|
+
Supports DALL-E and GPT-Image-1:
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
# GPT-Image-1 (default)
|
|
286
|
+
gpt_gen = generator_registry.get("gpt-image-1")
|
|
287
|
+
|
|
288
|
+
# Custom OpenAI-compatible endpoint
|
|
289
|
+
config.openai_base_url = "https://your-endpoint.com/v1"
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
#### Black Forest Labs
|
|
293
|
+
|
|
294
|
+
FLUX models for high-quality generation:
|
|
295
|
+
|
|
296
|
+
```python
|
|
297
|
+
flux_gen = generator_registry.get("FLUX-1.1-pro")
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## 📋 API Reference
|
|
303
|
+
|
|
304
|
+
### Core Classes
|
|
305
|
+
|
|
306
|
+
- `ImageGenerator` - Abstract base class for image generators
|
|
307
|
+
- `GenerationInput` - Input parameters for image generation
|
|
308
|
+
- `ImageGeneratorResponse` - Response containing generated images or errors
|
|
309
|
+
- `ImageGeneratorRegistry` - Registry managing all generators
|
|
310
|
+
|
|
311
|
+
### Generators
|
|
312
|
+
|
|
313
|
+
- `GoogleImageGenerator` - Google Gemini Imagen integration
|
|
314
|
+
- `OpenAIImageGenerator` - OpenAI DALL-E/GPT-Image integration
|
|
315
|
+
- `BlackForestLabsGenerator` - Black Forest Labs FLUX integration
|
|
316
|
+
|
|
317
|
+
### Component API
|
|
318
|
+
|
|
319
|
+
- `image_generator_page()` - Complete image generation page
|
|
320
|
+
- `image_ui()` - Main image display and controls
|
|
321
|
+
- `sidebar()` - Generation parameter controls
|
|
322
|
+
- `image_list()` - Generated image gallery
|
|
323
|
+
|
|
324
|
+
### State Management
|
|
325
|
+
|
|
326
|
+
- `CopyLocalState` - State for image copy/download operations
|
|
327
|
+
|
|
328
|
+
---
|
|
329
|
+
|
|
330
|
+
## 🔒 Security
|
|
331
|
+
|
|
332
|
+
> [!IMPORTANT]
|
|
333
|
+
> API keys are handled securely using the appkit-commons configuration system. Never hardcode secrets in your code.
|
|
334
|
+
|
|
335
|
+
- Use `SecretStr` for API key configuration
|
|
336
|
+
- Secrets resolved from environment variables or Key Vault
|
|
337
|
+
- Temporary images stored securely with unique filenames
|
|
338
|
+
- No sensitive data logged in generation processes
|
|
339
|
+
|
|
340
|
+
---
|
|
341
|
+
|
|
342
|
+
## 🤝 Integration Examples
|
|
343
|
+
|
|
344
|
+
### With AppKit User Management
|
|
345
|
+
|
|
346
|
+
Restrict image generation to authenticated users:
|
|
347
|
+
|
|
348
|
+
```python
|
|
349
|
+
from appkit_user import authenticated, requires_role
|
|
350
|
+
from appkit_imagecreator.pages import image_generator_page
|
|
351
|
+
|
|
352
|
+
@authenticated()
|
|
353
|
+
@requires_role("image_generator")
|
|
354
|
+
def protected_image_page():
|
|
355
|
+
return image_generator_page()
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### Custom Prompt Enhancement
|
|
359
|
+
|
|
360
|
+
Override prompt enhancement logic:
|
|
361
|
+
|
|
362
|
+
```python
|
|
363
|
+
class CustomGenerator(OpenAIImageGenerator):
|
|
364
|
+
async def _enhance_prompt(self, prompt: str) -> str:
|
|
365
|
+
# Your custom enhancement logic
|
|
366
|
+
enhanced = await self.client.chat.completions.create(
|
|
367
|
+
model="gpt-4",
|
|
368
|
+
messages=[{"role": "user", "content": f"Enhance this image prompt: {prompt}"}]
|
|
369
|
+
)
|
|
370
|
+
return enhanced.choices[0].message.content
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
### Batch Generation
|
|
374
|
+
|
|
375
|
+
Generate multiple images with different parameters:
|
|
376
|
+
|
|
377
|
+
```python
|
|
378
|
+
async def batch_generate(prompts: list[str]) -> list[str]:
|
|
379
|
+
generator = generator_registry.get("gpt-image-1")
|
|
380
|
+
images = []
|
|
381
|
+
|
|
382
|
+
for prompt in prompts:
|
|
383
|
+
input_data = GenerationInput(prompt=prompt, n=1)
|
|
384
|
+
response = await generator.generate(input_data)
|
|
385
|
+
if response.state == "succeeded":
|
|
386
|
+
images.extend(response.images)
|
|
387
|
+
|
|
388
|
+
return images
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## 📚 Related Components
|
|
394
|
+
|
|
395
|
+
- **[appkit-mantine](./../appkit-mantine)** - UI components used in the image generator interface
|
|
396
|
+
- **[appkit-user](./../appkit-user)** - User authentication for protected image generation
|
|
397
|
+
- **[appkit-commons](./../appkit-commons)** - Shared utilities and configuration
|
|
398
|
+
- **[appkit-assistant](./../appkit-assistant)** - AI assistant that can integrate with image generation
|