Add training dataset generator + fix MPS dtype for local inference
Browse files- scripts/generate_dataset.py: generates 80 kawaii scene images using
Gemini 3.1 Flash Image (Nano Banana 2) β 8 categories Γ 10 animals,
square 1:1 output, supports --start N resume and --dry-run preview,
loads GEMINI_API_KEY from .env via python-dotenv
- image_generator.py: use float16 on MPS (bfloat16 unsupported) and
enable_sequential_cpu_offload to avoid OOM on local Apple Silicon
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- image_generator.py +11 -4
- scripts/generate_dataset.py +309 -0
image_generator.py
CHANGED
|
@@ -118,10 +118,15 @@ def get_pipeline():
|
|
| 118 |
from diffusers import FluxPipeline
|
| 119 |
|
| 120 |
hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
_pipe = FluxPipeline.from_pretrained(
|
| 123 |
"black-forest-labs/FLUX.1-schnell",
|
| 124 |
-
torch_dtype=
|
| 125 |
token=hf_token,
|
| 126 |
)
|
| 127 |
|
|
@@ -131,8 +136,10 @@ def get_pipeline():
|
|
| 131 |
_pipe = _pipe.to("cuda")
|
| 132 |
elif torch.cuda.is_available():
|
| 133 |
_pipe = _pipe.to("cuda")
|
| 134 |
-
elif
|
| 135 |
-
|
|
|
|
|
|
|
| 136 |
else:
|
| 137 |
_pipe = _pipe.to("cpu")
|
| 138 |
|
|
|
|
| 118 |
from diffusers import FluxPipeline
|
| 119 |
|
| 120 |
hf_token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGING_FACE_HUB_TOKEN")
|
| 121 |
+
|
| 122 |
+
use_mps = (not IS_HF_SPACE) and (not torch.cuda.is_available()) and torch.backends.mps.is_available()
|
| 123 |
+
# MPS has incomplete bfloat16 support β float16 is faster and uses half the memory there.
|
| 124 |
+
dtype = torch.float16 if use_mps else torch.bfloat16
|
| 125 |
+
|
| 126 |
+
print(f"Loading FLUX.1-schnell pipeline⦠(token={'set' if hf_token else 'NOT SET'}, dtype={dtype})")
|
| 127 |
_pipe = FluxPipeline.from_pretrained(
|
| 128 |
"black-forest-labs/FLUX.1-schnell",
|
| 129 |
+
torch_dtype=dtype,
|
| 130 |
token=hf_token,
|
| 131 |
)
|
| 132 |
|
|
|
|
| 136 |
_pipe = _pipe.to("cuda")
|
| 137 |
elif torch.cuda.is_available():
|
| 138 |
_pipe = _pipe.to("cuda")
|
| 139 |
+
elif use_mps:
|
| 140 |
+
# Sequential CPU offload avoids MPS OOM: each transformer block is moved
|
| 141 |
+
# to MPS one at a time, then immediately returned to CPU.
|
| 142 |
+
_pipe.enable_sequential_cpu_offload()
|
| 143 |
else:
|
| 144 |
_pipe = _pipe.to("cpu")
|
| 145 |
|
scripts/generate_dataset.py
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
NumZoo training dataset generator.
|
| 3 |
+
|
| 4 |
+
Generates 80 images matching the NumZoo aesthetic using Gemini 3.1 Flash Image (Nano Banana 2):
|
| 5 |
+
- Kawaii chibi animals with big sparkling eyes
|
| 6 |
+
- Rich scene backgrounds (no white background)
|
| 7 |
+
- Warm pastel palette, fairy lights, cozy props
|
| 8 |
+
- Landscape 16:9, children's book illustration style
|
| 9 |
+
|
| 10 |
+
Output: training/image_001.jpg + training/image_001.txt (caption)
|
| 11 |
+
|
| 12 |
+
Requirements:
|
| 13 |
+
pip install google-genai pillow
|
| 14 |
+
|
| 15 |
+
Usage:
|
| 16 |
+
export GEMINI_API_KEY=your_key
|
| 17 |
+
python scripts/generate_dataset.py
|
| 18 |
+
python scripts/generate_dataset.py --start 41 # resume from image 41
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import os
|
| 22 |
+
import sys
|
| 23 |
+
import argparse
|
| 24 |
+
import time
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
|
| 27 |
+
# Load .env from project root (GEMINI_API_KEY etc.)
|
| 28 |
+
try:
|
| 29 |
+
from dotenv import load_dotenv
|
| 30 |
+
load_dotenv(Path(__file__).parent.parent / ".env")
|
| 31 |
+
except ImportError:
|
| 32 |
+
pass # dotenv optional β can also export GEMINI_API_KEY manually
|
| 33 |
+
|
| 34 |
+
# ---------------------------------------------------------------------------
|
| 35 |
+
# 80 prompts β 8 scene categories Γ 10 animals
|
| 36 |
+
# Style wrapper applied uniformly so the LoRA captures it as a learnable token
|
| 37 |
+
# ---------------------------------------------------------------------------
|
| 38 |
+
|
| 39 |
+
STYLE = (
|
| 40 |
+
"kawaii children's book illustration, pastel anime art style, "
|
| 41 |
+
"soft painterly lighting, detailed rich background with warm fairy lights, "
|
| 42 |
+
"cozy magical atmosphere, cute chibi character with big sparkling eyes, "
|
| 43 |
+
"soft pastel color palette, highly detailed scene, no text"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
PROMPTS: list[tuple[str, str]] = [
|
| 47 |
+
# ββ 1. Cozy cabin interior ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 48 |
+
("cozy_cabin_01", f"a fluffy bunny curled on an armchair by a stone fireplace inside a wooden cabin, "
|
| 49 |
+
f"pastel star blanket, string lights, hot cocoa on a tree-stump table, warm amber glow, {STYLE}"),
|
| 50 |
+
("cozy_cabin_02", f"a sleepy kitten reading a tiny book in a cozy log cabin, "
|
| 51 |
+
f"fairy lights strung above wooden shelves with colorful jars, fireplace crackling, "
|
| 52 |
+
f"pastel pink and lavender tones, {STYLE}"),
|
| 53 |
+
("cozy_cabin_03", f"a baby bear in a rainbow scarf sitting at a round wooden table with pancakes "
|
| 54 |
+
f"inside a cabin, soft morning light through an arched window, {STYLE}"),
|
| 55 |
+
("cozy_cabin_04", f"a hedgehog wrapped in a cloud-print blanket watching raindrops on a cabin window, "
|
| 56 |
+
f"string lights reflected in the glass, soft purple tones, {STYLE}"),
|
| 57 |
+
("cozy_cabin_05", f"a baby fox and a bunny sharing hot tea by a fireplace in a treehouse cabin, "
|
| 58 |
+
f"wooden bookshelves, pastel mugs, twinkle lights, {STYLE}"),
|
| 59 |
+
("cozy_cabin_06", f"a tiny owl perched on a branch reading a glowing book inside a lantern-lit cabin, "
|
| 60 |
+
f"warm golden light, mossy windowsill with flowers outside, {STYLE}"),
|
| 61 |
+
("cozy_cabin_07", f"a baby deer sitting on a plaid cushion inside a snug wooden cabin, "
|
| 62 |
+
f"potted cactus and tiny succulents on shelves, fairy lights overhead, {STYLE}"),
|
| 63 |
+
("cozy_cabin_08", f"a raccoon stirring a sparkling potion in a cozy cabin kitchen, "
|
| 64 |
+
f"mason jars of colorful ingredients, star-shaped window, warm light, {STYLE}"),
|
| 65 |
+
("cozy_cabin_09", f"a baby penguin in a striped scarf napping on a pastel sofa next to a glowing fireplace, "
|
| 66 |
+
f"snow visible through the cabin window, {STYLE}"),
|
| 67 |
+
("cozy_cabin_10", f"a squirrel decorating a tiny pine tree inside a cabin with star ornaments and ribbon, "
|
| 68 |
+
f"fairy lights everywhere, soft pink tones, {STYLE}"),
|
| 69 |
+
|
| 70 |
+
# ββ 2. Enchanted forest β day βββββββββββββββββββββββββββββββββββββββββββ
|
| 71 |
+
("forest_day_01", f"a bunny in a daisy field inside an enchanted forest, "
|
| 72 |
+
f"sunbeams through tall trees, floating sparkles, colorful mushrooms, {STYLE}"),
|
| 73 |
+
("forest_day_02", f"a kitten playing with a butterfly on a mossy log in a sunlit magical forest, "
|
| 74 |
+
f"wildflowers in pastel pink and lilac, {STYLE}"),
|
| 75 |
+
("forest_day_03", f"a baby bear discovering a tiny glowing door in a tree trunk in an enchanted forest, "
|
| 76 |
+
f"soft golden afternoon light, flower garlands, {STYLE}"),
|
| 77 |
+
("forest_day_04", f"a hedgehog gathering strawberries in a forest clearing, "
|
| 78 |
+
f"pastel checkered picnic blanket, wicker basket, soft dappled sunlight, {STYLE}"),
|
| 79 |
+
("forest_day_05", f"a baby fox sitting on a giant mushroom in a magical forest, "
|
| 80 |
+
f"fairy dust floating around, colorful birds in branches above, {STYLE}"),
|
| 81 |
+
("forest_day_06", f"an owl in a graduation cap perched on a tree branch in a sunlit forest, "
|
| 82 |
+
f"hanging star lanterns, flowers blooming below, {STYLE}"),
|
| 83 |
+
("forest_day_07", f"a baby deer drinking from a sparkling stream in a lush forest, "
|
| 84 |
+
f"rainbow trout visible in the water, cherry blossoms drifting, {STYLE}"),
|
| 85 |
+
("forest_day_08", f"a raccoon painting a tiny canvas in a forest studio made of logs and branches, "
|
| 86 |
+
f"colorful paint pots, sunlight streaming in, {STYLE}"),
|
| 87 |
+
("forest_day_09", f"a baby penguin waddling through a magical spring forest with tulips taller than it, "
|
| 88 |
+
f"pastel butterflies, {STYLE}"),
|
| 89 |
+
("forest_day_10", f"a squirrel and a bunny having a tea party on a giant leaf in the forest, "
|
| 90 |
+
f"acorn cups, mushroom chairs, sunlit clearing, {STYLE}"),
|
| 91 |
+
|
| 92 |
+
# ββ 3. Magical forest β night / campfire ββββββββββββββββββββββββββββββββ
|
| 93 |
+
("forest_night_01", f"a bunny and a kitten roasting marshmallows over a small campfire in a night forest, "
|
| 94 |
+
f"crescent moon, fireflies, string lights in the trees, {STYLE}"),
|
| 95 |
+
("forest_night_02", f"a baby bear stargazing in a moonlit forest clearing, lying on a cloud-print blanket, "
|
| 96 |
+
f"glowing constellations above, lantern beside, {STYLE}"),
|
| 97 |
+
("forest_night_03", f"a baby fox with a tiny lantern walking a forest path at night, "
|
| 98 |
+
f"glowing mushrooms lining the path, crescent moon, {STYLE}"),
|
| 99 |
+
("forest_night_04", f"a hedgehog sleeping under a luminescent mushroom at night in the forest, "
|
| 100 |
+
f"fireflies around, purple and blue tones, soft moonlight, {STYLE}"),
|
| 101 |
+
("forest_night_05", f"an owl sitting on a branch under the stars playing a tiny ukulele for forest friends "
|
| 102 |
+
f"gathered below, night forest, fairy lights, {STYLE}"),
|
| 103 |
+
("forest_night_06", f"a baby deer watching shooting stars from a mossy hilltop at night, "
|
| 104 |
+
f"forest silhouette below, soft purple sky, sparkles, {STYLE}"),
|
| 105 |
+
("forest_night_07", f"a raccoon cooking s'mores at a campfire in a night forest, "
|
| 106 |
+
f"camping tent with fairy lights, moon and stars above, {STYLE}"),
|
| 107 |
+
("forest_night_08", f"a baby penguin looking at its reflection in a glowing moonlit pond in a night forest, "
|
| 108 |
+
f"lily pads with tiny lights, {STYLE}"),
|
| 109 |
+
("forest_night_09", f"a squirrel telling stories around a campfire to bunny and kitten, night forest, "
|
| 110 |
+
f"warm firelight, stars through the tree canopy, {STYLE}"),
|
| 111 |
+
("forest_night_10", f"a kitten catching fireflies in a jar at the edge of a glowing forest at dusk, "
|
| 112 |
+
f"silhouette trees, warm golden light, {STYLE}"),
|
| 113 |
+
|
| 114 |
+
# ββ 4. Treehouse ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 115 |
+
("treehouse_01", f"a bunny inside a cozy treehouse at sunset, rope bridge entrance, "
|
| 116 |
+
f"flower window box, warm light glowing inside, {STYLE}"),
|
| 117 |
+
("treehouse_02", f"a kitten at the door of a treehouse with a welcome sign, "
|
| 118 |
+
f"string lights along the railing, forest view at golden hour, {STYLE}"),
|
| 119 |
+
("treehouse_03", f"a baby bear and a hedgehog playing board games on the treehouse porch, "
|
| 120 |
+
f"paper lanterns, leafy canopy above, {STYLE}"),
|
| 121 |
+
("treehouse_04", f"a baby fox gazing at the stars through a treehouse telescope at night, "
|
| 122 |
+
f"spiral staircase, crescent moon, {STYLE}"),
|
| 123 |
+
("treehouse_05", f"an owl's cozy treehouse library with tiny glowing books and a reading nook, "
|
| 124 |
+
f"ivy covered walls, daytime, {STYLE}"),
|
| 125 |
+
("treehouse_06", f"a baby bear watering flower boxes on a treehouse balcony, "
|
| 126 |
+
f"bees and butterflies, golden afternoon light, leafy forest below, {STYLE}"),
|
| 127 |
+
("treehouse_07", f"a hedgehog and a squirrel stringing fairy lights around a treehouse at dusk, "
|
| 128 |
+
f"warm glow, birds watching from nearby branches, {STYLE}"),
|
| 129 |
+
("treehouse_08", f"a baby fox sliding down a spiral slide from a treehouse into a pile of leaves, "
|
| 130 |
+
f"autumn forest, rope ladder, golden light, {STYLE}"),
|
| 131 |
+
("treehouse_09", f"a baby deer reading a glowing map inside a treehouse at night, "
|
| 132 |
+
f"star-shaped windows, moonlight, cozy lanterns, {STYLE}"),
|
| 133 |
+
("treehouse_10", f"a raccoon and a bunny cooking soup in a tiny treehouse kitchen, "
|
| 134 |
+
f"steam rising, herbs hanging, sunlight through small windows, {STYLE}"),
|
| 135 |
+
|
| 136 |
+
# ββ 5. Garden / meadow β day ββββββββββββββββββββββββββββββββββββββββββββ
|
| 137 |
+
("garden_01", f"a bunny watering oversized tulips in a magical garden, "
|
| 138 |
+
f"pastel blue watering can, butterflies, soft morning light, {STYLE}"),
|
| 139 |
+
("garden_02", f"a kitten napping in a flower hammock in a sunny garden, "
|
| 140 |
+
f"roses and lavender around, bees buzzing, {STYLE}"),
|
| 141 |
+
("garden_03", f"a baby bear picking giant strawberries in a garden, "
|
| 142 |
+
f"ladybugs on leaves, warm afternoon sun, picket fence, {STYLE}"),
|
| 143 |
+
("garden_04", f"a hedgehog rolling through a field of sunflowers, "
|
| 144 |
+
f"pastel sky, birds above, soft breeze, {STYLE}"),
|
| 145 |
+
("garden_05", f"a baby fox blowing dandelion seeds in a meadow, "
|
| 146 |
+
f"seeds glowing like stars, cherry trees in background, {STYLE}"),
|
| 147 |
+
("garden_06", f"a baby deer in a rain boots splashing in a puddle in a garden after rain, "
|
| 148 |
+
f"rainbow in the sky, wet flowers, {STYLE}"),
|
| 149 |
+
("garden_07", f"a raccoon painting a garden fence with rainbow stripes, "
|
| 150 |
+
f"paint buckets, butterflies landing on fresh paint, {STYLE}"),
|
| 151 |
+
("garden_08", f"a baby penguin planting seeds in a tiny garden plot, "
|
| 152 |
+
f"little labeled plant markers, pastel gloves and apron, {STYLE}"),
|
| 153 |
+
("garden_09", f"a squirrel collecting colorful autumn leaves in a basket in a golden meadow, "
|
| 154 |
+
f"maple trees, soft warm light, {STYLE}"),
|
| 155 |
+
("garden_10", f"a bunny and kitten flying a star-shaped kite in an open meadow, "
|
| 156 |
+
f"puffy clouds, wildflowers below, {STYLE}"),
|
| 157 |
+
|
| 158 |
+
# ββ 6. Beach / waterfront βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 159 |
+
("beach_01", f"a bunny building a sand castle on a pastel beach at sunset, "
|
| 160 |
+
f"sea shells, gentle waves, pink and orange sky, {STYLE}"),
|
| 161 |
+
("beach_02", f"a kitten surfing a tiny wave on a pastel board, "
|
| 162 |
+
f"tropical beach, palm trees, clear turquoise water, {STYLE}"),
|
| 163 |
+
("beach_03", f"a baby bear making friends with a crab on the beach, "
|
| 164 |
+
f"rock pools with anemones, soft summer light, {STYLE}"),
|
| 165 |
+
("beach_04", f"a baby fox asleep in a hammock strung between two palm trees on a beach, "
|
| 166 |
+
f"coconuts, ocean at dusk, {STYLE}"),
|
| 167 |
+
("beach_05", f"a baby penguin waddling along a sandy beach collecting glowing starfish at night, "
|
| 168 |
+
f"bioluminescent waves, crescent moon, {STYLE}"),
|
| 169 |
+
("beach_06", f"a bunny and a hedgehog sharing a watermelon slice on a colorful beach towel, "
|
| 170 |
+
f"sunny beach, parasol, gentle waves, {STYLE}"),
|
| 171 |
+
("beach_07", f"a baby fox building a sand boat on the beach, "
|
| 172 |
+
f"pebble sail, seagulls, golden sunset, {STYLE}"),
|
| 173 |
+
("beach_08", f"a baby bear snorkeling in a clear lagoon, colorful fish and coral below, "
|
| 174 |
+
f"tropical beach, bright midday light, {STYLE}"),
|
| 175 |
+
("beach_09", f"a kitten watching the sunset from a dock over calm ocean water, "
|
| 176 |
+
f"orange and pink sky, lantern beside, soft waves, {STYLE}"),
|
| 177 |
+
("beach_10", f"a baby deer and a squirrel collecting shells in tide pools at low tide, "
|
| 178 |
+
f"pastel sunset, starfish, {STYLE}"),
|
| 179 |
+
|
| 180 |
+
# ββ 7. Snowy winter ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 181 |
+
("snow_01", f"a bunny building a snowman in a snowy forest clearing, "
|
| 182 |
+
f"carrot nose, scarf, snowflakes falling, soft pink sky, {STYLE}"),
|
| 183 |
+
("snow_02", f"a kitten ice skating on a frozen pond in a winter forest, "
|
| 184 |
+
f"snowflakes, pine trees with snow caps, fairy lights on branches, {STYLE}"),
|
| 185 |
+
("snow_03", f"a baby bear sledding down a snowy hill at night, "
|
| 186 |
+
f"moonlight, sparkling snow, cozy village lights below, {STYLE}"),
|
| 187 |
+
("snow_04", f"a hedgehog warming up by a bonfire in the snow, "
|
| 188 |
+
f"hot chocolate in tiny paws, snowflakes floating, pine forest, {STYLE}"),
|
| 189 |
+
("snow_05", f"a baby fox wrapped in a giant scarf making snow angels in a winter field, "
|
| 190 |
+
f"snowflakes, soft blue and white tones, {STYLE}"),
|
| 191 |
+
("snow_06", f"an owl delivering a tiny letter through falling snow to a cabin, "
|
| 192 |
+
f"warm window glow, snow-covered trees, {STYLE}"),
|
| 193 |
+
("snow_07", f"a baby deer with snowflakes on its nose in a quiet snowy forest, "
|
| 194 |
+
f"bare tree branches with icicles, soft grey-blue light, {STYLE}"),
|
| 195 |
+
("snow_08", f"a raccoon and a squirrel having a snowball fight in a park, "
|
| 196 |
+
f"snow-covered benches, winter lanterns, {STYLE}"),
|
| 197 |
+
("snow_09", f"a baby penguin sliding down an icy path to the frozen ocean, "
|
| 198 |
+
f"auroras in the sky, soft blue and green glow, {STYLE}"),
|
| 199 |
+
("snow_10", f"a bunny and kitten sharing a pastel umbrella in gently falling snow, "
|
| 200 |
+
f"fairy lights on trees, warm glow from a cafΓ© window, {STYLE}"),
|
| 201 |
+
|
| 202 |
+
# ββ 8. Autumn / rainy day ββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 203 |
+
("autumn_01", f"a bunny jumping in a pile of colorful autumn leaves in a park, "
|
| 204 |
+
f"orange and red maples, soft afternoon sun, {STYLE}"),
|
| 205 |
+
("autumn_02", f"a kitten at a rainy window with a cup of tea, "
|
| 206 |
+
f"raindrops on glass, cozy sweater, autumn forest visible outside, {STYLE}"),
|
| 207 |
+
("autumn_03", f"a baby bear in a pumpkin patch at golden hour, "
|
| 208 |
+
f"scarecrow, autumn leaves drifting, {STYLE}"),
|
| 209 |
+
("autumn_04", f"a hedgehog foraging mushrooms in an autumn forest, "
|
| 210 |
+
f"golden light through orange leaves, red berries, {STYLE}"),
|
| 211 |
+
("autumn_05", f"a baby fox jumping through autumn leaves in a red-orange forest, "
|
| 212 |
+
f"bokeh light, warm amber tones, {STYLE}"),
|
| 213 |
+
("autumn_06", f"an owl in a cozy raincoat standing under a colorful mushroom in the rain, "
|
| 214 |
+
f"puddles reflecting fairy lights, {STYLE}"),
|
| 215 |
+
("autumn_07", f"a baby deer watching the first autumn rain from under a giant leaf, "
|
| 216 |
+
f"golden forest background, raindrops sparkle, {STYLE}"),
|
| 217 |
+
("autumn_08", f"a raccoon selling hot apple cider from a tiny wooden cart in an autumn market, "
|
| 218 |
+
f"string lights, orange and red leaves, {STYLE}"),
|
| 219 |
+
("autumn_09", f"a squirrel cozy in a hollow tree watching autumn rain, "
|
| 220 |
+
f"acorn collection visible inside, warm golden glow, {STYLE}"),
|
| 221 |
+
("autumn_10", f"a bunny and a baby fox under a giant colorful umbrella in a rainy autumn street, "
|
| 222 |
+
f"cafΓ© lights, reflections in puddles, {STYLE}"),
|
| 223 |
+
]
|
| 224 |
+
|
| 225 |
+
assert len(PROMPTS) == 80, f"Expected 80 prompts, got {len(PROMPTS)}"
|
| 226 |
+
|
| 227 |
+
# ---------------------------------------------------------------------------
|
| 228 |
+
# Generator using Gemini 3.1 Flash Image (Nano Banana 2)
|
| 229 |
+
# ---------------------------------------------------------------------------
|
| 230 |
+
|
| 231 |
+
def generate_image(prompt: str):
|
| 232 |
+
from google import genai
|
| 233 |
+
from google.genai import types
|
| 234 |
+
|
| 235 |
+
api_key = os.environ.get("GEMINI_API_KEY")
|
| 236 |
+
client = genai.Client(api_key=api_key)
|
| 237 |
+
|
| 238 |
+
response = client.models.generate_content(
|
| 239 |
+
model="gemini-3.1-flash-image",
|
| 240 |
+
contents=[prompt],
|
| 241 |
+
config=types.GenerateContentConfig(
|
| 242 |
+
response_modalities=["IMAGE"],
|
| 243 |
+
image_config=types.ImageConfig(
|
| 244 |
+
aspect_ratio="1:1",
|
| 245 |
+
image_size="1K",
|
| 246 |
+
),
|
| 247 |
+
),
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
for part in response.parts:
|
| 251 |
+
if part.inline_data is not None:
|
| 252 |
+
return part.as_image()
|
| 253 |
+
|
| 254 |
+
raise RuntimeError("No image in response")
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def main():
|
| 258 |
+
parser = argparse.ArgumentParser()
|
| 259 |
+
parser.add_argument("--start", type=int, default=1, help="Resume from image N (1-based)")
|
| 260 |
+
parser.add_argument("--dry-run", action="store_true", help="Print prompts without generating")
|
| 261 |
+
args = parser.parse_args()
|
| 262 |
+
|
| 263 |
+
if not os.environ.get("GEMINI_API_KEY") and not args.dry_run:
|
| 264 |
+
print("β Set GEMINI_API_KEY environment variable before running.")
|
| 265 |
+
print(" export GEMINI_API_KEY=your_key")
|
| 266 |
+
sys.exit(1)
|
| 267 |
+
|
| 268 |
+
out_dir = Path(__file__).parent.parent / "training"
|
| 269 |
+
out_dir.mkdir(exist_ok=True)
|
| 270 |
+
|
| 271 |
+
total = len(PROMPTS)
|
| 272 |
+
|
| 273 |
+
print(f"NumZoo dataset generator β {total} images β {out_dir}")
|
| 274 |
+
print(f"Starting from image {args.start}/{total}")
|
| 275 |
+
print()
|
| 276 |
+
|
| 277 |
+
for i, (name, prompt) in enumerate(PROMPTS):
|
| 278 |
+
n = i + 1
|
| 279 |
+
if n < args.start:
|
| 280 |
+
continue
|
| 281 |
+
|
| 282 |
+
img_path = out_dir / f"image_{n:03d}.jpg"
|
| 283 |
+
txt_path = out_dir / f"image_{n:03d}.txt"
|
| 284 |
+
|
| 285 |
+
if img_path.exists():
|
| 286 |
+
print(f"[{n:02d}/{total}] β {name} β already exists, skipping")
|
| 287 |
+
continue
|
| 288 |
+
|
| 289 |
+
print(f"[{n:02d}/{total}] π¨ {name}")
|
| 290 |
+
|
| 291 |
+
if args.dry_run:
|
| 292 |
+
print(f" {prompt[:120]}β¦")
|
| 293 |
+
continue
|
| 294 |
+
|
| 295 |
+
try:
|
| 296 |
+
image = generate_image(prompt)
|
| 297 |
+
image.save(img_path, "JPEG", quality=95)
|
| 298 |
+
txt_path.write_text(prompt)
|
| 299 |
+
print(f" β
saved {img_path.name}")
|
| 300 |
+
except Exception as e:
|
| 301 |
+
print(f" β failed: {e}")
|
| 302 |
+
time.sleep(5) # brief pause on error before continuing
|
| 303 |
+
|
| 304 |
+
generated = len(list(out_dir.glob("*.jpg")))
|
| 305 |
+
print(f"\nDone. {generated}/{total} images in {out_dir}")
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
if __name__ == "__main__":
|
| 309 |
+
main()
|