File size: 9,359 Bytes
80b58c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
"""

Byte Dream - Example Usage Scripts

Practical examples for different use cases

"""

from bytedream import ByteDreamGenerator
from pathlib import Path


def example_basic_generation():
    """Basic image generation example"""
    print("\n" + "="*60)
    print("Example 1: Basic Generation")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    # Simple prompt
    image = generator.generate(
        prompt="A beautiful sunset over mountains, digital art",
    )
    
    image.save("example_basic.png")
    print("βœ“ Saved to: example_basic.png")


def example_advanced_parameters():
    """Advanced parameter tuning"""
    print("\n" + "="*60)
    print("Example 2: Advanced Parameters")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    # Custom parameters
    image = generator.generate(
        prompt="Cyberpunk city at night, neon lights, futuristic architecture",
        negative_prompt="ugly, blurry, low quality, distorted, dark",
        width=768,
        height=768,
        num_inference_steps=75,
        guidance_scale=9.0,
        seed=42,
    )
    
    image.save("example_advanced.png")
    print("βœ“ Saved to: example_advanced.png")


def example_batch_generation():
    """Generate multiple images"""
    print("\n" + "="*60)
    print("Example 3: Batch Generation")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    prompts = [
        "Fantasy landscape with castle and waterfall, epic scenery",
        "Underwater coral reef, tropical fish, sunlight through water",
        "Space nebula, colorful clouds, stars, cosmic scene",
        "Medieval knight in armor, dramatic lighting, portrait",
        "Japanese garden, cherry blossoms, peaceful atmosphere",
    ]
    
    images = generator.generate_batch(
        prompts=prompts,
        width=512,
        height=512,
        num_inference_steps=50,
        guidance_scale=7.5,
    )
    
    # Save individually
    for i, (prompt, image) in enumerate(zip(prompts, images)):
        filename = f"batch_{i+1}.png"
        image.save(filename)
        print(f"βœ“ Saved: {filename}")
    
    # Create grid
    from bytedream.utils import create_image_grid
    grid = create_image_grid(images)
    grid.save("batch_grid.png")
    print("βœ“ Grid saved to: batch_grid.png")


def example_artistic_styles():
    """Different artistic styles"""
    print("\n" + "="*60)
    print("Example 4: Artistic Styles")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    style_prompts = [
        ("Oil Painting", "Portrait of a woman, oil painting style, brush strokes, classical art"),
        ("Watercolor", "Forest landscape, watercolor painting, soft colors, artistic"),
        ("Digital Art", "Sci-fi spaceship, digital art, concept art, highly detailed"),
        ("Sketch", "City skyline, pencil sketch, black and white, drawing"),
        ("Abstract", "Emotions and dreams, abstract art, colorful shapes, surreal"),
    ]
    
    for style_name, prompt in style_prompts:
        print(f"\nGenerating {style_name}...")
        
        image = generator.generate(
            prompt=prompt,
            num_inference_steps=50,
            guidance_scale=7.5,
        )
        
        filename = f"style_{style_name.lower().replace(' ', '_')}.png"
        image.save(filename)
        print(f"βœ“ Saved: {filename}")


def example_resolutions():
    """Test different resolutions"""
    print("\n" + "="*60)
    print("Example 5: Different Resolutions")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    base_prompt = "Majestic mountain range, snow peaks, blue sky"
    
    resolutions = [
        (256, 256),
        (512, 512),
        (768, 768),
        (512, 768),  # Portrait
        (768, 512),  # Landscape
    ]
    
    for width, height in resolutions:
        print(f"\nGenerating {width}x{height}...")
        
        image = generator.generate(
            prompt=base_prompt,
            width=width,
            height=height,
            num_inference_steps=40,
        )
        
        filename = f"res_{width}x{height}.png"
        image.save(filename)
        print(f"βœ“ Saved: {filename}")


