-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen.py
More file actions
147 lines (141 loc) · 9.51 KB
/
Copy pathgen.py
File metadata and controls
147 lines (141 loc) · 9.51 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
#!/usr/bin/env python3
"""Generate missing game art with Gemini flash image model -> assets/."""
import base64, json, os, sys, time, urllib.request
KEY = os.environ['GEMINI_API_KEY']
MODEL = 'gemini-3.1-flash-image'
ASSETS = '/Users/pesh/Sites/thea/assets'
STYLE = ('Storybook painterly illustration for a dress-up game for young girls, '
'soft dreamy light, magical pink-and-gold palette, matching the art style '
'of the attached reference image. No people, no animals, no text, no watermark, no logo.')
SCENE = ('Wide 16:9 scene. The horizon sits about one third up from the bottom edge; '
'the entire bottom third is an open, empty, walkable ground with no objects, '
'so a character can be composited walking there.')
JOBS = [
# (outfile, reference image, prompt, aspect)
('town-park.png', 'env-main.png',
f'{STYLE} {SCENE} A magical town park: rolling green lawns, big friendly leafy trees, '
'a small sparkling fountain in the middle distance, a soft rainbow in the sky, '
'a little duck pond, flowers along the sides, fluffy clouds.', '16:9'),
('town-strand.png', 'env-main.png',
f'{STYLE} {SCENE} A sunny magical beach: calm turquoise sea meeting the sky, a tiny white '
'sailboat far out, one palm tree on the left, a striped parasol on the right in the middle '
'distance, seashells sparse near the waterline, warm golden sand as the open foreground.', '16:9'),
('town-slott.png', 'env-main.png',
f'{STYLE} {SCENE} A fairy-tale princess castle with pink turrets and golden flags on a gentle '
'hill in the middle distance, dusk sky in purple and pink with early stars and sparkles, '
'rose bushes along the sides, a smooth path crossing the open foreground toward the gate.', '16:9'),
('backdrop.png', 'env-main.png',
f'{STYLE} A glamorous dressing-room studio interior, symmetric composition: a tall golden arch '
'alcove centered with a soft glowing spotlight, elegant pink curtains at both sides, warm fairy '
'lights, subtle sparkles, the bottom quarter is a clean empty stage floor centered where a doll '
'will be composited standing. 16:9.', '16:9'),
('look-08.png', 'base.png',
'Edit the attached character image. Keep EXACTLY the same girl: same pose, same framing, same '
'camera, same face and face position, same hairstyle, same proportions, same flat light-gray '
'studio background. ONLY change her clothing into: a colorful boho festival outfit — rainbow '
'fringe skirt, denim vest with patches, colorful friendship bracelets, and cute pink glitter '
'ankle boots that clearly match the outfit. Full body visible, feet flat on the ground, '
'no text, no watermark.', None),
('look-10.png', 'base.png',
'Edit the attached character image. Keep EXACTLY the same girl: same pose, same framing, same '
'camera, same face and face position, same hairstyle, same proportions, same flat light-gray '
'studio background. ONLY change her clothing into: a shimmering mermaid-dream gown — iridescent '
'teal-aqua scale-pattern fitted dress, pearl and seashell details, subtle sea-glitter. The gown '
'is FLOOR-LENGTH and flares out at the very bottom, fully covering and hiding her feet — NO '
'shoes, sneakers, or feet visible at all, just the hem of the gown pooling on the ground. '
'Full body visible, no text, no watermark.', None),
('env-ball.png', 'env-main.png',
f'{STYLE} A grand royal ballroom at night: soaring arched windows with a moonlit deep-blue '
'starry sky, huge glittering crystal chandeliers, warm golden candlelight, a polished cream-and-'
'pink marble dance floor with a subtle golden rose pattern, elegant draped curtains, floating '
'golden sparkles and bokeh, romantic and magical. The entire lower-center is an open empty dance '
'floor with NO people, so two characters can be composited dancing there. Do NOT include any '
'arrows, navigation icons, floor symbols, buttons or UI elements anywhere. 16:9.', '16:9'),
('prince.png', 'base.png',
'Keep the EXACT art style, glossy storybook toy-doll rendering, large expressive eyes, framing, '
'proportions and flat light-gray studio background of the attached reference doll — but draw a '
'DIFFERENT character, a BOY not a girl: a charming young fairytale prince with neat brown hair '
'and a warm friendly smile, wearing an elegant royal ball outfit (a fitted white-and-gold prince '
'jacket with gold epaulettes and buttons, a small gold crown, navy trousers, polished shoes). '
'Standing full-body facing forward, arms relaxed at his sides, feet flat on the ground. '
'Full body visible, no text, no watermark.', None),
('vaffel.png', 'base.png',
'Use the attached image ONLY as an art-style reference (glossy storybook toy rendering, soft '
'lighting, flat light-gray studio background). Draw a cute small fluffy toy dog and NO humans: '
'a Bichon Bolognese puppy with a PURE WHITE long fluffy cottony coat that stands away from the '
'body, a compact sturdy little body, large round dark eyes, a big black nose and black paw pads, '
'an adorable happy expression, sitting and facing forward. Centered, whole body visible on a '
'flat light-gray studio background. No text, no watermark, no collar tag.', '1:1'),
('npc-eiril.png', 'base.png',
'Keep the EXACT art style, glossy storybook toy-doll rendering, large expressive eyes, framing, '
'proportions and flat light-gray studio background of the attached reference doll — but draw a '
'DIFFERENT character: a beautiful young mermaid with long flowing turquoise-and-lavender hair, a '
'shimmering iridescent teal-green fish tail instead of legs, a pearl-and-seashell top, pearl '
'jewelry and sea-glitter on her skin, posed gracefully with her tail curving to one side. '
'Full body visible, no text, no watermark.', None),
('npc-raggis.png', 'base.png',
'Keep the EXACT art style, glossy storybook toy-doll rendering, large expressive eyes, framing, '
'proportions and flat light-gray studio background of the attached reference doll — but draw a '
'DIFFERENT character: an elegant young princess with golden-blonde hair in an updo, a sparkling '
'tiara, a luxurious pastel-pink-and-gold ball gown with puffed sleeves and jewels, and long '
'white gloves, in a regal graceful standing pose. Full body visible, no text, no watermark.', None),
('npc-sofia.png', 'base.png',
'Keep the EXACT art style, glossy storybook toy-doll rendering, large expressive eyes, framing, '
'proportions and flat light-gray studio background of the attached reference doll — but draw a '
'DIFFERENT character: a friendly fashion-boutique stylist girl with a sleek dark bob, a chic '
'modern outfit (a tailored blazer over a dress), a warm welcoming smile and one hand raised in a '
'friendly wave, standing full-body. Full body visible, no text, no watermark.', None),
('npc-kanel.png', 'base.png',
'Use the attached image ONLY as an art-style reference (glossy storybook toy rendering, soft '
'lighting, flat light-gray studio background). Draw a cute fluffy toy bunny character and NO '
'humans: a soft cream-white rabbit standing upright on two legs, big friendly dark eyes, long '
'ears, wearing a tiny pastel-pink café apron and bow, adorable happy expression. Whole body '
'centered on a flat light-gray studio background. No text, no watermark.', None),
('npc-stjerne.png', 'base.png',
'Use the attached image ONLY as an art-style reference (glossy storybook toy rendering, soft '
'lighting, flat light-gray studio background). Draw a cute magical baby unicorn and NO humans: '
'a fluffy white body, pastel pink-and-purple mane and tail, a shimmering rainbow horn, big '
'sparkly eyes, standing full body facing forward, adorable. Whole body centered on a flat '
'light-gray studio background. No text, no watermark.', None),
]
# optional filter: `python3 gen.py look-08 look-10` regenerates only those
if len(sys.argv) > 1:
want = set(sys.argv[1:])
JOBS = [j for j in JOBS if j[0] in want or j[0].removesuffix('.png') in want]
def gen(outfile, ref, prompt, aspect, tries=3):
with open(f'{ASSETS}/{ref}', 'rb') as f:
ref_b64 = base64.b64encode(f.read()).decode()
body = {
'contents': [{'parts': [
{'inline_data': {'mime_type': 'image/png', 'data': ref_b64}},
{'text': prompt},
]}],
'generationConfig': {'responseModalities': ['IMAGE']},
}
if aspect:
body['generationConfig']['imageConfig'] = {'aspectRatio': aspect}
req = urllib.request.Request(
f'https://generativelanguage.googleapis.com/v1beta/models/{MODEL}:generateContent',
data=json.dumps(body).encode(),
headers={'Content-Type': 'application/json', 'x-goog-api-key': KEY})
for attempt in range(tries):
try:
with urllib.request.urlopen(req, timeout=180) as r:
resp = json.load(r)
parts = resp['candidates'][0]['content']['parts']
img = next(p['inlineData']['data'] for p in parts if 'inlineData' in p)
with open(f'{ASSETS}/{outfile}', 'wb') as f:
f.write(base64.b64decode(img))
print(f'OK {outfile}', flush=True)
return
except Exception as e:
detail = ''
if hasattr(e, 'read'):
try: detail = e.read().decode()[:300]
except Exception: pass
print(f'retry {outfile} ({attempt+1}): {e} {detail}', flush=True)
time.sleep(5)
print(f'FAILED {outfile}', flush=True)
for job in JOBS:
gen(*job)
print('all done', flush=True)