ByteDream / examples.py
Enzo8930302's picture
Upload folder using huggingface_hub
80b58c8 verified
"""
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")