def example_reproducibility():
    """Demonstrate reproducibility with seeds"""
    print("\n" + "="*60)
    print("Example 6: Reproducibility with Seeds")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    prompt = "A mystical forest with glowing mushrooms, fantasy art"
    
    # Generate same image twice with same seed
    print("\nGenerating with seed=123...")
    image1 = generator.generate(
        prompt=prompt,
        seed=123,
    )
    image1.save("repro_1.png")
    
    print("Generating again with seed=123...")
    image2 = generator.generate(
        prompt=prompt,
        seed=123,
    )
    image2.save("repro_2.png")
    
    print("\nBoth images should be identical!")
    print("βœ“ Check repro_1.png and repro_2.png")
    
    # Generate with different seed
    print("\nGenerating with seed=456...")
    image3 = generator.generate(
        prompt=prompt,
        seed=456,
    )
    image3.save("repro_3.png")
    print("This one will be different!")


def example_negative_prompts():
    """Using negative prompts effectively"""
    print("\n" + "="*60)
    print("Example 7: Negative Prompts")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    base_prompt = "Beautiful princess, elegant dress, castle background"
    
    # Without negative prompt
    print("\nWithout negative prompt...")
    image1 = generator.generate(
        prompt=base_prompt,
        seed=789,
    )
    image1.save("no_negative.png")
    
    # With negative prompt
    print("With negative prompt...")
    image2 = generator.generate(
        prompt=base_prompt,
        negative_prompt="ugly, deformed, noisy, blurry, bad anatomy, poorly drawn",
        seed=789,
    )
    image2.save("with_negative.png")
    
    print("\nCompare no_negative.png and with_negative.png")


def example_quick_preview():
    """Quick low-resolution previews"""
    print("\n" + "="*60)
    print("Example 8: Quick Preview Mode")
    print("="*60)
    
    generator = ByteDreamGenerator()
    
    prompt = "Dragon breathing fire, epic fantasy battle scene"
    
    # Quick preview
    print("Generating quick preview (256x256, 20 steps)...")
    preview = generator.generate(
        prompt=prompt,
        width=256,
        height=256,
        num_inference_steps=20,
    )
    preview.save("preview.png")
    print("βœ“ Preview saved")
    
    # Full resolution
    print("\nGenerating full quality (768x768, 75 steps)...")
    full = generator.generate(
        prompt=prompt,
        width=768,
        height=768,
        num_inference_steps=75,
    )
    full.save("full_quality.png")
    print("βœ“ Full quality saved")


def run_all_examples():
    """Run all examples sequentially"""
    print("\n" + "="*60)
    print("Byte Dream - Complete Examples Suite")
    print("="*60)
    
    examples = [
        example_basic_generation,
        example_advanced_parameters,
        example_batch_generation,
        example_artistic_styles,
        example_resolutions,
        example_reproducibility,
        example_negative_prompts,
        example_quick_preview,
    ]
    
    for example_func in examples:
        try:
            example_func()
        except Exception as e:
            print(f"\nβœ— Error in {example_func.__name__}: {e}")
            import traceback
            traceback.print_exc()
        
        print("\n" + "-"*60)
        input("Press Enter to continue to next example...")
    
    print("\n" + "="*60)
    print("All examples completed!")
    print("="*60)


if __name__ == "__main__":
    import argparse
    
    parser = argparse.ArgumentParser(description="Byte Dream Examples")
    parser.add_argument("--all", action="store_true", help="Run all examples")
    parser.add_argument("--basic", action="store_true", help="Run basic example")
    parser.add_argument("--advanced", action="store_true", help="Run advanced example")
    parser.add_argument("--batch", action="store_true", help="Run batch generation")
    parser.add_argument("--styles", action="store_true", help="Run artistic styles")
    
    args = parser.parse_args()
    
    if args.all:
        run_all_examples()
    elif args.basic:
        example_basic_generation()
    elif args.advanced:
        example_advanced_parameters()
    elif args.batch:
        example_batch_generation()
    elif args.styles:
        example_artistic_styles()
    else:
        # Default: show menu
        print("\nByte Dream Examples")
        print("="*60)
        print("Choose an example:")
        print("  --basic     : Basic generation")
        print("  --advanced  : Advanced parameters")
        print("  --batch     : Batch generation")
        print("  --styles    : Artistic styles")
        print("  --all       : Run all examples")
        print("\nOr just run without arguments to see all examples")