-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
executable file
·272 lines (216 loc) · 8.75 KB
/
Copy pathexample_usage.py
File metadata and controls
executable file
·272 lines (216 loc) · 8.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env python3
"""
Example Usage Script for AI Art Generator
Demonstrates various features and usage patterns
"""
import asyncio
import os
from pathlib import Path
from ai_art_generator import AIArtGenerator
async def example_single_generation():
"""Example: Generate a single image"""
print("🎨 Example 1: Single Image Generation")
print("=" * 50)
generator = AIArtGenerator()
await generator.connect()
try:
result = await generator.generate_single_image(
prompt="A futuristic stealth jet streaking through a neon-lit cityscape with glowing purple exhaust",
model="runware:97@2",
width=1344,
height=768,
steps=40,
cfg_scale=5
)
if "error" in result:
print(f"❌ Generation failed: {result['error']}")
else:
print(f"✅ Generated successfully!")
print(f"📁 Local file: {result['local_path']}")
print(f"🌐 URL: {result['image_url']}")
print(f"📊 Model: {result['model']}")
print(f"📏 Size: {result['width']}x{result['height']}")
finally:
await generator.disconnect()
async def example_batch_generation():
"""Example: Generate multiple images in batch"""
print("\n🎨 Example 2: Batch Generation")
print("=" * 50)
generator = AIArtGenerator()
await generator.connect()
try:
prompts = [
"A serene mountain landscape at sunset with golden light",
"A cyberpunk city street at night with neon lights",
"A magical forest with glowing mushrooms and fairy lights",
"A futuristic robot in a high-tech laboratory"
]
print(f"📝 Generating {len(prompts)} images...")
results = await generator.generate_batch(
prompts=prompts,
model="runware:101@1",
width=1024,
height=1024
)
successful = [r for r in results if "error" not in r]
failed = [r for r in results if "error" in r]
print(f"✅ Successfully generated {len(successful)} images")
if failed:
print(f"❌ Failed to generate {len(failed)} images")
for i, result in enumerate(successful, 1):
print(f" {i}. {result['local_path']}")
finally:
await generator.disconnect()
async def example_template_generation():
"""Example: Generate images using templates"""
print("\n🎨 Example 3: Template-Based Generation")
print("=" * 50)
generator = AIArtGenerator()
await generator.connect()
try:
# Generate portraits
print("📸 Generating portrait templates...")
portrait_results = await generator.generate_from_template(
template_type="portrait",
subject="a young woman with blue hair and green eyes",
style="anime style",
count=2
)
successful_portraits = [r for r in portrait_results if "error" not in r]
print(f"✅ Generated {len(successful_portraits)} portraits")
# Generate landscapes
print("🏔️ Generating landscape templates...")
landscape_results = await generator.generate_from_template(
template_type="landscape",
subject="majestic mountains",
location="Swiss Alps",
style="realistic",
count=2
)
successful_landscapes = [r for r in landscape_results if "error" not in r]
print(f"✅ Generated {len(successful_landscapes)} landscapes")
# Show results
for i, result in enumerate(successful_portraits + successful_landscapes, 1):
print(f" {i}. {result['local_path']}")
finally:
await generator.disconnect()
async def example_style_variations():
"""Example: Generate style variations"""
print("\n🎨 Example 4: Style Variations")
print("=" * 50)
generator = AIArtGenerator()
await generator.connect()
try:
base_prompt = "A majestic dragon flying over mountains"
styles = ["realistic", "anime", "cyberpunk", "artistic"]
print(f"🎭 Generating style variations for: {base_prompt}")
print(f"🎨 Styles: {', '.join(styles)}")
results = await generator.generate_with_style_variations(
base_prompt=base_prompt,
styles=styles,
model="runware:97@2"
)
successful = [r for r in results if "error" not in r]
print(f"✅ Generated {len(successful)} style variations")
for i, (result, style) in enumerate(zip(successful, styles), 1):
print(f" {i}. {style}: {result['local_path']}")
finally:
await generator.disconnect()
async def example_custom_models():
"""Example: Using different models"""
print("\n🎨 Example 5: Custom Models")
print("=" * 50)
generator = AIArtGenerator()
await generator.connect()
try:
# Test different models
models_to_test = {
"Realistic": "runware:97@2",
"Artistic": "runware:101@1",
"Photorealistic": "runware:100@1"
}
prompt = "A beautiful sunset over a calm ocean"
for model_name, model_id in models_to_test.items():
print(f"🎨 Testing {model_name} model...")
result = await generator.generate_single_image(
prompt=prompt,
model=model_id,
width=1024,
height=1024
)
if "error" not in result:
print(f" ✅ {model_name}: {result['local_path']}")
else:
print(f" ❌ {model_name}: {result['error']}")
finally:
await generator.disconnect()
async def example_advanced_parameters():
"""Example: Using advanced generation parameters"""
print("\n🎨 Example 6: Advanced Parameters")
print("=" * 50)
generator = AIArtGenerator()
await generator.connect()
try:
prompt = "A highly detailed portrait of a wise old wizard with magical aura"
# High quality settings
result = await generator.generate_single_image(
prompt=prompt,
model="runware:97@2",
width=1344,
height=768,
steps=50, # More steps for higher quality
cfg_scale=7, # Higher CFG for more prompt adherence
negative_prompt="blurry, low quality, distorted, ugly, bad anatomy"
)
if "error" not in result:
print(f"✅ High-quality generation: {result['local_path']}")
print(f"📊 Parameters used:")
print(f" - Steps: {result['steps']}")
print(f" - CFG Scale: {result['cfg_scale']}")
print(f" - Size: {result['width']}x{result['height']}")
else:
print(f"❌ Generation failed: {result['error']}")
finally:
await generator.disconnect()
def show_available_features():
"""Show available models and templates"""
print("\n📋 Available Features")
print("=" * 50)
generator = AIArtGenerator()
# Show models
print("🎯 Available Models:")
models = generator.get_available_models()
for name, model_id in models.items():
print(f" {name}: {model_id}")
# Show templates
print("\n📝 Available Templates:")
templates = generator.get_prompt_templates()
for template_type, template_list in templates.items():
print(f" {template_type}:")
for i, template in enumerate(template_list[:2]): # Show first 2 examples
print(f" {i+1}. {template[:60]}...")
async def main():
"""Run all examples"""
print("🚀 AI Art Generator - Example Usage")
print("=" * 60)
# Check if API key is set
if not os.getenv("RUNWARE_API_KEY"):
print("❌ RUNWARE_API_KEY not found in environment variables")
print("Please set your API key in the .env file")
return
# Show available features
show_available_features()
# Run examples
try:
await example_single_generation()
await example_batch_generation()
await example_template_generation()
await example_style_variations()
await example_custom_models()
await example_advanced_parameters()
print("\n🎉 All examples completed!")
print("📁 Check the 'generated_images' folder for your creations")
except Exception as e:
print(f"❌ Error running examples: {e}")
if __name__ == "__main__":
asyncio.run(main())